xiaogang 4 years ago
parent
commit
f70ee3c5fc

+ 18 - 0
app/Admin/Controllers/NoticeController.php

xqd xqd
@@ -5,6 +5,7 @@ namespace App\Admin\Controllers;
 use App\Admin\Actions\Notice\NoticeSend;
 use App\Models\Notice;
 use App\Models\User;
+use App\Services\JPushService;
 use Dcat\Admin\Form;
 use Dcat\Admin\Grid;
 use Dcat\Admin\Show;
@@ -74,6 +75,23 @@ class NoticeController extends AdminController
             $form->radio('users')->options([0=>'全部用户',1=>'男性用户',2=>"女性用户"])->default(0);
             $form->display('created_at');
             $form->display('updated_at');
+            $form->saved(function (){
+               //推送消息
+                JPushService::pushNotify([
+                    //标题
+                    'title' => '测试',
+                    //内容
+                    'content' => '测试',
+                    //设备标识,跟设备相关
+                    'reg_id' => 'xxxxxxxxxxx',
+                    //扩展字段
+                    'extras' => [
+                        'key' => 'value',
+                    ],
+                    //推送类型
+                    'type' => JPushService::PUSH_TYPE_ALL,
+                ]);
+            });
         });
     }
 }

+ 23 - 0
app/Http/Controllers/Api/TestController.php

xqd xqd
@@ -7,6 +7,7 @@ namespace App\Http\Controllers\Api;
 use App\Models\DynamicModel;
 use App\Models\User;
 use App\Models\UserInfoModel;
+use App\Services\JPushService;
 
 class TestController
 {
@@ -83,4 +84,26 @@ class TestController
             DynamicModel::query()->create($ins);
         }
     }
+
+    public function test_push(){
+        try {
+            $res = JPushService::pushNotify([
+                //标题
+                'title' => '测试',
+                //内容
+                'content' => '测试',
+                //设备标识,跟设备相关
+                'reg_id' => 'xxxxxxxxxxx',
+                //扩展字段
+                'extras' => [
+                    'key' => 'value',
+                ],
+                //推送类型
+                'type' => JPushService::PUSH_TYPE_ALL,
+            ]);
+        }catch (\Exception $exception){
+            return response()->json(['msg'=>$exception->getMessage()]);
+        }
+        return response()->json(['data'=>$res]);
+    }
 }

+ 1 - 0
routes/api.php

xqd
@@ -182,6 +182,7 @@ $api->version('v1', [
     $api->any('/ali_notify', 'PayNotifyController@ali_notify')->name('ali_notify');
     $api->any('/creat_user', 'TestController@creat_user')->name('creat_user');
     $api->any('/create_dynamic', 'TestController@create_dynamic')->name('create_dynamic');
+    $api->any('/test_push', 'TestController@test_push')->name('test_push');
 
 
 });