Apicloud的云推送api, php版

  1. class ApicloudPush
  2. {
  3. public static $api = 'https://p.apicloud.com/api/push/message';
  4. public static $appid = 'A6920463******';
  5. public static $appkey = 'C******8-B6BB-3027-2C93-6C********29';
  6. public static function post($post_data)
  7. {
  8. $appkey = sha1(self::$appid . "UZ" . self::$appkey . "UZ" . time()) . "." . time();
  9. $ch = curl_init ();
  10. curl_setopt ($ch, CURLOPT_HTTPHEADER, [
  11. 'X-APICloud-AppId:'. self::$appid,
  12. 'X-APICloud-AppKey:' . $appkey
  13. ]);
  14. curl_setopt($ch, CURLOPT_POST, count($post_data));
  15. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  16. curl_setopt($ch, CURLOPT_URL, self::$api);
  17. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
  18. ob_start ();
  19. curl_exec ($ch);
  20. $result = ob_get_contents ();
  21. ob_end_clean();
  22. curl_close ($ch);
  23. return $result;
  24. }
  25. }
  26. $title = isset($_GET['title']) ? $_GET['title'] : '测试标题';
  27. $content = isset($_GET['content']) ? $_GET['content'] : '测试内容';
  28. var_dump(ApicloudPush::post([
  29. 'title' => $title,
  30. 'content' => $content,
  31. 'type' => 2, //– 消息类型,1:消息 2:通知
  32. 'platform' => 0, //0:全部平台,1:ios, 2:android
  33. // 'groupName' => 'department', //推送组名,多个组用英文逗号隔开.默认:全部组。eg.group1,group2 .
  34. // 'userIds' => 'shuai' //推送用户id, 多个用户用英文逗号分隔,eg. user1,user2。
  35. ]));
文章不错, 赏你二两银子

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续努力!