Send.php 4.3 KB

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