songxingwei преди 2 години
родител
ревизия
6f27e7bba8
променени са 2 файла, в които са добавени 46 реда и са изтрити 1 реда
  1. 45 0
      app/common.php
  2. 1 1
      app/data/controller/api/auth/Center.php

+ 45 - 0
app/common.php

@@ -12,6 +12,7 @@ use Darabonba\OpenApi\Models\Config;
 use think\admin\model\SystemConfig;
 use app\common\library\QRcode;
 use PhpOffice\PhpWord\TemplateProcessor;
+use JPush\Client as jpush;
 
 function systemConfig($name,$value=null){
     $nameArr=array_filter(explode('.',$name));
@@ -369,4 +370,48 @@ function num_to_rmb($num){
     }else{
         return $c . "整";
     }
+}
+
+/**
+ * @消息推送(最新版本)
+ */
+function push5($uid,$content,$alias){
+    $app_key = '9dd98f61eb4ad58dca4c8214';
+    $master_secret = 'f7cac744173f8ace703719cf';
+    $client = new JPush($app_key, $master_secret);
+    try {
+        $response = $client->push()
+            ->setPlatform(array('ios', 'android'))
+            ->addAlias($alias)
+            // ->addRegistrationId($registration_id)
+            ->setNotificationAlert($content)
+            ->iosNotification($content,array(
+                    'sound'=>'default',
+                    'badge' => 2,
+                    'content-available' => true,
+                    'category' => 'jiguang',
+                    'extras' => ['user_id'=>$uid,'alias'=>$alias]
+                )
+            )
+            ->androidNotification($content,array(
+                    'title' => $content,
+                    'build_id' => 2,
+                    'extras' => array(
+                        "user_id"=>$uid,"alias"=>$alias),
+                )
+            )
+            ->options([
+                'sendno' => 100,
+                'time_to_live' => 86400,
+                'apns_production' => false,
+                'big_push_duration' => 0
+            ])
+            ->send();
+        return 1;
+    }catch (APIRequestException $e) {
+        return 2;
+    } catch (APIConnectionException $e) {
+        return 3;
+    }
+
 }

+ 1 - 1
app/data/controller/api/auth/Center.php

@@ -1726,7 +1726,7 @@ class Center extends Auth
 
 
     public function send(){
-        $alias = 'user_1';
+        $alias = 'user_70';
         $content = 'ceshi';
         $client = new jpush('9dd98f61eb4ad58dca4c8214','f7cac744173f8ace703719cf');
         $response = $client->push()