PHP Aurora push (PUSH-API-V3)

Source: Internet
Author: User
PHP Aurora push (PUSH-API-V3)




  1. Error_reporting (E_all^e_notice);
  2. Class apipostaction{
  3. Private $_appkeys = ' f722b1337ded8******** ';
  4. Private $_mastersecret = ' bd267a37c3034fd6******* ';
  5. function Request_post ($url = "", $param = "", $header = "") {
  6. if (Empty ($url) | | empty ($param)) {
  7. return false;
  8. }
  9. $POSTURL = $url;
  10. $curlPost = $param;
  11. $ch = Curl_init ();//Initialize Curl
  12. curl_setopt ($ch, Curlopt_url, $POSTURL);//crawl specified Web page
  13. curl_setopt ($ch, Curlopt_header, 0);//Set HEADER
  14. curl_setopt ($ch, Curlopt_returntransfer, 1);//requires the result to be a string and output to the screen
  15. curl_setopt ($ch, Curlopt_post, 1);//post Submission method
  16. curl_setopt ($ch, Curlopt_postfields, $curlPost);
  17. curl_setopt ($ch, Curlopt_httpheader, $header);
  18. Add a field in the HTTP header (header)
  19. curl_setopt ($ch, Curlopt_ssl_verifypeer, FALSE);
  20. Terminating validation from the service side
  21. curl_setopt ($ch, Curlopt_ssl_verifyhost, FALSE);
  22. $data = curl_exec ($ch);//Run Curl
  23. Curl_close ($ch);
  24. return $data;
  25. }
  26. function Send ($title, $message)
  27. {
  28. $url = ' Https://api.jpush.cn/v3/push ';
  29. $base 64=base64_encode ("$this->_appkeys: $this->_mastersecret");
  30. $header =array ("Authorization:basic $base", "Content-type:application/json");
  31. Print_r ($header);
  32. $param = ' {"Platform": "All", "audience": "All", "notification": {"alert": "hi,jpush!"}, "message": {"msg_content": "'. $ Message. ' "," title ":" '. $title. ' "}} ';
  33. $res = $this->request_post ($url, $param, $header);
  34. $res _arr = Json_decode ($res, true);
  35. Print_r ($res _arr);
  36. }
  37. }
  38. $jpush =new apipostaction ();
  39. $jpush->send (' This title ', ' This mesage ');
Copy Code
  • 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.