PHP Aurora push (PUSH-API-V3)
- Error_reporting (E_all^e_notice);
- Class apipostaction{
- Private $_appkeys = ' f722b1337ded8******** ';
- Private $_mastersecret = ' bd267a37c3034fd6******* ';
- function Request_post ($url = "", $param = "", $header = "") {
- 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);
- curl_setopt ($ch, Curlopt_httpheader, $header);
- Add a field in the HTTP header (header)
- curl_setopt ($ch, Curlopt_ssl_verifypeer, FALSE);
- Terminating validation from the service side
- curl_setopt ($ch, Curlopt_ssl_verifyhost, FALSE);
- $data = curl_exec ($ch);//Run Curl
- Curl_close ($ch);
- return $data;
- }
- function Send ($title, $message)
- {
- $url = ' Https://api.jpush.cn/v3/push ';
- $base 64=base64_encode ("$this->_appkeys: $this->_mastersecret");
- $header =array ("Authorization:basic $base", "Content-type:application/json");
- Print_r ($header);
- $param = ' {"Platform": "All", "audience": "All", "notification": {"alert": "hi,jpush!"}, "message": {"msg_content": "'. $ Message. ' "," title ":" '. $title. ' "}} ';
- $res = $this->request_post ($url, $param, $header);
- $res _arr = Json_decode ($res, true);
- Print_r ($res _arr);
- }
- }
- $jpush =new apipostaction ();
- $jpush->send (' This title ', ' This mesage ');
Copy Code |