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; } }
/** * [push 根据别名推送] * @param [type] $alias [对象别名] * @param [type] $msg [信息数组] * @return [type] [description] */ public function push_by_alias($alias, $title, $content, $msg) { try { $client = new JPushClient($this->app_key, $this->master_secret); $result = $client->push()->setPlatform(M\all)->setAudience(M\audience(M\alias($alias)))->setNotification(M\notification(M\android($content, $title, null, $msg), M\ios($title, null, null, null, $msg)))->send(); } catch (APIRequestException $e) { } catch (APIConnectionException $e) { } }
/** * 推送 push_message */ public function push_message_registration($ids = array(), $notification = array()) { if ($ids && $notification) { vendor('jpush.autoload'); $app_key = C('API_PUSH_JPUSH.key'); $master_secret = C('API_PUSH_JPUSH.secret'); $client = new JPushClient($app_key, $master_secret); $client->push()->setPlatform(M\all)->setAudience(M\registration_id($ids))->setNotification(M\notification($notification['title'], M\android($notification['title'], $notification['title'], NULL, $notification['extras']), M\ios($notification['title'], 'default', 1)))->setOptions(M\options(NULL, NULL, NULL, true))->send(); } }
function pushAll($msg, $title = null, $arr = null) { try { $jpushClient = $this->client; $result = $jpushClient->push()->setPlatform(M\all)->setAudience(M\all)->setNotification(M\notification(M\android($msg, $title, null, $arr), M\ios($msg, 'default', '+1', true, $arr)))->send(); return array('status' => true, 'msg' => '发送成功!'); } catch (APIConnectionException $e) { return array('status' => false, 'msg' => '推送失败!'); } catch (APIRequestException $e) { return array('status' => false, 'msg' => $e->getMessage()); } catch (InvalidArgumentException $e) { return array('status' => false, 'msg' => '推送失败!'); } }
public static function pushMessage($uids, $alert, array $extras = null) { $config = self::getConfig(); $app_key = $config['app_key']; $master_secret = $config['master_secret']; if (!$app_key || !$master_secret) { return; } $client = new JPushClient($app_key, $master_secret); try { $uids = array_values(array_map('strval', $uids)); $audience = M\audience(M\alias($uids)); $notification = M\notification($alert, M\android($alert, null, null, $extras), M\ios($alert, null, null, null, $extras)); $result = $client->push()->setPlatform(M\all)->setAudience($audience)->setNotification($notification)->send(); //echo 'Push Success.' . PHP_EOL; //echo 'sendno : ' . $result->sendno . PHP_EOL; //echo 'msg_id : ' .$result->msg_id . PHP_EOL; //echo 'Response JSON : ' . $result->json . PHP_EOL; } catch (\Exception $e) { echo 'Push Fail: ' . $e->getMessage() . PHP_EOL; } }
public function testGlobalExceedLength4() { $tooBig220 = "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; $tooBig1200 = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; $payload = new M\PushPayload(null); $result = $payload->setPlatform(M\all)->setAudience(M\all)->setNotification(M\notification("HI, JPush", M\ios("Hi, JPUsh"), M\android($tooBig1200)))->setMessage(M\message("Hi,JPush"))->isGlobalExceedLength(); $this->assertEquals(true, $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 testNotificationIOSFull() { $client = new JPushClient($this->appKey, $this->masterSecret); $response = $client->push()->setPlatform(M\all)->setAudience(M\all)->setNotification(M\notification(null, M\ios($this->alert, 'happy', 1, true, $this->extras)))->send(); $this->assertTrue($response->isOk === true); }
<?php require_once '../../third_party/vendor/autoload.php'; use JPush\Model as M; use JPush\JPushClient; use JPush\Exception\APIConnectionException; use JPush\Exception\APIRequestException; $app_key = '74a7874f76fa5eb4e6baa6b3'; $master_secret = 'd50c83278b63a7b004da7364'; $br = '<br/>'; $client = new JPushClient($app_key, $master_secret); if (!isset($_POST['k'])) { exit; } $msg = $_POST['k']; $result = $client->push()->setPlatform(M\all)->setAudience(M\all)->setOptions(M\options(123456, null, null, true, 60))->setNotification(M\notification(M\ios($msg, 'happy', 1, true)))->send(); header('Location:' . $_SERVER['HTTP_REFERER']);
/** * 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;
use JPush\Model as M; use JPush\JPushClient; use JPush\JPushLog; use Monolog\Logger; use Monolog\Handler\StreamHandler; use JPush\Exception\APIConnectionException; use JPush\Exception\APIRequestException; $br = '<br/>'; $spilt = ' - '; $master_secret = 'd94f733358cca97b18b2cb98'; $app_key = '47a3ddda34b2602fa9e17c01'; 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', M\ios("Hi, IOS", "happy", "+1")))->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;
public function pushNotificationAll($msg, $title = null, $extras = null) { $result = $this->client->push()->setPlatform(M\all)->setAudience(M\all)->setNotification(M\notification($msg, M\android($msg, $title, null, $extras), M\ios($msg, null, null, null, $extras), M\winphone($msg, $title, null, $extras)))->send(); return $result->isOk; }
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;