|
@@ -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)];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|