public function push() { $app_key = $this->settings['jpushkey']; $master_secret = $this->settings['jpushsecret']; //'46867b6b0c46b34ee6848b56'; $client = new JPushClient($app_key, $master_secret); $device_token = $this->input['device_token']; if (!$device_token) { $this->errorOutput('NO_DEVICE_TOKEN'); } $message = $this->input['message']; if (!$message) { $this->errorOutput('NO_MESSAGE'); } $module = $this->input['module']; $content_id = $this->input['content_id']; if ($module) { $options = array($module => $content_id); } else { $options = array(); } $result = $client->push()->setPlatform(M\Platform('android'))->setAudience(M\audience(M\alias(array($device_token))))->setNotification(M\notification($message, M\android($message, '', 1, $options)))->send(); $this->addItem_withkey('result', $result->isOk ? 1 : 0); $this->output(); }
public function setPlatform($platform = 'all') { if (is_string($platform) && ($platform = 'all')) { $this->_platform = M\all; } elseif (is_array($platform)) { $this->_platform = M\Platform($platform); } }
/** * Index Page for this controller. * * Maps to the following URL * http://example.com/index.php/welcome * - or - * http://example.com/index.php/welcome/index * - or - * Since this controller is set as the default controller in * config/routes.php, it's displayed at http://example.com/ * * So any other public methods not prefixed with an underscore will * map to /index.php/welcome/<method_name> * * @see http://codeigniter.com/user_guide/general/urls.html */ public function index() { $br = '<br/>'; $spilt = ' - '; $master_secret = '3047c84ce72ed9ab392e6be1'; $app_key = '57d93d27208ab6e2516b129d'; JPushLog::setLogHandlers(array(new StreamHandler('jpush.log', Logger::DEBUG))); $client = new JPushClient($app_key, $master_secret); // easy push try { $result = $client->push()->setPlatform(M\all)->setAudience(M\all)->setNotification(M\notification('Hi, JPush'))->printJSON()->send(); echo 'Push Success.' . $br; echo 'sendno : ' . $result->sendno . $br; echo 'msg_id : ' . $result->msg_id . $br; echo 'Response JSON : ' . $result->json . $br; } catch (APIRequestException $e) { echo 'Push Fail.' . $br; echo 'Http Code : ' . $e->httpCode . $br; echo 'code : ' . $e->code . $br; echo 'Error Message : ' . $e->message . $br; echo 'Response JSON : ' . $e->json . $br; echo 'rateLimitLimit : ' . $e->rateLimitLimit . $br; echo 'rateLimitRemaining : ' . $e->rateLimitRemaining . $br; echo 'rateLimitReset : ' . $e->rateLimitReset . $br; } catch (APIConnectionException $e) { echo 'Push Fail: ' . $br; echo 'Error Message: ' . $e->getMessage() . $br; // response timeout means your request has probably be received by JPUsh Server,please check that whether need to be pushed again. echo 'IsResponseTimeout: ' . $e->isResponseTimeout . $br; } echo $br . '-------------' . $br; // easy push with ios badge +1 // 以下演示推送给 Android, IOS 平台下Tag为tag1的用户的示例 try { $result = $client->push()->setPlatform(M\Platform('android', 'ios'))->setAudience(M\Audience(M\Tag(array('tag1'))))->setNotification(M\notification('Hi, JPush', M\android('Hi, Android', 'Message Title', 1, array("key1" => "value1", "key2" => "value2")), M\ios("Hi, IOS", "happy", "+1", true, array("key1" => "value1", "key2" => "value2"), "Ios8 Category")))->setMessage(M\message('Message Content', 'Message Title', 'Message Type', array("key1" => "value1", "key2" => "value2")))->printJSON()->send(); echo 'Push Success.' . $br; echo 'sendno : ' . $result->sendno . $br; echo 'msg_id : ' . $result->msg_id . $br; echo 'Response JSON : ' . $result->json . $br; } catch (APIRequestException $e) { echo 'Push Fail.' . $br; echo 'Http Code : ' . $e->httpCode . $br; echo 'code : ' . $e->code . $br; echo 'Error Message : ' . $e->message . $br; echo 'Response JSON : ' . $e->json . $br; echo 'rateLimitLimit : ' . $e->rateLimitLimit . $br; echo 'rateLimitRemaining : ' . $e->rateLimitRemaining . $br; echo 'rateLimitReset : ' . $e->rateLimitReset . $br; } catch (APIConnectionException $e) { echo 'Push Fail: ' . $br; echo 'Error Message: ' . $e->getMessage() . $br; // response timeout means your request has probably be received by JPUsh Server,please check that whether need to be pushed again. echo 'IsResponseTimeout: ' . $e->isResponseTimeout . $br; } echo $br . '-------------' . $br; // full push try { $result = $client->push()->setPlatform(M\platform('ios', 'android'))->setAudience(M\audience(M\tag(array('555', '666')), M\alias(array('555', '666'))))->setNotification(M\notification('Hi, JPush', M\android('Hi, android'), M\ios('Hi, ios', 'happy', 1, true, null, 'THE-CATEGORY')))->setMessage(M\message('msg content', null, null, array('key' => 'value')))->setOptions(M\options(123456, null, null, false, 0))->printJSON()->send(); echo 'Push Success.' . $br; echo 'sendno : ' . $result->sendno . $br; echo 'msg_id : ' . $result->msg_id . $br; echo 'Response JSON : ' . $result->json . $br; } catch (APIRequestException $e) { echo 'Push Fail.' . $br; echo 'Http Code : ' . $e->httpCode . $br; echo 'code : ' . $e->code . $br; echo 'message : ' . $e->message . $br; echo 'Response JSON : ' . $e->json . $br; echo 'rateLimitLimit : ' . $e->rateLimitLimit . $br; echo 'rateLimitRemaining : ' . $e->rateLimitRemaining . $br; echo 'rateLimitReset : ' . $e->rateLimitReset . $br; } catch (APIConnectionException $e) { echo 'Push Fail: ' . $br; echo 'Error Message: ' . $e->getMessage() . $br; // response timeout means your request has probably be received by JPUsh Server,please check that whether need to be pushed again. echo 'IsResponseTimeout: ' . $e->isResponseTimeout . $br; } echo $br . '-------------' . $br; // fail push try { $result = $client->push()->setPlatform(M\all)->setAudience(M\all)->setNotification(M\notification('Hi, JPush'))->setAudience(M\audience(array('no one')))->printJSON()->send(); echo 'Push Success.' . $br; echo 'sendno : ' . $result->sendno . $br; echo 'msg_id : ' . $result->msg_id . $br; echo 'Response JSON : ' . $result->json . $br; } catch (APIRequestException $e) { echo 'Push Fail.' . $br; echo 'Http Code : ' . $e->httpCode . $br; echo 'code : ' . $e->code . $br; echo 'message : ' . $e->message . $br; echo 'Response JSON : ' . $e->json . $br; echo 'rateLimitLimit : ' . $e->rateLimitLimit . $br; echo 'rateLimitRemaining : ' . $e->rateLimitRemaining . $br; echo 'rateLimitReset : ' . $e->rateLimitReset . $br; } catch (APIConnectionException $e) { echo 'Push Fail: ' . $br; echo 'Error Message: ' . $e->getMessage() . $br; // response timeout means your request has probably be received by JPUsh Server,please check that whether need to be pushed again. echo 'IsResponseTimeout: ' . $e->isResponseTimeout . $br; } }
function JPushUser($message, $user, $params = array()) { if (empty($jpush) == TRUE) { $jpush = JPushInit(); } try { if (is_array($user) == FALSE) { $user = array($user); } $result = $jpush->push()->setPlatform(M\Platform('android'))->setAudience(M\Audience(M\Tag($user), M\Alias($user)))->setMessage(M\message($message, $message, $params['type'], array('message' => $message)))->send(); return $result->msg_id; } catch (APIRequestException $e) { } catch (APIConnectionException $e) { } return FALSE; }
echo 'Error Message : ' . $e->message . $br; echo 'Response JSON : ' . $e->json . $br; echo 'rateLimitLimit : ' . $e->rateLimitLimit . $br; echo 'rateLimitRemaining : ' . $e->rateLimitRemaining . $br; echo 'rateLimitReset : ' . $e->rateLimitReset . $br; } catch (APIConnectionException $e) { echo 'Push Fail: ' . $br; echo 'Error Message: ' . $e->getMessage() . $br; //response timeout means your request has probably be received by JPUsh Server,please check that whether need to be pushed again. echo 'IsResponseTimeout: ' . $e->isResponseTimeout . $br; } echo $br . '-------------' . $br; // easy push with ios badge +1 // 以下演示推送给 Android, IOS 平台下Tag为tag1的用户的示例 try { $result = $client->push()->setPlatform(M\Platform('android', 'ios'))->setAudience(M\Audience(M\Tag(array('tag1'))))->setNotification(M\notification('Hi, JPush', M\android('Hi, Android', 'Message Title', 1, array("key1" => "value1", "key2" => "value2")), M\ios("Hi, IOS", "happy", "+1", true, array("key1" => "value1", "key2" => "value2"), "Ios8 Category")))->setMessage(M\message('Message Content', 'Message Title', 'Message Type', array("key1" => "value1", "key2" => "value2")))->printJSON()->send(); echo 'Push Success.' . $br; echo 'sendno : ' . $result->sendno . $br; echo 'msg_id : ' . $result->msg_id . $br; echo 'Response JSON : ' . $result->json . $br; } catch (APIRequestException $e) { echo 'Push Fail.' . $br; echo 'Http Code : ' . $e->httpCode . $br; echo 'code : ' . $e->code . $br; echo 'Error Message : ' . $e->message . $br; echo 'Response JSON : ' . $e->json . $br; echo 'rateLimitLimit : ' . $e->rateLimitLimit . $br; echo 'rateLimitRemaining : ' . $e->rateLimitRemaining . $br; echo 'rateLimitReset : ' . $e->rateLimitReset . $br; } catch (APIConnectionException $e) { echo 'Push Fail: ' . $br;
use JPush\Model as M; $fromCellPhone = isset($_REQUEST['cellPhone']) ? $_REQUEST['cellPhone'] : ""; $nickname = isset($_REQUEST['nickname']) ? $_REQUEST['nickname'] : "匿名"; $targetCellPhone = isset($_REQUEST['targetCellPhone']) ? $_REQUEST['targetCellPhone'] : ""; $message = isset($_REQUEST['message']) ? $_REQUEST['message'] : "召唤"; if (empty($targetCellPhone) or empty($fromCellPhone)) { die("nothing else comes so close"); } $target = $prefix . $targetCellPhone; $br = '<br/>'; $spilt = ' - '; //JPushLog::setLogHandlers(array(new StreamHandler('jpush.log', Logger::DEBUG))); $client = new JPushClient($app_key, $master_secret); // 以下演示推送给 Android, IOS 平台下Tag为tag1的用户的示例 try { $result = $client->push()->setPlatform(M\Platform('ios'))->setAudience(M\Audience(M\alias([$target])))->setNotification(M\notification('来自' . $nickname . '的指令:' . $message, M\ios('来自' . $nickname . '的指令:' . $message, "happy", "+1", true, ["from" => $nickname, "message" => $message], "BearRemoter")))->printJSON()->send(); echo 'Push Success.' . $br; echo 'sendno : ' . $result->sendno . $br; echo 'msg_id : ' . $result->msg_id . $br; echo 'Response JSON : ' . $result->json . $br; } catch (APIRequestException $e) { echo 'Push Fail.' . $br; echo 'Http Code : ' . $e->httpCode . $br; echo 'code : ' . $e->code . $br; echo 'Error Message : ' . $e->message . $br; echo 'Response JSON : ' . $e->json . $br; echo 'rateLimitLimit : ' . $e->rateLimitLimit . $br; echo 'rateLimitRemaining : ' . $e->rateLimitRemaining . $br; echo 'rateLimitReset : ' . $e->rateLimitReset . $br; } catch (APIConnectionException $e) { echo 'Push Fail: ' . $br;