wupengfei 2 years ago
parent
commit
9c4825b5a9
3 changed files with 43 additions and 3 deletions
  1. 2 2
      .idea/workspace.xml
  2. 40 0
      application/api/common.php
  3. 1 1
      application/api/controller/Qc.php

+ 2 - 2
.idea/workspace.xml

@@ -3,8 +3,8 @@
   <component name="ChangeListManager">
     <list default="true" id="1a36929e-c054-4875-a943-593a74e55fa4" name="Default Changelist" comment="">
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/application/api/common.php" beforeDir="false" afterPath="$PROJECT_DIR$/application/api/common.php" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/application/api/controller/Qc.php" beforeDir="false" afterPath="$PROJECT_DIR$/application/api/controller/Qc.php" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/application/common/model/UserMessage.php" beforeDir="false" afterPath="$PROJECT_DIR$/application/common/model/UserMessage.php" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -214,7 +214,7 @@
       <workItem from="1663721089544" duration="18248000" />
       <workItem from="1663807609347" duration="18144000" />
       <workItem from="1663893231881" duration="18711000" />
-      <workItem from="1664152288609" duration="21050000" />
+      <workItem from="1664152288609" duration="21131000" />
     </task>
     <servers />
   </component>

+ 40 - 0
application/api/common.php

@@ -1,6 +1,46 @@
 <?php
 // 接口公共方法
 use think\Db;
+use JPush\Client;
+require_once env('root_path').'vendor/jpush/jpush/autoload.php';
+function Jpush($user_id = 0,$alert = ''){
+    if(empty($user_id)) return false;
+    $appKey = '02a7faefd91c8a6a446a6a14';
+    $masterSecret = 'ba2e100db997024d9b6e5d35';
+    $client = new Client($appKey, $masterSecret,null);
+    $push_payload = $client->push()
+        ->setPlatform(array('ios', 'android'))
+        ->addAlias(strval($user_id))
+        ->iosNotification($alert, array(
+            'badge' => '+1',
+            'content-available' => true,
+            'mutable-content' => true,
+            'category' => 'jiguang',
+            'extras' => array(
+                'key' => 'value',
+                'jiguang'
+            ),
+        ))->androidNotification($alert, array(
+            'title' => '消息通知',
+            // 'builder_id' => 2,
+            'extras' => array(
+                'key' => 'value',
+                'jiguang'
+            ),
+        ))->options(array(
+            'apns_production' => True,
+        ));
+    try {
+        $response = $push_payload->send();
+        return $response;
+    } catch  (\JPush\Exceptions\APIConnectionException $e) {
+        return $e;
+    } catch (\JPush\Exceptions\APIRequestException $e) {
+        return $e;
+    }
+}
+
+
 function get_order_sn(){
     $order_id_main = date('YmdHis') . rand(10000000,99999999);
     $order_id_len = strlen($order_id_main);

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

@@ -39,7 +39,7 @@ class Qc extends Base {
 
     public function index()
     {
-        $re = UserMessage::Jpush(22,'fdssdf');
+        $re = Jpush(22,'fdssdf');
         var_dump($re);
         die();
         $user_id = 22 ;