Examples of APP interface integration written thinkphp push Aurora

Let's look at an article about thinkphp write APP interface integration Aurora push for app data had to be achieved through the interface, of course, but this is very little of the built-in database.
Recently wrote interfaces used by third-party App Thinkphp a push, you push third-party tools used in this article is aurora push, push does not describe other.
Step One: Download and PHPSDK to the official online registration application will app_key, master_secret inside the file
download address: https: //www.jpush.cn/common/downloads/resource/1460966988359
Step two: after extracting file src -> the JPush files and folders to ORG-> push in (need to create a folder) or into the vender in
step 3: create push method in common controller CommonAction in
private $ app_key = ****;
**** the master_secret $ = Private;
public Push function ()
{
Import ( "ORG.Push.Push");
$ Client = new new JPush ($ this-> app_key, this- $> the master_secret);
$ $ Client Result = -> push ()
-> setPlatform ( 'All')
-> addAllAudience ()
-> setNotificationAlert ( "What is push test")
-> Send ();
.. // echo 'the Result =' json_encode (Result $) $ br;
}
This will complete the basic push
other features related to the item is not written to understand no more:
https://github.com/jpush/jpush PHP-Client--API / BLOB / Master / DOC / api.md #-Device API
====== ====== ornate frame line
in another way:
<PHP?
//jpush.php this method is used to push curl transmission request
class jpush {
Private _masterSecret $ = '';
Private _appkeys $ = '';

/**
* 构造函数
* @param string $username
* @param string $password
* @param string $appkeys
*/
function __construct($masterSecret = '',$appkeys = '') {
$this->_masterSecret = $masterSecret;
$this->_appkeys = $appkeys;
}
/**
* 模拟post进行url请求
* @param string $url
* @param string $param
*/
function request_post($url = '', $param = '') {
if (empty($url) || empty($param)) {
return false;
}

posturl URL = $ $;
$ curlPost = $ param;
$ curl_init CH = (); // initialize curl
curl_setopt ($ CH, CURLOPT_URL to, $ posturl); // fetch a given page
curl_setopt ($ ch, CURLOPT_HEADER, 0 ); // set header
curl_setopt ($ CH, CURLOPT_RETURNTRANSFER,. 1); // string and outputs the result of the requirements to the screen
curl_setopt ($ ch, CURLOPT_POST, 1 ); // post submission
curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ curlPost );
$ Data = the curl_exec ($ CH); // run curl
curl_close ($ CH);

Data $ return;
}
/ **
* Send
* @param transmission ID int $ sendno. Maintained by the developers themselves, identify a send request
* @param int $ receiver_type recipient type. 1, specified IMEI. At this point you must be specified appKeys. 2, the specified tag. 3, the specified alias. 4, the push message to the specified appkey all users.
* @Param string $ receiver_value transmission range of values, the corresponding receiver_type. 1, IMEI only supports a 2, tag support multiple use "," spacer. 3, alias support for multiple use, "" interval. 4, need not fill
* @param type of message sent int $ msg_type: 1, 2 notification, custom message
* @param string $ msg_content transmitted message content. And a value corresponding to msg_type
* @param string $ platform destination user equipment platform type of mobile phones, such as: android, ios plurality use a comma
* /
function Send ($ sendno = 0, = $ receiver_type. 1, receiver_value = $ ' ', $ MSG_TYPE =. 1, msg_content = $' ', $ = Platform' Android, iOS ') {
$ URL =' http://api.jpush.cn:8800/sendmsg/v2/sendmsg ';

$param .= '&sendno='.$sendno;
$appkeys = $this->_appkeys;
$param .= '&app_key='.$appkeys;
$param .= '&receiver_type='.$receiver_type;
$param .= '&receiver_value='.$receiver_value;
$masterSecret = $this->_masterSecret;
$verification_code = md5($sendno.$receiver_type.$receiver_value.$masterSecret);
$param .= '&verification_code='.$verification_code;
$param .= '&msg_type='.$msg_type;
$param .= '&msg_content='.$msg_content;
$param .= '&platform='.$platform;
$res = $this->request_post($url, $param);
if ($res === false) {
return false;
}
$res_arr = json_decode($res, true);
return $res_arr;
}

}
?>
Called:
? <PHP
the include ( 'jpush.php');
$ n_title = 'relay poise';
$ n_content = 'relay poise life';
$ ARR = Array ( 'Fromer' => 'sender' 'fromer_name' => 'sender name', 'fromer_icon' => 'sender avatar', 'image' => 'send image link', 'sound' => 'send music links'); // custom parameters
$ appkeys = 'upload an app application program, automatically generated Key';
$ MasterSecret = 'AppKey below on the same generated keys mastersecret a';
$ sendno =. 4;
$ receiver_value = '';
$ Platform = 'the Android, the iOS' ;
$ msg_content = json_encode (Array ( 'n_builder_id' => 0, 'n_title' => $ n_title, 'n_content' => $ n_content, 'n_extras' => $ ARR));
$ obj = new new jpush ($ MasterSecret, $ appkeys);
$res = $obj->send($sendno, 4, $receiver_value, 1, $msg_content, $platform);
print_r($res);
exit();
?>

Guess you like

Origin www.cnblogs.com/liushuang1/p/11204916.html