Esempio n. 1
0
 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;
     }
 }
Esempio n. 2
0
 /**
  * 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();
 }
Esempio n. 3
0
 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();
 }
Esempio n. 4
0
 private function _get_audience($alias = array())
 {
     $audience = M\all;
     if (!empty($alias)) {
         $audience = M\audience(M\alias($alias));
     }
     return $audience;
 }
Esempio n. 5
0
 /**
  * 根据别名推送消息
  * @param $content
  * @param $title
  * @param $extras
  * @param $alias array
  */
 public function pushMessageByAlias($content, $title, $extras, $alias)
 {
     $client = new JPushClient($this->app_key, $this->master_secret);
     try {
         $result = $client->push()->setPlatform(M\all)->setAudience(M\audience(M\alias($alias)))->setNotification(M\notification(M\android($content, $title, 3, $extras)))->send();
     } catch (APIRequestException $e) {
     } catch (APIConnectionException $e) {
     }
 }
Esempio n. 6
0
 /**
  * [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) {
     }
 }
Esempio n. 7
0
 /**
  * 推送方法
  * @param array $alias 别名
  * @param string $msg 推送信息
  * @param array $arr 附加信息数组
  * */
 function pushByAlias($alias, $msg, $title, $arr)
 {
     try {
         $jpushClient = $this->client;
         $result = $jpushClient->push()->setPlatform(M\all)->setAudience(M\audience(M\alias($alias)))->setNotification(M\notification(M\android($msg, $title, null, $arr), M\ios($msg, 'default', '+1', true, $arr)))->setOptions(M\options(null, null, null, true, null))->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' => '推送失败!');
     }
 }
Esempio n. 8
0
 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;
     }
 }
Esempio n. 9
0
 public function easy_push($id, $content = 'hello')
 {
     $br = '<br/>';
     $spilt = ' - ';
     $master_secret = '3dd1c77ac980516110338aa5';
     $app_key = 'ab36dbc34e0501604d25974e';
     JPushLog::setLogHandlers(array(new StreamHandler('jpush.log', Logger::DEBUG)));
     $client = new JPushClient($app_key, $master_secret);
     $json = array('type' => 2);
     //echo $json;
     try {
         $result = $client->push()->setPlatform(M\all)->setAudience(M\alias(array($id)))->setNotification(M\notification($content, M\android('hi,android', $title = null, $builder_id = null, $extras = $json)))->printJSON()->send();
         /*$result = $client->push()
           ->setPlatform(M\all)
           ->setAudience(M\alias(array($id)))
           ->setNotification(M\notification($content))
           ->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;
     }
 }
Esempio n. 10
0
 /**
  * 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;
     }
 }
Esempio n. 11
0
 public function pushMessageByAlias($alias, $msg_content, $title = null, $content_type = null, $extras = null)
 {
     $result = $this->client->push()->setPlatform(M\all)->setAudience(M\audience(M\alias(explode(',', $alias))))->setMessage(M\message($msg_content, $title, $content_type, $extras))->setOptions(M\options(null, null, null, true, null))->send();
     $this->writeLog($result);
     return $result->isOk;
 }
Esempio n. 12
0
    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;
Esempio n. 13
0
 /**
  * 标记发现交警的地点, 并向附近用户推送提示信息
  * @method markPolice
  * @return [type]
  *
  * @author wesley zhang <*****@*****.**>
  * @since  2015-08-11T16:30:19+0800
  */
 function markPolice()
 {
     global $db;
     $userid = $_REQUEST['userid'];
     $long = $_REQUEST['long'];
     $lat = $_REQUEST['lat'];
     $imgurl = $_REQUEST['imgurl'];
     $content = $_REQUEST['content'];
     $address = $_REQUEST['address'];
     if (!$userid) {
         $this->res['error'] = 1;
         $this->res['msg'] = '用户id不存在';
         return $this->res;
     }
     $aNewRec = array('user_id' => $userid, 'longitude' => $long, 'latitude' => $lat, 'image_url' => $imgurl, 'content' => $content, 'address' => $address, 'created_date' => $db->now());
     $id = $db->insert('mark_trafficpolice', $aNewRec);
     //获得附近停车用户
     $aUsers = $this->_getNearbyUsers($long, $lat);
     $sPushMsg = '您当前' . $this->searchRadius . '千米的范围内有交警,请注意!';
     if (count($aUsers)) {
         $sMsgType = 'markPolice';
         //去除重复用户
         $aPushAlias = array();
         $aPushUsersInfo = array();
         foreach ($aUsers as $user) {
             if (!in_array($user['user_name'], $aPushAlias) && $userid != $user['user_id']) {
                 $aPushAlias[] = $user['user_name'];
                 $aPushUsersInfo[] = $user;
             }
         }
         // 使用jpush 推送消息,
         // Options: 第一个参数为sendno,纯粹用来作为 API 调用标识,API 返回时被原样返回,以方便 API 调用方匹配请求与返回。
         //Options: 第二个参数为time_to_live,0 表示不保留离线消息,只有推送当前在线的用户可以收到。默认 86400 (1 天),最长 10 天
         // Options: http://docs.jpush.io/server/rest_api_v3_push/#options
         try {
             $client = new JPushClient($this->appKey, $this->masterSecret);
             $response = $client->push()->setPlatform(M\all)->setAudience(M\audience(M\alias($aPushAlias)))->setNotification(M\notification($sPushMsg))->setOptions(M\options($id, 0, null, true))->send();
             // $aPusRes = $this->_objectToArray($response);
             // if($response->isOk == 1){
             //      //推送成功, 标记用户收到推送
             // }
         } catch (Exception $e) {
             // print('<pre>');
             // print_r($e->getMessage());
             // print('</pre>');
         }
         //不管推送是否成功, 都标记用户收到
         foreach ($aPushUsersInfo as $user) {
             $aNewLog = array('mt_id' => $id, 'user_id' => $user['user_id'], 'push_content' => $sPushMsg, 'push_param' => $response->json, 'created_date' => $db->now());
             $db->insert('mark_trafficpolice_received', $aNewLog);
         }
     }
     $aRes = array('id' => $id);
     if ($id) {
         $this->res['data'] = $aRes;
         $this->res['error'] = 0;
         $this->res['msg'] = '保存成功';
     } else {
         $this->res['error'] = 1;
         $this->res['msg'] = '保存失败';
     }
     return $this->res;
 }
Esempio n. 14
0
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;
Esempio n. 15
0
 public function testSendByTagAlias_0_2()
 {
     $client = new JPushClient($this->appKey, $this->masterSecret);
     $response = $client->push()->setPlatform(M\all)->setAudience(M\audience(M\tag(array($this->tag_all)), M\alias(array($this->alias_no))))->setNotification(M\notification($this->alert))->send();
     $this->assertTrue($response->isOk === true);
 }
Esempio n. 16
0
 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);
 }
