|
|
@@ -1,188 +0,0 @@
|
|
|
-<?php
|
|
|
-
|
|
|
-namespace common\components;
|
|
|
-
|
|
|
-use GTAlert;
|
|
|
-use GTAndroid;
|
|
|
-use GTAps;
|
|
|
-use GTClient;
|
|
|
-use GTIos;
|
|
|
-use GTMultimedia;
|
|
|
-use GTNotification;
|
|
|
-use GTPushChannel;
|
|
|
-use GTPushMessage;
|
|
|
-use GTPushRequest;
|
|
|
-use GTSettings;
|
|
|
-use GTStrategy;
|
|
|
-use GTThirdNotification;
|
|
|
-use GTUps;
|
|
|
-use GuzzleHttp\Client;
|
|
|
-use GuzzleHttp\Exception\GuzzleException;
|
|
|
-use Yii;
|
|
|
-
|
|
|
-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)
|
|
|
- {
|
|
|
- $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 = new GTPushMessage();
|
|
|
- $message->setNotification($notify);
|
|
|
-
|
|
|
- //设置推送参数
|
|
|
- $push = new GTPushRequest();
|
|
|
- $time = time();
|
|
|
- $rand = rand(1000, 9999);
|
|
|
- $rId = $time . $rand . $adminId;
|
|
|
- $push->setRequestId($rId);
|
|
|
- $push->setPushMessage($message);
|
|
|
- $push->setCid($cId);
|
|
|
-
|
|
|
- //创建API,APPID等配置参考 环境要求 进行获取
|
|
|
- $api = new GTClient(self::domainUrl, self::appKey, self::appId, self::masterSecret);
|
|
|
- $api->pushApi()->pushToSingleByCid($push);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public static function gtPush($cId, $title, $body)
|
|
|
- {
|
|
|
- Yii::info('start -- push/single/cid');
|
|
|
- $set = new GTSettings();
|
|
|
- $set->setTtl(3600000);
|
|
|
- $strategy = new GTStrategy();
|
|
|
- $strategy->setDefault(GTStrategy::STRATEGY_THIRD_FIRST);
|
|
|
- // $strategy->setIos(GTStrategy::STRATEGY_GT_ONLY);
|
|
|
- // $strategy->setOp(GTStrategy::STRATEGY_THIRD_FIRST);
|
|
|
- // $strategy->setHw(GTStrategy::STRATEGY_THIRD_ONLY);
|
|
|
- $set->setStrategy($strategy);
|
|
|
-
|
|
|
-
|
|
|
- //设置推送参数
|
|
|
- $push = new GTPushRequest();
|
|
|
- $push->setRequestId(self::micro_time());
|
|
|
- $push->setSettings($set);
|
|
|
-
|
|
|
- $message = new GTPushMessage();
|
|
|
- $notify = new GTNotification();
|
|
|
- $notify->setTitle($title);
|
|
|
- $notify->setBody($body);
|
|
|
- $notify->setChannelId('channelId1');
|
|
|
- $notify->setChannelName('channelName1');
|
|
|
- $notify->setChannelLevel(4);
|
|
|
-
|
|
|
- //点击通知后续动作,目前支持以下后续动作:
|
|
|
- //1、intent:打开应用内特定页面 url:打开网页地址。2、payload:自定义消息内容启动应用。
|
|
|
- //3、payload_custom:自定义消息内容不启动应用。4、startapp:打开应用首页。5、none:纯通知,无后续动作
|
|
|
- $notify->setClickType("startapp");
|
|
|
- $message->setNotification($notify);
|
|
|
- $push->setPushMessage($message);
|
|
|
- $push->setCid($cId);
|
|
|
-
|
|
|
-
|
|
|
- //厂商推送消息参数
|
|
|
- $pushChannel = new GTPushChannel();
|
|
|
-
|
|
|
- // ------------- ios ---------------
|
|
|
- $ios = new GTIos();
|
|
|
- $ios->setType("notify");
|
|
|
- //$ios->setAutoBadge("1");
|
|
|
- //$ios->setPayload("ios_payload");
|
|
|
- //$ios->setApnsCollapseId("apnsCollapseId");
|
|
|
-
|
|
|
- //aps设置
|
|
|
- $aps = new GTAps();
|
|
|
- $aps->setContentAvailable(0);
|
|
|
- $aps->setSound("com.gexin.ios.silenc");
|
|
|
- //$aps->setCategory("category");
|
|
|
- //$aps->setThreadId("threadId");
|
|
|
-
|
|
|
- $alert = new GTAlert();
|
|
|
- $alert->setTitle($title);
|
|
|
- $alert->setBody($body);
|
|
|
-
|
|
|
- /*$alert->setActionLocKey("ActionLocKey");
|
|
|
- $alert->setLocKey("LocKey");
|
|
|
- $alert->setLocArgs(array("LocArgs1", "LocArgs2"));
|
|
|
- $alert->setLaunchImage("LaunchImage");
|
|
|
- $alert->setTitleLocKey("TitleLocKey");
|
|
|
- $alert->setTitleLocArgs(array("TitleLocArgs1", "TitleLocArgs2"));
|
|
|
- $alert->setSubtitle("Subtitle");
|
|
|
- $alert->setSubtitleLocKey("SubtitleLocKey");
|
|
|
- $alert->setSubtitleLocArgs(array("subtitleLocArgs1", "subtitleLocArgs2"));*/
|
|
|
-
|
|
|
- $aps->setAlert($alert);
|
|
|
- $ios->setAps($aps);
|
|
|
-
|
|
|
- /*$multimedia = new GTMultimedia();
|
|
|
- $multimedia->setUrl("url");
|
|
|
- $multimedia->setType(1);
|
|
|
- $multimedia->setOnlyWifi(false);
|
|
|
- $multimedia2 = new GTMultimedia();
|
|
|
- $multimedia2->setUrl("url2");
|
|
|
- $multimedia2->setType(2);
|
|
|
- $multimedia2->setOnlyWifi(true);
|
|
|
- $ios->setMultimedia(array($multimedia));
|
|
|
- $ios->addMultimedia($multimedia2);*/
|
|
|
- $pushChannel->setIos($ios);
|
|
|
- // ------------- ios end ---------------
|
|
|
-
|
|
|
-
|
|
|
- // ----------------- 安卓 -----------------
|
|
|
- $android = new GTAndroid();
|
|
|
- $ups = new GTUps();
|
|
|
- //$ups->setTransmission("ups Transmission");
|
|
|
- $ups->addOption("HW","badgeAddNum",1);
|
|
|
- $ups->addOption("HW", "/message/android/urgency","HIGH");
|
|
|
- $ups->addOption("HW", "/message/android/category", "WORK");
|
|
|
- $ups->addOption("HW", "/message/android/notification/importance", "NORMAL");
|
|
|
-
|
|
|
- //$ups->addOption("OP","channel","Default");
|
|
|
- $ups->addOption("OP","/classification",1);
|
|
|
- //$ups->addOption(null,"a","b");
|
|
|
-
|
|
|
- $thirdNotification = new GTThirdNotification();
|
|
|
- $thirdNotification->setTitle($title);
|
|
|
- $thirdNotification->setBody($body);
|
|
|
- $thirdNotification->setClickType(GTThirdNotification::CLICK_TYPE_STAERAPP);
|
|
|
- //$thirdNotification->setIntent("intent:#Intent;component=你的包名/你要打开的 activity 全路径;S.parm1=value1;S.parm2=value2;end");
|
|
|
- //$thirdNotification->setUrl("http://docs.getui.com/getui/server/rest_v2/push/");
|
|
|
- //$thirdNotification->setPayload("payload");
|
|
|
- $thirdNotification->setNotifyId(time());
|
|
|
-
|
|
|
- $ups->setNotification($thirdNotification);
|
|
|
- $android->setUps($ups);
|
|
|
- $pushChannel->setAndroid($android);
|
|
|
- // ----------------- 安卓 end -----------------
|
|
|
-
|
|
|
- $push->setPushChannel($pushChannel);
|
|
|
-
|
|
|
-
|
|
|
- //创建API,APPID等配置
|
|
|
- $api = new GTClient(self::domainUrl, self::appKey, self::appId, self::masterSecret);
|
|
|
- //处理返回结果
|
|
|
- $result = $api->pushApi()->pushToSingleByCid($push);
|
|
|
- Yii::info('push/single/cid: ' . json_encode($result));
|
|
|
- }
|
|
|
-
|
|
|
- public static function micro_time()
|
|
|
- {
|
|
|
- list($usec, $sec) = explode(" ", microtime());
|
|
|
- $time = ($sec . substr($usec, 2, 3));
|
|
|
- return $time;
|
|
|
- }
|
|
|
-}
|