123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?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;
- use think\Db;
- use think\Queue;
- use think\Request;
- use think\log;
- class Send extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /* public function callbackAp()
- {
- $data =input();
- $event_type = $data['event_type'];
- if(empty($event_type)){
- echo '不处理';
- exit;
- }
- $t =$data['t'];
- $k='longyiWkApp20240315143927';
- $sign = MD5($k.$t);
- if($sign!=$data['sign']){
- echo 'sign error';
- exit;
- }
- $appId ='b3124d44-7bc7-4965-95dc-0ecb502fdaea';
- $appKeyToken='NzRhMTYyODUtYzczYi00Yjg5LWI3NzktODFmMmY0MGUyODIx';
- $userKeyToken='NWU3OGMxNzgtZjEzNS00M2JmLThmNzItZjY5YzIxOWU5YTQ3';
- $config= Configuration::getDefaultConfiguration()
- ->setAppKeyToken($appKeyToken)
- ->setUserKeyToken($userKeyToken);
- $apiInstance = new DefaultApi(
- new GuzzleHttp\Client(),
- $config
- );
- $result =$this->sendTest($apiInstance,$appId);
- $this->success('',$result);
- }*/
- public function callbackWk()
- {
- $data =input();
- $event_type = $data['event_type'];
- if(empty($event_type)){
- echo '不处理';
- exit;
- }
- $t =$data['t'];
- $k='longyiWkApp20240315143927';
- $sign = MD5($k.$t);
- if($sign!=$data['sign']){
- echo 'sign error';
- exit;
- }
- $appId ='6bbd561f-4d8e-4d04-a6c4-dbef1bf99694';
- $appKeyToken='MDMwZThjYWMtOWQ4ZC00YzU3LWIwNjktOGYzNTA2NjA3NTBh';
- $userKeyToken='YTdmZGE5MGEtN2Y3Yi00Mzk0LTgyOGQtMGMzNDkzYTcxYmJh';
- $config= Configuration::getDefaultConfiguration()
- ->setAppKeyToken($appKeyToken)
- ->setUserKeyToken($userKeyToken);
- $apiInstance = new DefaultApi(
- new GuzzleHttp\Client(),
- $config
- );
- $result =$this->sendMessage($apiInstance,$appId);
- $this->success('',$result);
- }
- function createNocation($appId){
- $title='Westkiss live is on air now🔔';
- $template_dsc='What does the Live Stream have? Most popular wigs! Best price! Exclusive events!
- Join the live now!';
- $content = new StringMap();
- $content->setEn($template_dsc);
- $notification = new Notification();
- $notification->setAppId($appId);
- $notification->setContents($content);
- $notification->setIncludedSegments(['All']);
- $notification->setIosBadgeType('Increase');
- $notification->setIosBadgeCount(1);
- $notification->setIsIos(true);
- $notification->setContentAvailable(true);
- $data['push_para']='';
- $data['push_type']=888;
- $data['title']=$title;
- $data['message_id']=66888;
- $notification->setData($data);
- $notification->setMutableContent(true);
- $apns_alert['title']=$title;
- $notification->setApnsAlert($apns_alert);
- return $notification;
- }
- public function sendMessage($apiInstance,$appId){
- $notification = $this->createNocation($appId);
- $re=$apiInstance->createNotification($notification);
- log::write($re,'info');
- /*for($i=0;$i<10;$i++){
- $dt = new DateTime();
- $minute = 1+$i ;
- $dt->modify("+$minute minute");
- $notification->setSendAfter($dt);
- $filters = [ // 可选,基于特定条件过滤用户
- ['field' => 'tag', 'key' => 'SufixUid', 'relation' => '=', 'value' => $i]
- ];
- $notification->setFilters($filters);
- $re[] = $apiInstance->createNotification($notification);
- }*/
- return $re;
- }
- }
|