TP Integrated Aurora Push

Source: Internet
Author: User
Tags sendmsg
Has any of the great gods ever done the aurora push? Trouble there is no code can give me a look.

On the internet to find a big God-sent source code but do not know how to put in the TP frame. I'll give you a little bit of code later.


Another: I want to ask if I wrote a function myself called jpush.php How do I call it in the controller? Which folder do you want to put this file in?

jpush.php

/**
* Aurora Push
* @author Dawn
* @Email jakehu1991@163.com
* @Website http://www.jakehu.me/
* @version 20130706
*/


Class Jpush {
Private $_mastersecret = ';
Private $_appkeys = ';

/**
* Constructor function
* @param string $username
* @param string $password
* @param string $appkeys
*/
function __construct ($masterSecret = ', $appkeys = ') {
$this->_mastersecret = $masterSecret;
$this->_appkeys = $appkeys;
}
/**
* Analog post for URL request
* @param string $url
* @param string $param
*/
function Request_post ($url = ', $param = ') {
if (Empty ($url) | | empty ($param)) {
return false;
}

$POSTURL = $url;
$curlPost = $param;
$ch = Curl_init ();//Initialize Curl
curl_setopt ($ch, Curlopt_url, $POSTURL);//crawl specified Web page
curl_setopt ($ch, Curlopt_header, 0);//Set HEADER
curl_setopt ($ch, Curlopt_returntransfer, 1);//requires the result to be a string and output to the screen
curl_setopt ($ch, Curlopt_post, 1);//post Submission method
curl_setopt ($ch, Curlopt_postfields, $curlPost);
$data = curl_exec ($ch);//Run Curl
Curl_close ($ch);

return $data;
}
/**
* Send
* @param int $sendno send number. Maintained by the developer, identifies a send request
* @param int $receiver _type recipient type. 1, the specified IMEI. Appkeys must be specified at this time. 2, the specified tag. 3, the specified alias. 4. Push messages to all users of the specified appkey.
* @param string $receiver _value Send range value, which corresponds to Receiver_type. 1, IMEI only support a 2, tag support multiple, use "," interval. 3, alias support multiple, use "," interval. 4, do not need to fill
* @param int $msg _type The type of message sent: 1, notification 2, custom message
* @param string $msg _content to send the contents of the message. Values corresponding to the Msg_type
* @param string $platform target user terminal phone platform type, such as: Android, iOS multiple please use comma delimited
*/
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 = ";
$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;
}

}

?>

send.php
/**
* Aurora Push
* @author Dawn
* @Email jakehu1991@163.com
* @Website http://www.jakehu.me/
* @version 20130706
*/

Include (' jpush.php ');
$n _title = ' 1231232 ';
$n _content = ' 12312321231232123123212312321231232 ';
$appkeys = ' 123123212312321231232 ';
$masterSecret = ' 1231232123123212312321231232 ';
$sendno = 4;
$receiver _value = ";
$platform = ' Android,ios ';
$msg _content = json_encode (Array (' n_builder_id ' =>0, ' n_title ' = $n _title, ' n_content ' = = $n _content));
$obj = new Jpush ($masterSecret, $appkeys);
$res = $obj->send ($sendno, 4, $receiver _value, 1, $msg _content, $platform);
Print_r ($res);
Exit ();
?>


Reply to discussion (solution)

Is there any great God who can guide ...

The class files in the SDK are placed in the vendor directory
Custom function know where it is ...
The function of TP in the Custom function vendor (' Jiguang.jpush ') introduced
A $ A = new \jpush () is required for instantiation;

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.