gogs 1 年之前
父节点
当前提交
521c2158da
共有 5 个文件被更改,包括 140 次插入5 次删除
  1. 10 2
      app/Http/Controllers/Api/WxController.php
  2. 81 2
      app/Service/Wx/WxService.php
  3. 7 1
      composer.json
  4. 41 0
      config/wx/msg.php
  5. 1 0
      public/MP_verify_YoqFDm4m0ulELrlC.txt

+ 10 - 2
app/Http/Controllers/Api/WxController.php

@@ -6,6 +6,7 @@ use App\Service\PurchaseOrderService;
 use App\Service\SalesOrderService;
 use App\Service\Weixin\WeixinService;
 use App\Service\Wx\WxEmployeeService;
+use App\Service\Wx\WxService;
 use Illuminate\Http\Request;
 
 class WxController extends BaseController
@@ -93,8 +94,15 @@ class WxController extends BaseController
     }
 
     public function ttt(){
-        $a = new WeixinService();
-        $a = $a->sendTmpMsg([]);
+        $a = new WxService();
+        $order_data = [
+            '下单人',
+            '经办人',
+            date('Y-m-d H:i:s'),
+            'so1233123',
+            '客户名称',
+        ];
+        $a = $a->wx_sendMsg('180','1','0','37',$order_data);
 
         return $a;
     }

+ 81 - 2
app/Service/Wx/WxService.php

@@ -2,6 +2,7 @@
 
 namespace App\Service\Wx;
 
+use App\Model\WxEmployeeOfficial;
 use Illuminate\Support\Facades\Redis;
 
 class WxService extends Service
@@ -9,8 +10,8 @@ class WxService extends Service
 //    public $appid = 'wx4e1324c600df37a6';
 //    public $secret = '72f8c912d462b0f4ff46cbedac0c80bf';
 
-    public $appid = 'wx4e1324c600df37a6';
-    public $secret = 'cec65770bf168a57dc8e5a012d4c9537';
+    public $appid = 'wxe048bcdcc21aae6e';
+    public $secret = '191789c5b4ef2b3d5b9e79bb62428092';
 
     public function getOpenid($code){
 
@@ -69,4 +70,82 @@ class WxService extends Service
 
         return [true,$res];
     }
+
+    //写一个单独的微信推送
+
+    /**
+     * @param $user_id
+     * @param $type 1审核申请 2抄送 3 审核结果
+     * @param $state 0申请审核1审核通过2审核拒绝
+     * @param $menu_id
+     * @param $order_data
+     * @return array
+     */
+    public function wx_sendMsg($user_id,$type,$state,$menu_id,$order_data){
+        $openid = WxEmployeeOfficial::where('employee_id',$user_id)->value('openid');
+        if(empty($openid)) return [false,'not invaild openid'];
+        $config = config('wx.msg');
+        switch ($type){
+            case '1':
+            case '2':
+                $menu_type = $menu_id.'_'.$type;
+                break;
+            case '3':
+                $menu_type = $menu_id.'_'.$type.'_'.$state;
+                break;
+            default :
+                $menu_type = '';
+        }
+        if(!isset($config['wx_menu'][$menu_type])) return [false,'not invaild menu_type'];
+        $tmp_data = $config['wx_tmp_id'][$config['wx_menu'][$menu_type]];
+        $detail = $tmp_data['param'];
+        $tmp_id = $tmp_data['tmp_id'];
+        $data = [];
+        foreach ($detail as $k=>$v){
+            $data[$v] = $order_data[$k];
+        }
+        $this->sendTmpMsg($openid,$tmp_id,['detail'=>$data]);
+
+        return [true,''];
+    }
+
+
+    public function sendTmpMsg($openid,$tempid,$data){
+        $reload_url = $data['reload_url']??'';
+        list($status,$token) = $this->getToken();
+        if(!$status) return [false,$token];
+        $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$token;
+        $post = '{
+           "touser":"'.$openid.'",
+           "template_id":"'.$tempid.'",
+           "url":"'.$reload_url.'",
+           "data":{
+                   "first": {
+                       "value":"1",
+                       "color":"#173177"
+                   },
+                   %s
+                   "remark":{
+                       "value":"1",
+                       "color":"#173177"
+                   }
+           }
+       }';
+        $content = "";
+        foreach ($data['detail'] as $k=>$v){
+
+            $content .= '"'.$k.'": {
+                       "value":"'.$v.'",
+                       "color":"#173177"
+                   },';
+        }
+        $post = sprintf($post,$content);
+        $res = $this->curlOpen($url,['post'=>$post]);
+        $res = json_decode($res,true);
+        if(isset($res['errcode'])&&$res['errcode'] != 0) return [false,$res['errmsg']];
+        if(isset($res['errcode'])&&$res['errcode'] === 0) return [true,''];
+        return [false,json_encode($res)];
+
+    }
+
 }

+ 7 - 1
composer.json

@@ -64,5 +64,11 @@
         "post-create-project-cmd": [
             "@php artisan key:generate --ansi"
         ]
-    }
+    },
+    "repositories": [
+        {
+            "type": "composer",
+            "url": "https://mirrors.aliyun.com/composer/"
+        }
+    ]
 }

+ 41 - 0
config/wx/msg.php

@@ -0,0 +1,41 @@
+<?php
+return [
+    //前面为菜单id,后面为类型
+    'wx_menu' => [
+        '37_1' => 1,
+        '37_2' => 2,
+        '37_3_2' => 3,
+    ],
+
+    'wx_tmp_id' => [
+        1=>[
+            'tmp_id'=>'5azHlaoAu6MgRzkxn_HL6ygFt_wIkXEz9CklPWEdP70',
+            'param' => [
+                'thing2',
+                'thing6',
+                'time4',
+                'character_string3',
+                'thing1',
+            ]
+        ],
+        2=>[
+            'tmp_id'=>'xuddRh6WEE6lDI4ujc3G24W9VLHQu9oYPMVS80rlMHY',
+            'param' => [
+                'character_string8',
+                'const10',
+                'const11',
+                'time2',
+                'thing17',
+            ]
+        ],
+        3=>[
+            'tmp_id'=>'fp56KqG8iR3QrAaDe-FRh_WWcrWJB58THaXm_cpwndA',
+            'param' => [
+                'character_string2',
+                'phrase3',
+                'time5',
+                'thing4'
+            ]
+        ]
+    ]
+];

+ 1 - 0
public/MP_verify_YoqFDm4m0ulELrlC.txt

@@ -0,0 +1 @@
+YoqFDm4m0ulELrlC