当前位置:   article > 正文

个推 tp6 --APP消息推送(Cid单推)

个推 tp6 --APP消息推送(Cid单推)

1,安装项目依赖。

        composer require getuilaboratory/getui-pushapi-php-client-v2

2,根据用户Cid单推

  1. public function pushToSingleByCid($system = 'android'){
  2. //创建API,APPID等配置参考 环境要求 进行获取
  3. $api = new \GTClient("https://restapi.getui.com","你的个推appkey", "你的个推appId","你的个推masterSecret");
  4. //设置推送参数
  5. $push = new \GTPushRequest();
  6. $push->setRequestId($this->micro_time());
  7. $message = new \GTPushMessage();
  8. $notify = new \GTNotification();
  9. $settings = new \GTSettings();
  10. $strategy = new \GTStrategy();
  11. $strategy->setDefault(\GTStrategy::STRATEGY_GT_FIRST);
  12. $settings->setStrategy($strategy);
  13. $notify->setTitle("订单提醒");
  14. $notify->setBody("您有新的订单,请及时处理");
  15. //点击通知后续动作,目前支持以下后续动作:
  16. //1、intent:打开应用内特定页面url:打开网页地址。2、payload:自定义消息内容启动应用。3、payload_custom:自定义消息内容不启动应用。4、startapp:打开应用首页。5、none:纯通知,无后续动作
  17. // $notify->setClickType("intent:#Intent;launchFlags=0x04000000;action=android.intent.action.oppopush;component=and.dcloud.Lapp/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title=测试标题;S.content=测试内容;S.payload=test;end");
  18. $notify->setClickType("startapp");
  19. //判断一下操作系统
  20. if$system == "android"){
  21. $message->setNotification($notify); //android
  22. }elseif($system == "ios"){
  23. $message->setTransmission("您有新的订单,请及时处理"); //ios
  24. }
  25. $push->setPushMessage($message);
  26. $push->setSettings($settings);
  27. $pushChannel = new \GTPushChannel();
  28. //ios
  29. $ios = new \GTIos();
  30. $ios->setType("notify");
  31. $ios->setAutoBadge("1");
  32. $ios->setPayload("ios_payload");
  33. $ios->setApnsCollapseId($this->micro_time());
  34. //aps设置
  35. $aps = new \GTAps();
  36. $aps->setContentAvailable(0);
  37. $aps->setSound("music");
  38. $aps->setCategory("category");
  39. $aps->setThreadId("threadId");
  40. $alert = new \GTAlert();
  41. $alert->setTitle("订单提醒");
  42. $alert->setBody("您有新的订单,请及时处理");
  43. $alert->setActionLocKey("ActionLocKey");
  44. $alert->setLocKey("LocKey");
  45. $alert->setLocArgs(array("LocArgs1","LocArgs2"));
  46. $alert->setLaunchImage("LaunchImage");
  47. $alert->setTitleLocKey("TitleLocKey");
  48. $alert->setTitleLocArgs(array("TitleLocArgs1","TitleLocArgs2"));
  49. $alert->setSubtitle("");
  50. $alert->setSubtitleLocKey("");
  51. $alert->setSubtitleLocArgs(array("subtitleLocArgs1","subtitleLocArgs2"));
  52. $aps->setAlert($alert);
  53. $ios->setAps($aps);
  54. $multimedia = new \GTMultimedia();
  55. $multimedia->setUrl("url");
  56. $multimedia->setType(1);
  57. $multimedia->setOnlyWifi(false);
  58. $multimedia2 = new \GTMultimedia();
  59. $multimedia2->setUrl("url2");
  60. $multimedia2->setType(2);
  61. $multimedia2->setOnlyWifi(true);
  62. $ios->setMultimedia(array($multimedia));
  63. $ios->addMultimedia($multimedia2);
  64. $pushChannel->setIos($ios);
  65. //安卓
  66. $android = new \GTAndroid();
  67. $ups = new \GTUps();
  68. // $ups->setTransmission("ups Transmission");
  69. $thirdNotification = new \GTThirdNotification();
  70. $thirdNotification->setTitle("订单提醒");
  71. $thirdNotification->setBody("您有新的订单,请及时处理");
  72. $thirdNotification->setClickType(\GTThirdNotification::CLICK_TYPE_STAERAPP);
  73. $thirdNotification->setIntent("intent:#Intent;component=and.dcloud.Lapp/io.dcloud.PandoraEntry;S.parm1=value1;S.parm2=value2;end");
  74. $thirdNotification->setUrl("https://www.baidu.com");
  75. $thirdNotification->setPayload("payload");
  76. $thirdNotification->setNotifyId(mt_rand(0,2147483647));
  77. $ups->addOption("HW","badgeAddNum",1);
  78. $ups->addOption("OP","channel","Default");
  79. $ups->addOption("OP","aaa","bbb");
  80. $ups->addOption(null,"a","b");
  81. $ups->setNotification($thirdNotification);
  82. $android->setUps($ups);
  83. $pushChannel->setAndroid($android);
  84. $push->setPushChannel($pushChannel);
  85. $push->setCid("用户cid");
  86. $result = $api->pushApi()->pushToSingleByCid($push);
  87. }
  88. public function micro_time()
  89. {
  90. list($usec, $sec) = explode(" ", microtime());
  91. $time = ($sec . substr($usec, 2, 3));
  92. return $time;
  93. }

参考文档:https://docs.getui.com/getui/

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/274567
推荐阅读
相关标签
  

闽ICP备14008679号