pushNotice.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace common\components;
  3. class pushNotice
  4. {
  5. const domainUrl = 'https://restapi.getui.com';
  6. const appKey = 'uC5ZdrWSV48cLRBJWMSId9';
  7. const appId = 'YjALucIHmI7DylcjlMZEx2';
  8. const masterSecret = 'zSbdBLOQrxAa5IcDNqIne7';
  9. public static function push($adminId, $cId, $title, $body)
  10. {
  11. //创建API,APPID等配置参考 环境要求 进行获取
  12. $api = new \GTClient(self::domainUrl, self::appKey, self::appId, self::masterSecret);
  13. //设置推送参数
  14. $push = new \GTPushRequest();
  15. $time = time();
  16. $rand = rand(1000, 9999);
  17. $rId = $time . $rand . $adminId;
  18. $push->setRequestId($rId);
  19. $message = new \GTPushMessage();
  20. $notify = new \GTNotification();
  21. $notify->setTitle($title);
  22. $notify->setBody($body);
  23. //点击通知后续动作,目前支持以下后续动作:
  24. //1、intent:打开应用内特定页面url:打开网页地址。2、payload:自定义消息内容启动应用。3、payload_custom:自定义消息内容不启动应用。4、startapp:打开应用首页。5、none:纯通知,无后续动作
  25. $notify->setClickType("startapp");
  26. //保证有振动
  27. $notify->setChannelId('channelId1');
  28. $notify->setChannelName('channelName1');
  29. $notify->setChannelLevel(4);
  30. $message->setNotification($notify);
  31. $push->setPushMessage($message);
  32. //客户ID
  33. $push->setCid($cId);
  34. $api->pushApi()->pushToSingleByCid($push);
  35. }
  36. }