风腾网络
风腾网络
  • 发布:2021-04-02 12:02
  • 更新:2021-09-05 01:08
  • 阅读:2820

关于个推getui,服务端发送推送,在线可以收到,离线永远收不到的问题解决。

分类:uni-app

1.检查参数是否正确。

  1. 可以先不要使用透传方式。
  2. 是否设置了厂商通道消息内容
  3. 设置为打开应用内特定页面就是intent参数。
  4. intent参数是否正确 intent:#Intent;component=包名/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title=".urlencode(标题).";S.content=".urlencode($内容).";S.payload=".json_encode(你的自定义参数).";end

6.PHP端参考代码。

 $api = new \GTClient("https://restapi.getui.com/","", "","");  
        $stt = ['default'=>1];  
        //设置推送参数  
        $push = new \GTPushRequest();  
        $push->setRequestId(time());  
        $message = new \GTPushMessage();  
        $notify = new \GTNotification();  
        $channel = new \GTPushChannel();  

        //配置推送条件  
        $str = new \GTStrategy();  
        $str->setDefault(1);  
        $str->setHw(1);  
        $setting = new \GTSettings();  //定时推送暂无  
        $setting->setStrategy($str);  
        $push->setSettings($setting);  
        $setting->setTtl(3600000); ////消息有效期,走厂商消息需要设置该值  

       //推送苹果离线通知标题内容  
        $alert = new \GTAlert();  
         $alert->setTitle($title);  
       $alert->setBody($content);  
        $aps = new \GTAps();  
        //1表示静默推送(无通知栏消息),静默推送时不需要填写其他参数。  
        //苹果建议1小时最多推送3条静默消息  
        $aps->setContentAvailable(0);  
       $aps->setSound("default");  
       $aps->setAlert($alert);  
       $iosDto = new \GTIos();  
       $iosDto->setAps($aps);  
        $iosDto->setType("notify");  
        $pushChannel = new \GTPushChannel();  
        $pushChannel->setIos($iosDto);  

        //安卓离线厂商通道推送消息体  
        $pushChannel = new \GTPushChannel();  
        $androidDTO = new \GTAndroid();  
        $ups = new \GTUps();  
        $notification1 = new \GTThirdNotification();;  
        $notification1->setTitle($title);  
        $notification1->setBody($content);  
        $ups->setNotification($notification1);  
        if($clickType == 'none')  //设置推送类型  
        {  
            $notification1->setClickType($clickType);  
        }else if($clickType == 'payload' || $clickType == 'payload_custom'){ //自定义消息 打开APP和不打开APP  
            $notification1->setClickType($clickType);  
            $notification1->setPayload(json_encode($data));  
        }else if($clickType == 'url'){  //打开URL  
            $notification1->setClickType($clickType);  
            $notification1->setUrl($url);  
        }else if($clickType == 'intent'){  //打开特定页面  
            $notification1->setClickType($clickType);  
            $notification1->setIntent("intent:#Intent;component=com.hqtwtq.y8/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title=".urlencode($title).";S.content=".urlencode($content).";S.payload=".json_encode($data).";end");  
        }else{  
            $notification1->setClickType($clickType);  
        }  
            //各厂商自有功能单项设置  
        if($time){  
            $message->setDuration($time);  //设置推送时间  
            $data = json_encode(array('title'=>$title,'content'=>$content,'duration'=>$time,'importance'=>'HIGH','payload'=>json_encode($data)));  
        }else{  
            $data = json_encode(array('title'=>$title,'content'=>$content,'payload'=>json_encode($data)));  
        }  
        //$ups->setTransmission($data);  
        $androidDTO->setUps($ups);  
        $pushChannel->setAndroid($androidDTO);  
        $push->setPushChannel($pushChannel);  

        //个推在线通道  
        $notify->setTitle($title);  
        $notify->setBody($content);  
        if($img) $notify->setBigImage($img); //推送图片  
        //1、intent:打开应用内特定页面 2、url:打开网页地址。3、payload:自定义消息内容启动应用。4、payload_custom:自定义消息内容不启动应用。5、startapp:打开应用首页。6、none:纯通知,无后续动作  
        if($clickType == 'none')  //设置推送类型  
        {  
            $notify->setClickType($clickType);  
        }else if($clickType == 'payload' || $clickType == 'payload_custom'){ //自定义消息 打开APP和不打开APP  
            $notify->setClickType($clickType);  
            $notify->setPayload(json_encode($data));  
        }else if($clickType == 'url'){  //打开URL  
            $notify->setClickType($clickType);  
            $notify->setUrl($url);  
        }else if($clickType == 'intent'){  //打开特定页面  
            $notify->setClickType($clickType);  
            $notify->setIntent("intent:#Intent;component=com.hqtwtq.y8/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title=".urlencode($title).";S.content=".urlencode($content).";S.payload=".json_encode($data).";end");  
        }else{  
            $notify->setClickType($clickType);  
        }  
        $message->setNotification($notify);  
        $push->setPushMessage($message);  
      /*  if($time){  
            $message->setDuration($time);  //设置推送时间  
            $data = json_encode(array('title'=>$title,'body'=>$content,'duration'=>$time,'importance'=>'HIGH','payload'=>json_encode($data)));  
        }else{  
            $data = json_encode(array('title'=>$title,'body'=>$content,'payload'=>json_encode($data)));  
        }  
        $ups->setTransmission($data);  //  
        $android->setUps($ups);  
        $channel->setAndroid($android);  
        $push->setPushChannel($channel);  
        $push->setPushMessage($message);*/  
        if($cid)  //推送给某个用户  
        {  
            $push->setCid($cid);  
            //处理返回结果  
            $result = $api->pushApi()->pushToSingleByCid($push);  
        }else{  
            $result = $api->pushApi()->pushAll($push);  
        }  
        Log::info('推送数据:【推送】'.json_encode($result)); //写入日志  
        return $result;
0 关注 分享

要回复文章请先登录注册

初学者123

初学者123

参照这个方法写了,但是报500错误。在 PHP 中,引入时需要注意什么呢?
2021-09-05 01:08