Wx.php
3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
namespace addons\qingdong\controller;
use addons\qingdong\model\Staff;
use addons\qingdong\model\AdminConfig;
use think\Log;
use WeWork\Crypt\WXBizMsgCrypt;
use addons\qingdong\library\Wechat;
/**
* * 操作文档:https://doc.fastadmin.net/qingdong
* 软件介绍:https://www.fastadmin.net/store/qingdong.html
* 售后微信:qingdong_crm
* 企业微信接口
*/
class Wx extends StaffApi
{
protected $noNeedLogin = ['userid','template','token'];
protected $noNeedRight = [];
public function _initialize()
{
parent::_initialize();
}
//验证
public function token()
{
$wechat = new Wechat('wxOfficialAccount');
$app = $wechat->getApp();
// $current = $app->menu->current();
// halt($current);
// $buttons = [
// [
// "type" => "click",
// "name" => "绑定帐号",
// "key" => "V1001_BIND"
// ]
// ];
// $app->menu->create($buttons);
// return;
$app->server->push(function ($message)use($app) {
// \think\Cache::set('logs',11);
if($message['MsgType']=='event'){
// \think\Cache::set('logs',22);
if($message['Event']=='CLICK' && $message['EventKey']=='V1001_BIND'){
// \think\Cache::set('logs',33);
$user = $app->user->get($message['FromUserName']);
$staff = \think\Db::name('qingdong_staff')->where('unionid',$user['unionid'])->find();
if($staff){
\think\Db::name('qingdong_staff')->where('unionid',$user['unionid'])->update(['wx_openid'=>$user['openid']]);
return "你好{$staff['name']},小程序帐号【{$staff['mobile']}】绑定成功";
}else{
return "未查询到小程序帐号,请重新登陆小程序";
}
}
}
return "您好!欢迎使用 瑄玑云超融合平台";
});
$response = $app->server->serve();
$response->send();
return $response;
halt($app);
return;
$corpId = AdminConfig::getConfigValue('wechat', 'corpid');
$token = 'crm';
$encodingAesKey = '';
Log::write('a---' . json_encode(input()));
//{"signature":"a5e65529fbfb664f861123bf788d3148c2f81410","echostr":"8516206395270299499","timestamp":"1730084704","nonce":"787142174"}
$sVerifyMsgSig = input('signature');
$sVerifyTimeStamp = input('timestamp');
$sVerifyNonce = input('nonce');
$sVerifyEchoStr = input('echostr');
return $sVerifyEchoStr;
if (empty($sVerifyMsgSig) || empty($sVerifyTimeStamp) || empty($sVerifyNonce) || empty($sVerifyEchoStr)) {
$this->error('参数不正确');
}
$sEchoStr = "";
$wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId);
$errCode = $wxcpt->VerifyURL($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $sVerifyEchoStr, $sEchoStr);
// halt($errCode);
if ($errCode == 0) {
return $sEchoStr;
} else {
return false;
}
}
}