123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2022/12/3 0003
- * Time: 9:49
- */
- namespace app\api\controller;
- use app\common\controller\Api;
- use DateTime;
- use onesignal\client\api\DefaultApi;
- use onesignal\client\Configuration;
- use onesignal\client\model\GetNotificationRequestBody;
- use onesignal\client\model\Notification;
- use onesignal\client\model\StringMap;
- use onesignal\client\model\Player;
- use onesignal\client\model\UpdatePlayerTagsRequestBody;
- use onesignal\client\model\ExportPlayersRequestBody;
- use onesignal\client\model\Segment;
- use onesignal\client\model\FilterExpressions;
- use GuzzleHttp;
- use app\common\model\User;
- class Message extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- public function _initialize()
- {
- parent::_initialize();
- $config= Configuration::getDefaultConfiguration()
- ->setAppKeyToken('MDMwZThjYWMtOWQ4ZC00YzU3LWIwNjktOGYzNTA2NjA3NTBh')
- ->setUserKeyToken('YTdmZGE5MGEtN2Y3Yi00Mzk0LTgyOGQtMGMzNDkzYTcxYmJh');
- $this->apiInstance = new DefaultApi(
- new GuzzleHttp\Client(),
- $config
- );
- }
- public function getPlayers()
- {
- $limit = 10;
- $getPlayersResult = $this->apiInstance->getPlayers('6bbd561f-4d8e-4d04-a6c4-dbef1bf99694', $limit);
- print_r($getPlayersResult->getPlayers());
- }
- public function addPlayers()
- {
- $data=$this->request->post();
- $user = User::getByUserId($data['user_id']);
- if ($user) {
- $user->group_id = $data['group_id'];
- $user->save();
- }else{
- User::create($data, true);
- }
- $this->success();
- }
- function createNotification($enContent){
- $content = new StringMap();
- $content->setEn($enContent);
- $notification = new Notification();
- $notification->setAppId('6bbd561f-4d8e-4d04-a6c4-dbef1bf99694');
- $notification->setContents($content);
- $notification->setIncludedSegments(['SegmentA']);
- return $notification;
- }
- public function send(){
- $notification = $this->createNotification(' wk Test notification');
- $result = $this->apiInstance->createNotification($notification);
- print_r($result);
- }
- }
|