public static function iosPush($user, $user_info) { $br = '<br/>'; $client = new JPushClient($app_key, $master_secret); try { $result = $client->push()->setPlatform(M\platform('ios'))->setAudience(M\audience(M\alias(array($user->id))))->setNotification(M\ios($user_info))->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) { return Response::json(array('errCode' => 1, 'message' => 'Push Fail.' . $br . 'Http Code : ' . $e->httpCode . $br . 'code : ' . $e->code . $br . 'message : ' . $e->message . $br . 'Response JSON : ' . $e->json . $br . 'rateLimitLimit : ' . $e->rateLimitLimit . $br . 'rateLimitRemaining : ' . $e->rateLimitRemaining . $br . 'rateLimitReset : ' . $e->rateLimitReset . $br)); // 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) { return Response::json(array('errCode' => 2, 'message' => 'Push Fail.' . $br . 'message' . $e->getMessage() . $br)); // echo 'Push Fail.' . $br; // echo 'message' . $e->getMessage() . $br; } }
/** * android别名发送 * @param $title string 消息内容 * @param $alias array 别名数组 */ public function sendByAlias($title, $alias) { $this->setPlatform = M\platform('android'); $this->setAudience = M\alias($alias); $this->setNotification = M\notification($title); return $this->send(); }
private function _get_platform($platform_id = 0) { $platform = M\all; switch ($platform_id) { case C('jpush.platform.all'): $platform = M\all; break; case C('jpush.platform.android'): $platform = M\platform("android"); break; case C('jpush.platform.ios'): $platform = M\platform("android"); break; default: break; } return $platform; }
public function testPayload() { $array = array("platform" => array("android", "ios", "winphone"), "audience" => array("tag" => array("tag1", "tag2"), "tag_and" => array("tag3"), "alias" => array("alias1", "alias2"), "registration_id" => array("id1", "id2")), "notification" => array("alert" => "notification alert", "ios" => array("alert" => "ios alert", "sound" => "happy", "badge" => 1, "content-available" => 1, "extras" => array("key1" => "value1", "key2" => "value2")), "android" => array("alert" => "android alert", "title" => "android title", "builder_id" => 1, "extras" => array("key1" => "value1", "key2" => "value2")), "winphone" => array("alert" => "winphone alert", "title" => "winphone title", "_open_page" => "/friends.xaml", "extras" => array("key1" => "value1", "key2" => "value2"))), "message" => array("msg_content" => "message msg content", "title" => "message title", "content_type" => "message content type", "extras" => array("key1" => "value1", "key2" => "value2")), "options" => array("sendno" => 654321, "time_to_live" => 60, "override_msg_id" => 123456, "apns_production" => false)); $json = json_encode($array); $payload = new M\PushPayload(null); $result = $payload->setPlatform(M\platform('android', 'ios', 'winphone'))->setAudience(M\audience(M\tag(array("tag1", "tag2")), M\tag_and(array("tag3")), M\alias(array("alias1", "alias2")), M\registration_id(array("id1", "id2"))))->setNotification(M\notification('notification alert', M\ios('ios alert', 'happy', 1, true, array("key1" => "value1", "key2" => "value2")), M\android('android alert', 'android title', 1, array("key1" => "value1", "key2" => "value2")), M\winphone('winphone alert', 'winphone title', '/friends.xaml', array("key1" => "value1", "key2" => "value2"))))->setMessage(M\message('message msg content', 'message title', 'message content type', array("key1" => "value1", "key2" => "value2")))->setOptions(M\options(654321, 60, 123456, false))->getJSON(); $this->assertEquals($json, $result); }
if (isset($uid) && isset($msg) && isset($role)) { $rs_arr = $d2b->select("user_main", ["channelid"], ["uid" => $uid]); $channelid = $rs_arr[0]['channelid']; switch ($role) { case 1: $client = new JPushClient($app_key_c, $master_secret_c); try { $result = $client->push()->setPlatform(M\platform('ios', 'android'))->setAudience(M\audience(M\registration_id(array($channelid))))->setNotification(M\notification($msg, M\android($msg), M\ios($msg, 'happy', 1, true, null, 'THE-CATEGORY')))->setMessage(M\message($msg, null, null, array('key' => 'value')))->setOptions(M\options(123456, null, null, false, 0))->send(); $return_arr = ["channelid" => $channelid]; include "../include/return_data.php"; } catch (APIRequestException $e) { echo 'code : ' . $e->code; } break; case 2: $client = new JPushClient($app_key_p, $master_secret_p); try { $result = $client->push()->setPlatform(M\platform('ios', 'android'))->setAudience(M\audience(M\registration_id(array($channelid))))->setNotification(M\notification($msg, M\android($msg), M\ios($msg, 'happy', 1, true, null, 'THE-CATEGORY')))->setMessage(M\message($msg, null, null, array('key' => 'value')))->setOptions(M\options(123456, null, null, false, 0))->send(); $return_arr = ["channelid" => $channelid]; include "../include/return_data.php"; } catch (APIRequestException $e) { echo 'code : ' . $e->code; } break; default: echo json_encode(0); break; } } else { echo json_encode(0); }
public function testAlertWinphone() { $client = new JPushClient($this->appKey, $this->masterSecret); $response = $client->push()->setPlatform(M\platform("winphone"))->setAudience(M\all)->setNotification(M\notification($this->alert))->send(); $this->assertTrue($response->isOk === true); }
/** * 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; } }
public function pushNotificationAlliOS($msg, $title = null, $extras = null) { $result = $this->client->push()->setPlatform(M\platform('ios'))->setAudience(M\all)->setNotification(M\notification($msg, M\android($msg, $title, null, $extras), M\ios($msg, 'happy', 0, null, $extras), M\winphone($msg, $title, null, $extras)))->setOptions(M\options(null, null, null, true, null))->send(); $this->writeLog($result); return $result->isOk; }
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;