Esempio n. 17
0
 public function push()
 {
     if ($this->param['type'] === null || $this->param['ispushservice'] === null || $this->param['phone'] === null || $this->param['content'] === null || $this->param['shop_id'] === null) {
         return $this->returnResult($this->DATAERROR, '数据错误!');
     }
     if (strlen($this->param['phone']) != 11) {
         return $this->returnResult($this->DATAERROR, '数据错误!');
     }
     if ($this->param['phone'] == '') {
         return $this->returnResult($this->DATAERROR, '数据错误!');
     }
     $userinfo = UserBase::findFirst("user_account = " . $this->param['phone']);
     if (!$userinfo) {
         return $this->returnResult($this->DATAERROR, '数据错误!');
     }
     $user_id = $userinfo->user_id;
     $usermessage = new UserMessage();
     $usermessage->user_id = $user_id;
     if ($this->param['ispushservice'] == 1) {
         $usermessage->is_read_b = 0;
     } else {
         $usermessage->is_read_b = 1;
     }
     $usermessage->message_content = $this->param['content'];
     $usermessage->push_type = $this->param['type'];
     $usermessage->message_state = 1;
     $usermessage->shop_id = $this->param['shop_id'];
     $usermessage->from_user_name = 1;
     $usermessage->from_user_cover = 1;
     $this->db->begin();
     $message_status = $usermessage->save();
     //添加数据到user_message
     if (!$message_status) {
         $this->db->rollback();
         return $this->returnResult($this->MYSQLERROR, "数据库错误");
     }
     /*推送至APP代码*/
     $config = $this->di->get('appConfig')->jpush;
     $app_key = $config->app_key;
     $master_secret = $config->master_secret;
     JPushLog::setLogHandlers([new StreamHandler('jpush.log', Logger::DEBUG)]);
     $client = new JPushClient($app_key, $master_secret);
     //easy push
     try {
         $result = $client->push()->setPlatform(M\all)->setAudience(M\alias([$user_id]))->setNotification(M\notification($this->param['content']))->setOptions(M\options(null, null, null, true, null))->send();
         if ($result->isOk === true) {
             $this->db->commit();
             return $this->returnResult($this->SUCCESS, "推送成功!");
         } else {
             $this->db->rollback();
             return $this->returnResult($this->PUSHFAIL, "推送失败!");
         }
     } 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>';
          		exit; */
         $this->db->rollback();
         return $this->returnResult($this->PUSHFAIL, "推送失败!");
     } catch (APIConnectionException $e) {
         $this->db->rollback();
         return $this->returnResult($this->PUSHFAIL, "推送失败!");
     }
     /*the end*/
 }