Send.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2022/12/3 0003
  6. * Time: 9:49
  7. */
  8. namespace app\api\controller;
  9. use app\common\controller\Api;
  10. use DateTime;
  11. use onesignal\client\api\DefaultApi;
  12. use onesignal\client\Configuration;
  13. use onesignal\client\model\GetNotificationRequestBody;
  14. use onesignal\client\model\Notification;
  15. use onesignal\client\model\StringMap;
  16. use onesignal\client\model\Player;
  17. use onesignal\client\model\UpdatePlayerTagsRequestBody;
  18. use onesignal\client\model\ExportPlayersRequestBody;
  19. use onesignal\client\model\Segment;
  20. use onesignal\client\model\FilterExpressions;
  21. use GuzzleHttp;
  22. use app\common\model\User;
  23. use think\Db;
  24. use think\Queue;
  25. use think\Request;
  26. class Send extends Api
  27. {
  28. protected $noNeedLogin = ['*'];
  29. protected $noNeedRight = ['*'];
  30. /* public function callbackAp()
  31. {
  32. $data =input();
  33. $event_type = $data['event_type'];
  34. if(empty($event_type)){
  35. echo '不处理';
  36. exit;
  37. }
  38. $t =$data['t'];
  39. $k='longyiWkApp20240315143927';
  40. $sign = MD5($k.$t);
  41. if($sign!=$data['sign']){
  42. echo 'sign error';
  43. exit;
  44. }
  45. $appId ='b3124d44-7bc7-4965-95dc-0ecb502fdaea';
  46. $appKeyToken='NzRhMTYyODUtYzczYi00Yjg5LWI3NzktODFmMmY0MGUyODIx';
  47. $userKeyToken='NWU3OGMxNzgtZjEzNS00M2JmLThmNzItZjY5YzIxOWU5YTQ3';
  48. $config= Configuration::getDefaultConfiguration()
  49. ->setAppKeyToken($appKeyToken)
  50. ->setUserKeyToken($userKeyToken);
  51. $apiInstance = new DefaultApi(
  52. new GuzzleHttp\Client(),
  53. $config
  54. );
  55. $result =$this->sendTest($apiInstance,$appId);
  56. $this->success('',$result);
  57. }*/
  58. public function callbackWk()
  59. {
  60. $data =input();
  61. $event_type = $data['event_type'];
  62. if(empty($event_type)){
  63. echo '不处理';
  64. exit;
  65. }
  66. $t =$data['t'];
  67. $k='longyiWkApp20240315143927';
  68. $sign = MD5($k.$t);
  69. if($sign!=$data['sign']){
  70. echo 'sign error';
  71. exit;
  72. }
  73. $appId ='6bbd561f-4d8e-4d04-a6c4-dbef1bf99694';
  74. $appKeyToken='MDMwZThjYWMtOWQ4ZC00YzU3LWIwNjktOGYzNTA2NjA3NTBh';
  75. $userKeyToken='YTdmZGE5MGEtN2Y3Yi00Mzk0LTgyOGQtMGMzNDkzYTcxYmJh';
  76. $config= Configuration::getDefaultConfiguration()
  77. ->setAppKeyToken($appKeyToken)
  78. ->setUserKeyToken($userKeyToken);
  79. $apiInstance = new DefaultApi(
  80. new GuzzleHttp\Client(),
  81. $config
  82. );
  83. $result =$this->sendMessage($apiInstance,$appId);
  84. $this->success('',$result);
  85. }
  86. function createNotification($appId){
  87. $title='Westkiss live is on air now🔔';
  88. $template_dsc='What does the Live Stream have? Most popular wigs! Best price! Exclusive events!
  89. Join the live now!';
  90. $content = new StringMap();
  91. $content->setEn($template_dsc);
  92. $notification = new Notification();
  93. $notification->setAppId($appId);
  94. $notification->setContents($content);
  95. $notification->setIosBadgeType('Increase');
  96. $notification->setIosBadgeCount(1);
  97. $notification->setIsIos(true);
  98. $notification->setContentAvailable(true);
  99. $data['push_para']='';
  100. $data['push_type']=888;
  101. $data['title']=$title;
  102. $data['message_id']=66888;
  103. $notification->setData($data);
  104. $notification->setMutableContent(true);
  105. $apns_alert['title']=$title;
  106. $notification->setApnsAlert($apns_alert);
  107. return $notification;
  108. }
  109. public function sendMessage($apiInstance,$appId){
  110. $notification = $this->createNocation($appId);
  111. $re=array();
  112. for($i=0;$i<10;$i++){
  113. $dt = new DateTime();
  114. $minute = 1+$i ;
  115. $dt->modify("+$minute minute");
  116. $notification->setSendAfter($dt);
  117. $filters = [ // 可选,基于特定条件过滤用户
  118. ['field' => 'tag', 'key' => 'SufixUid', 'relation' => '=', 'value' => $i]
  119. ];
  120. $notification->setFilters($filters);
  121. $re[] = $apiInstance->createNotification($notification);
  122. }
  123. return $re;
  124. }
  125. }