Message.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. class Message extends Api
  23. {
  24. protected $noNeedLogin = ['*'];
  25. protected $noNeedRight = ['*'];
  26. public function _initialize()
  27. {
  28. parent::_initialize();
  29. $config= Configuration::getDefaultConfiguration()
  30. ->setAppKeyToken('MDMwZThjYWMtOWQ4ZC00YzU3LWIwNjktOGYzNTA2NjA3NTBh')
  31. ->setUserKeyToken('YTdmZGE5MGEtN2Y3Yi00Mzk0LTgyOGQtMGMzNDkzYTcxYmJh');
  32. $this->apiInstance = new DefaultApi(
  33. new GuzzleHttp\Client(),
  34. $config
  35. );
  36. }
  37. public function getPlayers()
  38. {
  39. $limit = 10;
  40. $getPlayersResult = $this->apiInstance->getPlayers('6bbd561f-4d8e-4d04-a6c4-dbef1bf99694', $limit);
  41. print_r($getPlayersResult->getPlayers());
  42. }
  43. function createNotification($enContent){
  44. $content = new StringMap();
  45. $content->setEn($enContent);
  46. $notification = new Notification();
  47. $notification->setAppId('6bbd561f-4d8e-4d04-a6c4-dbef1bf99694');
  48. $notification->setContents($content);
  49. $notification->setIncludedSegments(['SegmentA']);
  50. return $notification;
  51. }
  52. public function send(){
  53. $notification = $this->createNotification(' wk Test notification');
  54. $result = $this->apiInstance->createNotification($notification);
  55. print_r($result);
  56. }
  57. }