bianjunhui hace 1 año
padre
commit
d9666fb9a7

+ 1 - 1
application/api/controller/Apmessage.php

@@ -164,7 +164,7 @@ class Apmessage extends Api
             $wheres['user_id']=$post['user_id'];
             $lists = Db::name('message_read')->where($wheres)->find();
             if($lists){
-                $this->success();
+                $this->error();
             }else{
                 $isPushedres=true;
                 if($list['coupon']){

+ 1 - 1
application/api/controller/Message.php

@@ -164,7 +164,7 @@ class Message extends Api
             $wheres['user_id']=$post['user_id'];
             $lists = Db::name('message_read')->where($wheres)->find();
             if($lists){
-                $this->success();
+                $this->error();
             }else{
                 $isPushedres=true;
                 if($list['coupon']){

+ 102 - 78
application/api/controller/Send.php

@@ -1,108 +1,132 @@
 <?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2022/12/3 0003
+ * Time: 9:49
+ */
 namespace app\api\controller;
+
 use app\common\controller\Api;
-use think\Db;
 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 Send extends Api
 {
-
     protected $noNeedLogin = ['*'];
     protected $noNeedRight = ['*'];
 
-    public function _initialize()
+
+   /* public function callbackAp()
     {
-        parent::_initialize();
-        $url = $_SERVER['HTTP_HOST'];
-        if (strpos($url, 'westkiss') !== false) {
-            $this->oneSignalAppId='6bbd561f-4d8e-4d04-a6c4-dbef1bf99694';
-            $this->oneSignalRestApiKey='MDMwZThjYWMtOWQ4ZC00YzU3LWIwNjktOGYzNTA2NjA3NTBh';
-        }else{
-            $this->oneSignalAppId='b3124d44-7bc7-4965-95dc-0ecb502fdaea';
-            $this->oneSignalRestApiKey='NzRhMTYyODUtYzczYi00Yjg5LWI3NzktODFmMmY0MGUyODIx';
+        $data =input();
+        $event_type  = $data['event_type'];
+        if(empty($event_type)){
+            echo '不处理';
+            exit;
         }
-    }
-    public function test()
+        $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();
-        $id=$data['ids'];
-        $wheres['id']=$id;
-        $one_push = Db::name('message')->where($wheres)->find();
-        if (empty($one_push)) {
-            echo '没有查到推送队列';
+        $event_type  = $data['event_type'];
+        if(empty($event_type)){
+            echo '不处理';
             exit;
         }
-        $result =$this->sendTest($one_push);
+        $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);
     }
-    public function sendTest($one_push){
-        $template_dsc =$one_push['template_dsc'];
-        $title =$one_push['template_name'];
-        $type =$one_push['type'];
-        $url =$one_push['para'];
-        $data['push_para']=$url;
-        $data['push_type']=$type;
+
+    function createNotification($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->setIosBadgeType('Increase');
+        $notification->setIosBadgeCount(1);
+        $notification->setIsIos(true);
+        $notification->setContentAvailable(true);
+        $data['push_para']='';
+        $data['push_type']=888;
         $data['title']=$title;
-        $data['message_id']=$one_push['id'];
+        $data['message_id']=66888;
+        $notification->setData($data);
+        $notification->setMutableContent(true);
         $apns_alert['title']=$title;
-        $images['id'] = 'https://message.romandhair.com/uploads/20240307/9d98d28158a102ec6d5ba9caaab05f5b.jpg';
+        $notification->setApnsAlert($apns_alert);
+        return $notification;
+    }
+    public function sendMessage($apiInstance,$appId){
+        $notification = $this->createNocation($appId);
         $re=array();
         for($i=0;$i<10;$i++){
             $dt = new DateTime();
-            $minute =10*($i+1);
+            $minute = 1+$i ;
             $dt->modify("+$minute minute");
-            $fields = [
-                'app_id' =>  $this->oneSignalAppId,
-                //'included_segments' => ['All'], // 使用 'included_segments' 或 'include_player_ids'
-                //'include_player_ids' => ['player_id1', 'player_id2'], // 如果你要推送给指定的用户
-                'filters' => [ // 可选,基于特定条件过滤用户
-                    ['field' => 'tag', 'key' => 'SufixUid', 'relation' => '=', 'value' => $i]
-                ],
-                'contents' => ['en' => $template_dsc], // 消息内容
-                'data' =>$data, // 可选,额外的自定义数据字段
-                'content_available'=>true,
-                'is_ios'=>true,
-                'ios_badge_type'=>'Increase',
-                'apns_alert'=>$apns_alert,
-                'ios_attachments'=> $images,
-                'send_after'=>$dt,
+            $notification->setSendAfter($dt);
+            $filters = [ // 可选,基于特定条件过滤用户
+                ['field' => 'tag', 'key' => 'SufixUid', 'relation' => '=', 'value' => $i]
             ];
-            if($one_push['template_image']){
-                $request = Request::instance();
-                $domain=$request->domain();
-                $images['id'] = $domain.$one_push['template_image'];
-                //$images['id'] = 'https://message.romandhair.com/uploads/20240307/9d98d28158a102ec6d5ba9caaab05f5b.jpg';
-                $fields['ios_attachments']=$images;
-            }
-            $re[] = $this ->sendMessage($fields);
+            $notification->setFilters($filters);
+            $re[] = $apiInstance->createNotification($notification);
         }
         return $re;
     }
 
-    public function sendMessage($fields){
-        $headers = [
-            'Content-Type: application/json; charset=utf-8',
-            'Authorization: Basic ' . $this->oneSignalRestApiKey
-        ];
-        $ch = curl_init();
-        curl_setopt($ch, CURLOPT_URL, 'https://onesignal.com/api/v1/notifications');
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
-        curl_setopt($ch, CURLOPT_HEADER, FALSE);
-        curl_setopt($ch, CURLOPT_POST, TRUE);
-        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
-        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
-        
-        $response = curl_exec($ch);
-        if ($response === FALSE) {
-            die('Curl failed: ' . curl_error($ch));
-        }
-        curl_close($ch);
-        $responseData = json_decode($response, TRUE);
-        print_r($responseData);
-        return $responseData;
-    }
-
-
 
 }