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