lizhen_gitee před 1 rokem
rodič
revize
a56441d8a6

+ 1 - 0
.gitignore

@@ -10,3 +10,4 @@ Homestead.json
 Homestead.yaml
 npm-debug.log
 yarn-error.log
+.idea

+ 73 - 0
app/Common/Library/Easemob.php

@@ -0,0 +1,73 @@
+<?php
+namespace App\Common\Library;
+
+use Easemob\Auth;
+use Easemob\Push;
+
+class Easemob {
+
+    protected $auth;
+
+
+    public function __construct() {
+
+        //环信推送 正式
+        $easemob_config =  [
+            'appkey'        => '1137221110163975#tkenim',
+            'client_id'     => 'YXA6DEehGBpFTb-UOcgmWtveZQ',
+            'client_secret' => 'YXA6KhfJfqyJYBn2I20DdgTEzWpx5Cs',
+        ];
+
+        //初始化配置
+//        $easemob_config               = config('easemob');
+        $appKey                       = $easemob_config['appkey'];
+        $clientIdOrAppID              = $easemob_config['client_id'];
+        $clientSecretOrAppCertificate = $easemob_config['client_secret'];
+
+        $this->auth = new Auth($appKey,$clientIdOrAppID,$clientSecretOrAppCertificate);
+    }
+
+    //////////////////消息推送//////////////////////////
+    public function push_text($uid,$title,$msg){
+        $message = new Push($this->auth);
+
+        $pushMessage =
+        [
+            'title'=> $title,
+//            'subTitle'=> '',
+            'content'=> $msg,
+            /*'ext'=> [],
+            'config'=> [
+                'clickAction'=> [
+                    'url'=>'',
+                    'action'=>'',
+                    'activity'=>'',
+                ],
+                'badge'=> [
+                    'addNum'=> 0,
+                    'setNum'=> 0,
+                ],
+            ],
+
+            'easemob'=>[],
+            'apns'=> [],
+            'fcm'=> [],
+            'fcmV1'=>[],
+            'huawei'=> [],
+            'meizu'=> [],
+            'oppo'=> [],
+            'vivo'=> [],
+            'xiaomi'=> [],
+            'honor'=>[]*/
+        ];
+
+        $rs = $message->push_sync($uid,$pushMessage);
+        //dump($rs);
+    }
+
+
+
+
+
+
+}

+ 7 - 1
app/Http/Controllers/Controller.php

@@ -6,8 +6,14 @@ use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
 use Illuminate\Foundation\Bus\DispatchesJobs;
 use Illuminate\Foundation\Validation\ValidatesRequests;
 use Illuminate\Routing\Controller as BaseController;
-
+use App\Common\Library\Easemob;
 class Controller extends BaseController
 {
     use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
+
+    public function test(){
+        $easemob = new Easemob();
+        $rs = $easemob->push_text(1018,'标题','内容');
+        dd($rs);
+    }
 }

+ 1 - 0
routes/web.php

@@ -16,3 +16,4 @@ use Illuminate\Support\Facades\Route;
 Route::get('/', function () {
     return view('welcome');
 });
+Route::get('/test', [\App\Http\Controllers\Controller::class,'test']);