|
@@ -0,0 +1,99 @@
|
|
|
|
+<?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;
|
|
|
|
+class Test extends Api
|
|
|
|
+{
|
|
|
|
+ protected $noNeedLogin = ['*'];
|
|
|
|
+ protected $noNeedRight = ['*'];
|
|
|
|
+
|
|
|
|
+ public function _initialize()
|
|
|
|
+ {
|
|
|
|
+ parent::_initialize();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ public function test()
|
|
|
|
+ {
|
|
|
|
+ $data =input();
|
|
|
|
+ $id=$data['ids'];
|
|
|
|
+ $wheres['id']=$id;
|
|
|
|
+ $one_push = Db::name('message')->where($wheres)->find();
|
|
|
|
+ if (empty($one_push)) {
|
|
|
|
+ echo '没有查到推送队列';
|
|
|
|
+ exit;
|
|
|
|
+ }
|
|
|
|
+ $result =$this->sendTest($one_push);
|
|
|
|
+ $this->success('',$result);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function createNotification($one_push){
|
|
|
|
+ $template_dsc =$one_push['template_dsc'];
|
|
|
|
+ $title =$one_push['template_name'];
|
|
|
|
+ $type =$one_push['type'];
|
|
|
|
+ $url =$one_push['para'];
|
|
|
|
+ $content = new StringMap();
|
|
|
|
+ $content->setEn($template_dsc);
|
|
|
|
+ $notification = new Notification();
|
|
|
|
+ $notification->setContents($content);
|
|
|
|
+ $notification->setIosBadgeType('Increase');
|
|
|
|
+ $notification->setIosBadgeCount(1);
|
|
|
|
+ $notification->setIsIos(true);
|
|
|
|
+ $notification->setContentAvailable(true);
|
|
|
|
+ $data['push_para']=$url;
|
|
|
|
+ $data['push_type']=$type;
|
|
|
|
+ $data['title']=$title;
|
|
|
|
+ $data['message_id']=$one_push['id'];
|
|
|
|
+ $notification->setData($data);
|
|
|
|
+ $notification->setMutableContent(true);
|
|
|
|
+ $apns_alert['title']=$title;
|
|
|
|
+ $notification->setApnsAlert($apns_alert);
|
|
|
|
+ if($one_push['template_image']){
|
|
|
|
+ $request = Request::instance();
|
|
|
|
+ $domain=$request->domain();
|
|
|
|
+ $images['id'] = $domain.$one_push['template_image'];
|
|
|
|
+ $notification->setIosAttachments($images);
|
|
|
|
+ }
|
|
|
|
+ return $notification;
|
|
|
|
+ }
|
|
|
|
+ public function sendTest($one_push){
|
|
|
|
+ $appId =$this->getAppId();
|
|
|
|
+ $notification = $this->createNotification($one_push);
|
|
|
|
+ $notification->setAppId($appId);
|
|
|
|
+ $notification->setIncludedSegments(['TestUsers']);
|
|
|
|
+ $dt = new DateTime();
|
|
|
|
+ $dt->modify('+1 hour');
|
|
|
|
+ $notification->setSendAfter($dt);
|
|
|
|
+ return $this->apiInstance->createNotification($notification);
|
|
|
|
+ }
|
|
|
|
+ public function getAppId(){
|
|
|
|
+ $url = $_SERVER['HTTP_HOST'];
|
|
|
|
+ if (strpos($url, 'westkiss') !== false) {
|
|
|
|
+ $appId ='6bbd561f-4d8e-4d04-a6c4-dbef1bf99694';
|
|
|
|
+ }else{
|
|
|
|
+ $appId ='b3124d44-7bc7-4965-95dc-0ecb502fdaea';
|
|
|
|
+ }
|
|
|
|
+ return $appId;
|
|
|
|
+ }
|
|
|
|
+}
|