function capi_jpush($uidarr, $message, $title = null, $extras = null) { $client = new JPush(JPUSH_APP_KEY, JPUSH_MASTER_SECRET); try { $result = $client->push()->setPlatform(array('ios', 'android'))->addAlias($uidarr)->setNotificationAlert($message)->addAndroidNotification($message, $title, 1, $extras)->addIosNotification($message, JPUSH_IOS_SOUND, '+1', true, null, $extras)->send(); if (D_BUG) { runlog('jpush', 'Push Success:' . json_encode($result)); } } 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; */ if (D_BUG) { runlog('jpush', 'Push Fail:' . json_encode(array('error' => $e))); } } 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; */ if (D_BUG) { runlog('jpush', 'Push Fail:' . json_encode(array('ErrorMessage' => $e->getMessage(), 'IsResponseTimeout' => $e->isResponseTimeout))); } } //echo $br . '-------------' . $br; }
public function actionJPush() { $client = new JPush(Yii::app()->params['teacher_JPush']['app_key'], Yii::app()->params['teacher_JPush']['master_secret']); $result = $client->push()->setPlatform(array('ios', 'android'))->addAlias('alias1')->addTag('all')->setNotificationAlert('Hi, hello')->addAndroidNotification('Hi, android notification', 'notification title', 1, array("key1" => "value1", "key2" => "value2"))->addIosNotification("Hi, iOS notification", 'iOS sound', JPush::DISABLE_BADGE, true, 'iOS category', array("key1" => "value1", "key2" => "value2"))->setMessage("msg content", 'msg title', 'type', array("key1" => "value1", "key2" => "value2"))->setOptions(100000, 3600, null, false)->send(); $message = ""; //存储推送状态 if ($result) { $res_arr = json_encode($result, true); if (isset($res_arr['error'])) { //如果返回了error则证明失败 echo $res_arr['error']['message']; //错误信息 $error_code = $res_arr['error']['code']; //错误码 switch ($error_code) { case 200: $message = '发送成功!'; break; case 1000: $message = '失败(系统内部错误)'; break; case 1001: $message = '失败(只支持 HTTP Post 方法,不支持 Get 方法)'; break; case 1002: $message = '失败(缺少了必须的参数)'; break; case 1003: $message = '失败(参数值不合法)'; break; case 1004: $message = '失败(验证失败)'; break; case 1005: $message = '失败(消息体太大)'; break; case 1008: $message = '失败(appkey参数非法)'; break; case 1020: $message = '失败(只支持 HTTPS 请求)'; break; case 1030: $message = '失败(内部服务超时)'; break; default: $message = '失败(返回其他状态,目前不清楚额,请联系开发人员!)'; break; } } else { $message = "发送成功!"; } } else { //接口调用失败或无响应 $message = '接口调用失败或无响应'; } echo "推送信息:{$message}"; }
/** * @param $app_id * @param $user_id * @param $msg_type * @param $msg_title * @param $alert_content * @return bool */ public function pushMsg($app_id, $user_id, $msg_type, $msg_title, $alert_content) { if ($app_id == 10) { // 学员端jPush $app_key = Yii::app()->params['student_JPush']['app_key']; $masterSecret = Yii::app()->params['student_JPush']['master_secret']; } elseif ($app_id == 11) { // 教师端jPush $app_key = Yii::app()->params['teacher_JPush']['app_key']; $masterSecret = Yii::app()->params['teacher_JPush']['master_secret']; } else { return false; } $result = array(); try { // 调用jPush API $client = new JPush($app_key, $masterSecret); $result = $client->push()->setPlatform(array('ios', 'android'))->addAlias($user_id)->addTag('all')->addAndroidNotification($alert_content, $msg_title, 1, array("msg_type" => $msg_type, "msg_title" => $msg_title))->addIosNotification($alert_content, $msg_title, '+1', true, 'iOS category', array("msg_type" => $msg_type, "msg_title" => $msg_title))->setOptions(100000, 3600, null, false)->send(); } catch (Exception $e) { error_log($e); return false; } // $message=""; //存储推送状态 // if($result){ // $res_arr = json_encode($result, true); // if(isset($res_arr['error'])){ //如果返回了error则证明失败 // $message = $res_arr['error']['message']; //错误信息 // $error_code = $res_arr['error']['code']; //错误码 // self::insertPush($error_code, $message); // }else{ // $message="发送成功!"; // $error_code = 1111; // self::insertPush($error_code, $message); // } // }else{ //接口调用失败或无响应 // $message = '接口调用失败或无响应'; // $error_code = 0000; // self::insertPush($error_code, $message); // } return true; }
public function push_msg($msg) { require_once APPPATH . 'libraries/JPush/JPush.php'; $app_key = 'd6c00aaba4220737c096b0f5'; $master_secret = '6738878b5566b6a9275ac090'; // 初始化 $client = new JPush($app_key, $master_secret); // 简单推送示例 $result = $client->push()->setPlatform('all')->addAllAudience()->setNotificationAlert($msg)->send(); echo 'Result=' . json_encode($result); // // 完整的推送示例,包含指定Platform,指定Alias,Tag,指定iOS,Android notification,指定Message等 // $result = $client->push() // ->setPlatform(array('ios', 'android')) // ->addAlias('alias1') // ->addTag(array('tag1', 'tag2')) // ->setNotificationAlert('Hi, JPush') // ->addAndroidNotification('Hi, android notification', 'notification title', 1, array("key1"=>"value1", "key2"=>"value2")) // ->addIosNotification("Hi, iOS notification", 'iOS sound', JPush::DISABLE_BADGE, true, 'iOS category', array("key1"=>"value1", "key2"=>"value2")) // ->setMessage("msg content", 'msg title', 'type', array("key1"=>"value1", "key2"=>"value2")) // ->setOptions(100000, 3600, null, false) // ->send(); // echo 'Result=' . json_encode($result); // // 指定推送短信示例(推送未送达的情况下进行短信送达, 该功能需预付短信费用, 并调用Device API绑定设备与手机号) // $result = $client->push() // ->setPlatform('all') // ->addTag('tag1') // ->setNotificationAlert("Hi, JPush SMS") // ->setSmsMessage('Hi, JPush SMS', 60) // ->send(); // echo 'Result=' . json_encode($result); }
<?php /** * 该示例主要为JPush Schedule API的调用示例 * HTTP API文档:http://docs.jpush.io/server/rest_api_push_schedule/ * PHP API文档:https://github.com/jpush/jpush-api-php-client/blob/master/doc/api.md#schedule-api */ ini_set("display_errors", "On"); error_reporting(E_ALL | E_STRICT); require_once "../src/JPush/JPush.php"; $br = '<br/>'; $app_key = 'dd1066407b044738b6479275'; $master_secret = 'e8cc9a76d5b7a580859bcfa7'; // 初始化 $client = new JPush($app_key, $master_secret); $payload = $client->push()->setPlatform("all")->addAllAudience()->setNotificationAlert("Hi, 这是一条定时发送的消息")->build(); // 创建一个2016-12-22 13:45:00触发的定时任务 $response = $client->schedule()->createSingleSchedule("每天14点发送的定时任务", $payload, array("time" => "2016-12-22 13:45:00")); echo 'Result=' . json_encode($response) . $br; // 创建一个每天14点发送的定时任务 $response = $client->schedule()->createPeriodicalSchedule("每天14点发送的定时任务", $payload, array("start" => "2016-12-22 13:45:00", "end" => "2016-12-25 13:45:00", "time" => "14:00:00", "time_unit" => "DAY", "frequency" => 1)); echo 'Result=' . json_encode($response) . $br; // 更新指定的定时任务 $response = $client->schedule()->updatePeriodicalSchedule('89c984f4-a880-11e5-b41a-0021f652c102', null, true); echo "Result=" . json_encode($response) . "\r\n"; // 获取定时任务列表 $response = $client->schedule()->getSchedules(); echo "Result=" . json_encode($response) . "\r\n";
<?php /** * 该示例主要为JPush Push API的调用示例 * HTTP API文档:http://docs.jpush.io/server/rest_api_v3_push/ * PHP API文档:(待补充) */ require_once "../src/JPush/JPush.php"; $br = '<br/>'; $app_key = 'dd1066407b044738b6479275'; $master_secret = 'e8cc9a76d5b7a580859bcfa7'; // 初始化 $client = new JPush($app_key, $master_secret); // 简单推送示例 $result = $client->push()->setPlatform('all')->addAllAudience()->setNotificationAlert('Hi, JPush')->send(); echo 'Result=' . json_encode($result) . $br; // 完整的推送示例,包含指定Platform,指定Alias,Tag,指定iOS,Android notification,指定Message等 $result = $client->push()->setPlatform(array('ios', 'android'))->addAlias('alias1')->addTag(array('tag1', 'tag2'))->setNotificationAlert('Hi, JPush')->addAndroidNotification('Hi, android notification', 'notification title', 1, array("key1" => "value1", "key2" => "value2"))->addIosNotification("Hi, iOS notification", 'iOS sound', JPush::DISABLE_BADGE, true, 'iOS category', array("key1" => "value1", "key2" => "value2"))->setMessage("msg content", 'msg title', 'type', array("key1" => "value1", "key2" => "value2"))->setOptions(100000, 3600, null, false)->send(); echo 'Result=' . json_encode($result) . $br; // 指定推送短信示例(推送未送达的情况下进行短信送达, 该功能需预付短信费用, 并调用Device API绑定设备与手机号) $result = $client->push()->setPlatform('all')->addTag('tag1')->setNotificationAlert("Hi, JPush SMS")->setSmsMessage('Hi, JPush SMS', 60)->send(); echo 'Result=' . json_encode($result) . $br;
private function dealVoice($voice) { $len = mb_strlen($voice, 'utf-8'); if ($len > 3) { $navWord = mb_substr($voice, 0, 3, 'utf-8'); if ($navWord == "导航到") { $len = mb_strlen($voice, 'utf-8'); $navWord = mb_substr($voice, 3, $len - 3, 'utf-8'); $geourl = "http://api.map.baidu.com/geocoder/v2/?ak=m9fCLsMnPDsla4lTuKGNsw6c&callback=renderOption&output=xml&address={$navWord}"; $apistr = file_get_contents($geourl); //读取文件 $apiobj = simplexml_load_string($apistr); //xml解析 $lat = $apiobj->result->location->lat; $lng = $apiobj->result->location->lng; $br = '<br/>'; $app_key = 'ad2add0d7bafaab683ca3b16'; $master_secret = '2009611fff8213ed1bd0c3a6'; // 初始化 $client = new JPush($app_key, $master_secret); //$label='999899'; // 简单推送示例 $result = $client->push()->setPlatform('all')->addAllAudience()->setNotificationAlert("导航到" . "{$navWord}" . "(" . $lng . "," . $lat . ")")->send(); echo 'Result1=' . json_encode($result) . $br; //JPUSH应用 $app_key = '5f1e36080805488ab8f22631'; $master_secret = '2bd1c368081d8ad860afb867'; // 初始化 $client = new JPush($app_key, $master_secret); //$label='999899'; // 简单推送示例 $result = $client->push()->setPlatform('all')->addAllAudience()->setNotificationAlert("导航到" . "{$navWord}" . "(" . $lng . "," . $lat . ")")->send(); echo 'Result0=' . json_encode($result) . $br; $contentStr = "位置已发送,如果长时间未收到,可能是网络原因,请重试!"; } else { $contentStr = "您的语音有误,请重新输入"; } } else { $contentStr = "您的语音有误,请重新输入"; } return $contentStr; }