叶凌风
叶凌风
  • 发布:2021-03-07 01:25
  • 更新:2021-10-27 18:06
  • 阅读:1032

unipush 服务端PHP不能离线发送

分类:uni-app
function pushToSingleByCid($title,$content,$payload,$cid,$package){  
    //创建API,APPID等配置参考 环境要求 进行获取  
    $api = new \GTClient("https://restapi.getui.com","XXX","XXX","XXX");  
    //设置推送参数  
    $push = new \GTPushRequest();  
    $osn = date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);  
    $push->setRequestId((string)$osn);  

    $message = new \GTPushMessage();  
      $channel = new \GTPushChannel();  
    $notify = new \GTNotification();  
  $thirdnotify = new \GTThirdNotification();  
   $ups = new \GTUps();  
    $gtAndroid = new \GTAndroid();  
    $notify->setTitle($title);  
    $notify->setBody($content);  

    $thirdnotify->setTitle($title);  
    $thirdnotify->setBody($content);  
    if(is_array($payload))  
    $pj =  json_encode($payload);  
    else  
     $pj = $payload;  
    $notify-> setPayload($pj);  
   $thirdnotify-> setPayload($pj);  

       $intent = "intent:#Intent;launchFlags=0x14000000;action=android.intent.action.oppopush;component={$package}/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title={$title};S.content={$content};S.payload={$pj};end";  
         $notify->setClickType("intent");  
   $thirdnotify->setClickType("intent");  
    $notify->setIntent($intent);  
     $thirdnotify->setIntent($intent);  
    echo  $intent;  

    //点击通知后续动作,目前支持以下后续动作:  
    //1、intent:打开应用内特定页面url:打开网页地址。2、payload:自定义消息内容启动应用。3、payload_custom:自定义消息内容不启动应用。4、startapp:打开应用首页。5、none:纯通知,无后续动作  

    // $notify->setIntent($intent);  
     // $notify->setChannelLevel(3);  

 // $touchuan=['title'=>$title,'content'=>$content,'payload'=>$package];  

//$message->setTransmission(json_encode($touchuan));  
//$message->setNotification($notify);  
 $upsback= $ups->setNotification($thirdnotify);  
 // $upsback= $ups->setTransmission('透传');  

$gtAndroid->setUps($ups);  
$channel->setAndroid($gtAndroid);  
 //$push->setPushMessage($message);  

      $push->setPushChannel( $channel);  
    $push->setCid($cid);  
    //处理返回结果  
    $result = $api->pushApi()->pushToSingleByCid($push);  
}

这个能在线推送,但是不能离线推送,dcloud后台推送单推却可以离线成功,但是服务端不能。以上是PHP代码了,V2 版SDK.而且都是参考SDK的demo的第三方厂商家通道发送,都是不能发送的,而且在小米推送后台输入CID弹出输入的regId格式不正确,请确认regid是否不全是数字且长度为44或64或128的错误,是不是CID小米不兼容啊所以发送不了商家通道发送。

2021-03-07 01:25 负责人:无 分享
已邀请:
叶凌风

叶凌风 (作者) - 叶凌风

好像我这个是通知的,不是透传,那透传有DEMO吗V2版本的

DCloud_uniCloud_JSON
  • 叶凌风 (作者)

    有php服务端的吗,我的不是unicloud,就是透传没有demo服务端

    2021-03-08 14:42

  • DCloud_uniCloud_JSON

    回复 叶凌风: 仔细看插件说明,可以直接转url用。就js的语法抄一个也简单。

    2021-03-08 17:34

  • 叶凌风 (作者)

    回复 DCloud_uniCloud_JSON: 我完全按照SDK的例子写了,都是不能发送厂家通道的推送,代码已经上了

    2021-03-09 01:05

  • DCloud_uniCloud_JSON

    回复 叶凌风: 百分之99.999是细节问题。仔细检查一下吧。那么多人实战项目都用了,插件没问题我测试过

    2021-03-09 11:44

  • 叶凌风 (作者)

    回复 叶凌风: 回复 DCloud_UNI_linju_json: 回复 DCloud_UNI_linju_json: 都怪我没有输出 $result = $api->pushApi()->pushToSingleByCid($push); 这个返回值就知道错哪里了。整个过程在线的离线的都完成了,谢谢指导。我把代码改成成功的让大家参考一下,毕竟SDK v2的PHP在线和离线推送的的网上的几乎都没有。成功代码文章地址https://ask.dcloud.net.cn/article/38809

    2021-03-09 14:16

1***@qq.com

1***@qq.com

SDK怎么整合进TP6?分享一下吧

  • DCloud_uniCloud_JSON

    云函数url化,然后这个url你自己拿去在任何语言任何系统中当api调。插件中有详细的说明:https://ext.dcloud.net.cn/plugin?id=1680

    2021-10-08 11:20

m***@163.com

m***@163.com

小米的CID跟unipush的cid是不同的,unipush的CID是多厂商集成的,即是它的CID会对应自动创建的多个厂商的client_id,你只能问个推的工作人员才知道小米真实的cid是什么。

2***@qq.com

2***@qq.com

cid是个推,如果有配厂商,cid会绑定一个devicetoken的,这个才是厂商的推送ID

该问题目前已经被锁定, 无法添加新回复