shizhongqi 4 жил өмнө
parent
commit
b500c0cf0e

+ 92 - 4
common/components/pushNotice.php

@@ -2,10 +2,20 @@
 
 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;
@@ -23,7 +33,7 @@ class pushNotice
 
     public static function push($adminId, $cId, $title, $body)
     {
-        $notify = new \GTNotification();
+        $notify = new GTNotification();
         $notify->setTitle($title);
         $notify->setBody($body);
         //点击通知后续动作,目前支持以下后续动作:
@@ -34,11 +44,11 @@ class pushNotice
         $notify->setChannelName('channelName1');
         $notify->setChannelLevel(4);
 
-        $message = new \GTPushMessage();
+        $message = new GTPushMessage();
         $message->setNotification($notify);
 
         //设置推送参数
-        $push = new \GTPushRequest();
+        $push = new GTPushRequest();
         $time = time();
         $rand = rand(1000, 9999);
         $rId = $time . $rand . $adminId;
@@ -47,19 +57,31 @@ class pushNotice
         $push->setCid($cId);
 
         //创建API,APPID等配置参考 环境要求 进行获取
-        $api = new \GTClient(self::domainUrl, self::appKey, self::appId, self::masterSecret);
+        $api = new GTClient(self::domainUrl, self::appKey, self::appId, self::masterSecret);
         $api->pushApi()->pushToSingleByCid($push);
     }
 
 
     public static function nPush($adminId, $cId, $title, $body)
     {
+        $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);
+
+
         //设置推送参数
         $time = time();
         $rand = rand(1000, 9999);
         $rId = $time . $rand . $adminId;
         $push = new GTPushRequest();
         $push->setRequestId($rId);
+        $push->setSettings($set);
+
         $message = new GTPushMessage();
         $notify = new GTNotification();
         $notify->setTitle($title);
@@ -72,6 +94,72 @@ class pushNotice
         $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("alert title");
+        $alert->setBody("alert 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);
+
+        //安卓
+        $android = new GTAndroid();
+        $ups = new GTUps();
+        //    $ups->setTransmission("ups Transmission");
+        $thirdNotification = new GTThirdNotification();
+        $thirdNotification->setTitle("title".micro_time());
+        $thirdNotification->setBody("body".micro_time());
+        $thirdNotification->setClickType(GTThirdNotification::CLICK_TYPE_URL);
+        $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(456666);
+        $ups->addOption("HW","badgeAddNum",1);
+        $ups->addOption("OP","channel","Default");
+        $ups->addOption("OP","aaa","bbb");
+        $ups->addOption(null,"a","b");
+
+        $ups->setNotification($thirdNotification);
+        $android->setUps($ups);
+        $pushChannel->setAndroid($android);
+        $push->setPushChannel($pushChannel);
+
+
         //创建API,APPID等配置参考 环境要求 进行获取
         $api = new GTClient(self::domainUrl, self::appKey, self::appId, self::masterSecret);
         //处理返回结果