本文整理汇总了PHP中jsonRPCClient::add_contact方法的典型用法代码示例。如果您正苦于以下问题:PHP jsonRPCClient::add_contact方法的具体用法?PHP jsonRPCClient::add_contact怎么用?PHP jsonRPCClient::add_contact使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsonRPCClient
的用法示例。
在下文中一共展示了jsonRPCClient::add_contact方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: AutoResponderGetResponseAPI
function AutoResponderGetResponseAPI($that, $ar, $wpm_id, $email, $unsub = false)
{
global $wpdb;
require_once $that->pluginDir . '/extlib/jsonRPCClient.php';
if ($ar['campaign'][$wpm_id]) {
$campaign = trim($ar['campaign'][$wpm_id]);
$name = trim($that->ARSender['name']);
$email = trim($that->ARSender['email']);
$api_key = trim($ar['apikey']);
$api_url = empty($ar['api_url']) ? "http://api2.getresponse.com" : trim($ar['api_url']);
$grUnsub = $ar['grUnsub'][$wpm_id] == 1 ? true : false;
$uid = $wpdb->get_var("SELECT ID FROM {$wpdb->users} WHERE `user_email`='" . esc_sql($that->ARSender['email']) . "'");
$ip = trim($that->Get_UserMeta($uid, 'wpm_login_ip'));
$ip = $ip ? $ip : trim($that->Get_UserMeta($uid, 'wpm_registration_ip'));
$ip = $ip ? $ip : trim($_SERVER['REMOTE_ADDR']);
try {
if (!extension_loaded('curl') || !extension_loaded('json')) {
# these extensions are a must
throw new Exception("CURL and JSON are modules required to use" . " the GetResponse Integration");
}
$api = new jsonRPCClient($api_url);
#get the campaign id
$resp = $api->get_campaigns($api_key);
$cid = null;
if (!empty($resp)) {
foreach ($resp as $i => $item) {
if (strtolower($item['name']) == strtolower($campaign)) {
$cid = $i;
}
}
}
if (empty($cid)) {
throw new Exception("Could not find campaign {$campaign}");
}
if ($unsub) {
if ($grUnsub) {
//list contacts
$contacts = $api->get_contacts($api_key, array('campaigns' => array($cid), 'email' => array('EQUALS' => "{$email}")));
if (empty($contacts)) {
#could not find the contact, nothing to remove
return;
}
$pid = key($contacts);
$res = $api->delete_contact($api_key, array('contact' => $pid));
if (empty($res)) {
throw new Exception("Empty server response while deleting contact");
}
}
} else {
$resp = $api->add_contact($api_key, array('campaign' => $cid, 'name' => $name, 'email' => $email, 'ip' => $ip, 'cycle_day' => 0));
if (empty($resp)) {
throw new Exception("Empty server response while sending");
}
}
} catch (Exception $e) {
return;
}
}
}
示例2: indeed_getResponse
public function indeed_getResponse($api_key, $token, $e_mail, $full_name = '')
{
require_once $this->dir_path . '/email_services/getresponse/jsonRPCClient.php';
$api = new jsonRPCClient('http://api2.getresponse.com');
$args = array('campaign' => $token, 'email' => $e_mail);
if (!empty($full_name)) {
$args['name'] = $full_name;
}
$res = $api->add_contact($api_key, $args);
if ($res) {
return 1;
} else {
return 0;
}
}
示例3: process
function process()
{
global $order;
if (!$this->enabled) {
return;
}
$client = new jsonRPCClient('http://api2.getresponse.com');
$result = NULL;
try {
$result = $client->get_campaigns(MODULE_ORDER_TOTAL_GETRESPONSE_API_KEY, array('name' => array('EQUALS' => MODULE_ORDER_TOTAL_GETRESPONSE_CAMPAIGN)));
if (empty($result)) {
throw new Exception('Missing GetResponse campaign: ' . MODULE_ORDER_TOTAL_GETRESPONSE_CAMPAIGN);
}
$client->add_contact(MODULE_ORDER_TOTAL_GETRESPONSE_API_KEY, array('campaign' => array_pop(array_keys($result)), 'name' => $order->customer['firstname'] . ' ' . $order->customer['lastname'], 'email' => $order->customer['email_address'], 'cycle_day' => '0', 'customs' => array(array('name' => 'ref', 'content' => STORE_NAME), array('name' => 'telephone', 'content' => $order->customer['telephone']), array('name' => 'country', 'content' => $order->customer['country']['title']), array('name' => 'city', 'content' => $order->customer['city']))));
} catch (Exception $e) {
error_log($e->getMessage());
return;
}
}
示例4: jsonRPCClient
/**
* Subscribes to GetResponse list. Returns either "success" string or error message.
* @return string
*/
function subscribe_get_response($list, $email, $api_key, $name = '-')
{
if (!function_exists('curl_init')) {
return;
}
require_once RAD_RAPIDOLOGY_PLUGIN_DIR . 'subscription/getresponse/jsonrpcclient.php';
$api_url = 'http://api2.getresponse.com';
$name = '' == $name ? '-' : $name;
$client = new jsonRPCClient($api_url);
$result = $client->add_contact($api_key, array('campaign' => $list, 'name' => $name, 'email' => $email));
if (isset($result['result']['queued']) && 1 == $result['result']['queued']) {
$result = 'success';
} else {
if (isset($result['error']['message'])) {
$result = $result['error']['message'];
} else {
$result = 'unknown error';
}
}
return $result;
}
示例5: snp_popup_submit
//.........这里部分代码省略.........
$CustomFields = array();
foreach ($cf_data as $k => $v) {
$args[$k] = $v;
}
}
$res = $client->addSubscriber($args);
if (isset($res['UID'])) {
$Done = 1;
}
} catch (Exception $e) {
// Error...
// We'll send this by email.
}
} elseif (snp_get_option('ml_manager') == 'getresponse') {
$ml_gr_apikey = snp_get_option('ml_gr_apikey');
require_once SNP_DIR_PATH . '/include/getresponse/jsonRPCClient.php';
$api = new jsonRPCClient('http://api2.getresponse.com');
try {
$ml_gr_list = $POPUP_META['snp_ml_gr_list'][0];
if (!$ml_gr_list) {
$ml_gr_list = snp_get_option('ml_gr_list');
}
$args = array('campaign' => $ml_gr_list, 'email' => $_POST['email']);
if (!empty($_POST['name'])) {
$args['name'] = $_POST['name'];
}
if (count($cf_data) > 0) {
$CustomFields = array();
foreach ($cf_data as $k => $v) {
$CustomFields[] = array('name' => $k, 'content' => $v);
}
$args['customs'] = $CustomFields;
}
$res = $api->add_contact($ml_gr_apikey, $args);
$Done = 1;
} catch (Exception $e) {
// Error...
// We'll send this by email.
$api_error_msg = $e->getMessage();
}
} elseif (snp_get_option('ml_manager') == 'campaignmonitor') {
require_once SNP_DIR_PATH . '/include/campaignmonitor/csrest_subscribers.php';
$ml_cm_list = $POPUP_META['snp_ml_cm_list'][0];
if (!$ml_cm_list) {
$ml_cm_list = snp_get_option('ml_cm_list');
}
$wrap = new CS_REST_Subscribers($ml_cm_list, snp_get_option('ml_cm_apikey'));
$args = array('EmailAddress' => $_POST['email'], 'Resubscribe' => true);
if (!empty($_POST['name'])) {
$args['Name'] = $_POST['name'];
}
if (count($cf_data) > 0) {
$CustomFields = array();
foreach ($cf_data as $k => $v) {
$CustomFields[] = array('Key' => $k, 'Value' => $v);
}
$args['CustomFields'] = $CustomFields;
}
$res = $wrap->add($args);
if ($res->was_successful()) {
$Done = 1;
} else {
// Error...
// We'll send this by email.
$api_error_msg = 'Failed with code ' . $res->http_status_code;
}
示例6: jsonRPCClient
$api_key = 'ENTER_YOUR_API_KEY_HERE';
# API 2.x URL
$api_url = 'http://api2.getresponse.com';
# initialize JSON-RPC client
$client = new jsonRPCClient($api_url);
$result = NULL;
# get CAMPAIGN_ID of 'sample_marketing' campaign
try {
$result = $client->get_campaigns($api_key, array('name' => array('EQUALS' => 'sample_marketing')));
} catch (Exception $e) {
# check for communication and response errors
# implement handling if needed
die($e->getMessage());
}
# uncomment this line to preview data structure
# print_r($result);
# since there can be only one campaign of this name
# first key is the CAMPAIGN_ID you need
$campaigns = array_keys($result);
$CAMPAIGN_ID = array_pop($campaigns);
# add contact to 'sample_marketing' campaign
try {
$result = $client->add_contact($api_key, array('campaign' => $CAMPAIGN_ID, 'name' => 'Sample Name', 'email' => 'sample@email.com', 'cycle_day' => '0', 'customs' => array(array('name' => 'last_purchased_product', 'content' => 'netbook'))));
} catch (Exception $e) {
# check for communication and response errors
# implement handling if needed
die($e->getMessage());
}
# uncomment this line to preview data structure
# print_r($result);
print "Contact added\n";
示例7: ajax_subscribe
//.........这里部分代码省略.........
$subscriber = array(
'email' => sanitize_email( $_POST['email'] ),
'name' => sanitize_text_field( $_POST['first_name'] ) . ' ' . sanitize_text_field( $_POST['last_name'] ),
'ip' => $_SERVER['REMOTE_ADDR']
);
$newSubscriber = $list->subscribers->create($subscriber);
echo json_encode(array(
'status' => 'check',
'message' => $success_message,
));
die();
} catch (AWeberAPIException $exc) {
echo json_encode(array(
'status' => 'warning',
'message' => $exc->message,
));
die();
}
}
// Add email to Get Response
else if ($_POST['type'] == 'getresponse') {
require_once('includes/getresponse/jsonRPCClient.php');
$api = new jsonRPCClient('http://api2.getresponse.com');
try {
$api->add_contact(
$this->settings['subscribe']['getresponse']['api_key'],
array (
'campaign' => $this->settings['subscribe']['getresponse']['campaign'],
'name' => sanitize_text_field( $_POST['first_name'] ) . ' ' . sanitize_text_field( $_POST['last_name'] ),
'email' => sanitize_email( $_POST['email'] ),
)
);
echo json_encode(array(
'status' => 'check',
'message' => $success_message,
));
die();
} catch (RuntimeException $exc) {
$msg = $exc->getMessage();
$msg = substr($msg, 0, strpos($msg, ";"));
echo json_encode(array(
'status' => 'warning',
'message' => $msg,
));
die();
}
}
// Add email to Campaign Monitor
else if ($_POST['type'] == 'campaignmonitor') {
示例8: export
public function export()
{
$this->load->model('module/getresponse');
$contacts = $this->model_module_getresponse->getContacts();
$this->gr_apikey = $this->request->post['api_key'];
$this->campaign = $this->request->post['campaign'];
$this->load->library('jsonRPCClient');
try {
$client = new jsonRPCClient($this->gr_apikey_url);
$result = $client->get_campaigns($this->gr_apikey, array('name' => array('EQUALS' => $this->campaign)));
} catch (Exception $e) {
$this->data['error_warning'] = 'Error!' . $e;
}
if (empty($result)) {
$results = array('status' => 2, 'response' => ' No campaign with the specified name.');
} else {
$duplicated = 0;
$queued = 0;
$contact = 0;
$not_added = 0;
$allow_fields = array('telephone', 'country', 'city', 'address', 'postcode');
$campaign_id = key($result);
foreach ($contacts as $row) {
$customs = array();
$customs[] = array('name' => 'ref', 'content' => 'OpenCart');
foreach ($allow_fields as $af) {
if (!empty($row[$af])) {
$customs[] = array('name' => $af, 'content' => $row[$af]);
}
}
$check_cycle_day = $client->get_contacts($this->gr_apikey, array('campaigns' => array($campaign_id), 'email' => array('EQUALS' => $row['email'])));
if (!empty($check_cycle_day) and is_array($check_cycle_day)) {
$res = array_shift($check_cycle_day);
$cycle_day = $res['cycle_day'];
} else {
$cycle_day = '0';
}
$params = array('campaign' => $campaign_id, 'name' => $row['firstname'] . ' ' . $row['lastname'], 'email' => $row['email'], 'cycle_day' => $cycle_day, 'customs' => $customs);
try {
$r = $client->add_contact($this->gr_apikey, $params);
$contact++;
if (array_key_exists('queued', $r)) {
$queued++;
} else {
if (array_key_exists('duplicated', $r)) {
$duplicated++;
}
}
} catch (Exception $e) {
$not_added++;
}
}
$results = array('status' => 1, 'response' => ' Export completed. Contacts: ' . $contact . '. Queued:' . $queued . '. Updated: ' . $duplicated . '. Not added (Contact already queued): ' . $not_added . '.');
}
$this->response->setOutput(json_encode($results));
}
示例9: affwp_add_to_getresponse
public function affwp_add_to_getresponse($name, $email, $user_id)
{
if (empty($name) || empty($email) || empty($user_id)) {
return;
}
$getresponse_campaign_id = affiliate_wp()->settings->get('affwp_getresponse_campaign_id');
$getresponse_api_key = affiliate_wp()->settings->get('affwp_getresponse_api_key');
$getresponse_api_key = trim($getresponse_api_key);
if (!class_exists('jsonRPCClient')) {
require_once 'classes/jsonRPCClient.php';
}
$api_url = 'http://api2.getresponse.com';
$client = new jsonRPCClient($api_url);
try {
$response = $client->add_contact($getresponse_api_key, array('campaign' => $getresponse_campaign_id, 'name' => $name, 'email' => $email, 'ip' => $_SERVER['REMOTE_ADDR'], 'cycle_day' => 0));
update_user_meta($user_id, 'tbz_affwp_subscribed_to_getresponse', 'yes');
return true;
} catch (Exception $e) {
return false;
}
}
示例10: isset
//.........这里部分代码省略.........
if (isset($result['email'])) {
echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
die;
} else {
if (isset($result['status']) && $result['status'] == 'error') {
echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => $result['error']));
die;
}
}
} else {
echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('Unable to subscribe.', $_POST['text_domain'])));
die;
}
} else {
if ($_POST['type'] == 'aweber') {
require_once dirname(dirname(__FILE__)) . '/services/aweber/aweber_api.php';
$aweber = new AWeberAPI($data_instance['args']['newsletter']['aweber']['consumer_key'], $data_instance['args']['newsletter']['aweber']['consumer_secret']);
try {
$account = $aweber->getAccount($data_instance['args']['newsletter']['aweber']['access_key'], $data_instance['args']['newsletter']['aweber']['access_secret']);
$list = $account->loadFromUrl('/accounts/' . $account->id . '/lists/' . $data_instance['args']['newsletter']['aweber']['list_id']);
$subscriber = array('email' => $_POST['email'], 'name' => $_POST['first_name'] . ' ' . $_POST['last_name'], 'ip' => $_SERVER['REMOTE_ADDR']);
$newSubscriber = $list->subscribers->create($subscriber);
echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
die;
} catch (AWeberAPIException $exc) {
echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => $exc->message));
die;
}
} else {
if ($_POST['type'] == 'getresponse') {
require_once dirname(dirname(__FILE__)) . '/services/getresponse/jsonRPCClient.php';
$api = new jsonRPCClient('http://api2.getresponse.com');
try {
$api->add_contact($data_instance['args']['newsletter']['getresponse']['api_key'], array('campaign' => $data_instance['args']['newsletter']['getresponse']['campaign'], 'name' => $_POST['first_name'] . ' ' . $_POST['last_name'], 'email' => $_POST['email']));
echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
die;
} catch (RuntimeException $exc) {
$msg = $exc->getMessage();
$msg = substr($msg, 0, strpos($msg, ";"));
echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => $msg));
die;
}
} else {
if ($_POST['type'] == 'campaignmonitor') {
require_once dirname(dirname(__FILE__)) . '/services/campaignmonitor/csrest_subscribers.php';
$wrap = new CS_REST_Subscribers($data_instance['args']['newsletter']['campaignmonitor']['list'], $data_instance['args']['newsletter']['campaignmonitor']['api_key']);
// Check if subscriber is already subscribed
$result = $wrap->get($_POST['email']);
if ($result->was_successful()) {
echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('You are already subscribed to this list.', $_POST['text_domain'])));
die;
}
$result = $wrap->add(array('EmailAddress' => $_POST['email'], 'Name' => $_POST['first_name'] . ' ' . $_POST['last_name'], 'Resubscribe' => true));
if ($result->was_successful()) {
echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
die;
} else {
echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => $result->response->Message));
die;
}
} else {
if ($_POST['type'] == 'madmimi') {
require_once dirname(dirname(__FILE__)) . '/services/madmimi/MadMimi.class.php';
$mailer = new MadMimi($data_instance['args']['newsletter']['madmimi']['username'], $data_instance['args']['newsletter']['madmimi']['api_key']);
try {
// Check if user is already in list
示例11: switch
function add_new_contact(){
$name = $_POST['name'];
$email = $_POST['email'];
$mailer_id = $_POST['mailer_id'];
$campaign_id = $_POST['campaign_id'];
$tracker_id = $_POST['tracker_id'];
switch($mailer_id){
// GetResponse
case 1: $getresponse_api_key = get_option('wpcb_getresponse_api_key');
include_once(plugin_dir_path(dirname(__FILE__)).'admin/mailers/getresponse-api.php');
$getresponse = new jsonRPCClient('http://api2.getresponse.com');
try{
$result_contact = $getresponse->add_contact($getresponse_api_key, array ('campaign' => $campaign_id,'name' => $name,'email' => $email,'cycle_day' => 0));
global $wpdb;
$wpcb_tbl_name = $this->get_tracking_table_name();
$wpdb->update($wpcb_tbl_name, array('visittype' => 'optin'), array('id' => $tracker_id), array('%s'), array('%d'));
echo 1;
}
catch (Exception $e){
echo $e;
}
break;
// MailChimp
case 2: $mailchimp_api_key = get_option('wpcb_mailchimp_api_key');
include_once(plugin_dir_path(dirname(__FILE__)).'admin/mailers/mailchimp-api.php');
$mailchimp = new MCAPI($mailchimp_api_key);
$merge_vars = array('FNAME' => $name, 'LNAME' => '');
$retval = $mailchimp->listSubscribe($campaign_id, $email, $merge_vars, 'html', true, true);
if($mailchimp->errorCode){
echo 0;
}
else {
global $wpdb;
$wpcb_tbl_name = $this->get_tracking_table_name();
$wpdb->update($wpcb_tbl_name, array('visittype' => 'optin'), array('id' => $tracker_id), array('%s'), array('%d'));
echo 1;
}
break;
// Aweber
case 3: include_once(plugin_dir_path(dirname(__FILE__)).'admin/mailers/aweber_api/aweber_api.php');
try {
$aweber_api_key = get_option('wpcb_aweber_api_key');
$aweber_data = unserialize($aweber_api_key);
$aweber = new AWeberAPI($aweber_data[0], $aweber_data[1]);
$account = $aweber->getAccount($aweber_data[2], $aweber_data[3]);
$account_id = $account->id;
$listURL = "/accounts/".$account_id."/lists/".$campaign_id;
$list = $account->loadFromUrl($listURL);
$params = array(
'email' => $email,
'name' => $name
);
$subscribers = $list->subscribers;
$new_subscriber = $subscribers->create($params);
global $wpdb;
$wpcb_tbl_name = $this->get_tracking_table_name();
$wpdb->update($wpcb_tbl_name, array('visittype' => 'optin'), array('id' => $tracker_id), array('%s'), array('%d'));
echo 1;
}
catch (Exception $exc)
{
echo 0;
}
break;
// MailPoet
case 9 :$mailpoet_data = array(
'user' => array('email' => $email, 'firstname' => $name),
'user_list' => array('list_ids' => array($campaign_id))
);
// Add subscriber to MailPoet.
$userHelper = WYSIJA::get('user', 'helper');
$userHelper->addSubscriber($mailpoet_data);
global $wpdb;
$wpcb_tbl_name = $this->get_tracking_table_name();
$wpdb->update($wpcb_tbl_name, array('visittype' => 'optin'), array('id' => $tracker_id), array('%s'), array('%d'));
$this->data['success'] = true;
echo 1;
die();
break;
// Feedburner
case 11:$feedburner_uri = get_option('wpcb_feedburner_uri');
global $wpdb;
$wpcb_tbl_name = $this->get_tracking_table_name();
$wpdb->update($wpcb_tbl_name, array('visittype' => 'optin'), array('id' => $tracker_id), array('%s'), array('%d'));
echo 1;
break;
}
die();
}