1
This commit is contained in:
parent
ccf87d323f
commit
f335a773e2
@ -1777,20 +1777,13 @@ class Driver
|
||||
function getAccessToken(int $applet_id = 0, int $type = 1)
|
||||
{
|
||||
$access_token = '';
|
||||
|
||||
if ($applet = Applet::getApplet(['applet_id' => $applet_id, 'status' => 1])) {
|
||||
$access_token = $applet['access_token'];
|
||||
|
||||
if ($type == 1) {
|
||||
$appid = 'wx3668302906e3894f';
|
||||
$app_secret = '3ef948febd085fb89908f22b4a79c52f';
|
||||
} else {
|
||||
$appid = 'wx89c12dd426a55a2e';
|
||||
$app_secret = '33e66bcf944f9810abbb5ddd7825403d';
|
||||
}
|
||||
|
||||
|
||||
if ($applet = Applet::getApplet(['applet_id' => $applet_id, 'status' => 1])) {
|
||||
if (empty($access_token) || time() > $applet['expires_in']) {
|
||||
|
||||
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$app_secret";
|
||||
$result = json_decode(Http::get($url), true);
|
||||
|
||||
@ -1807,6 +1800,34 @@ class Driver
|
||||
return $access_token;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取令牌 - 开放平台
|
||||
* $type 请求类型 1小程序,2公众号
|
||||
*/
|
||||
function getWxAccessToken(int $applet_id = 0, $openid = '')
|
||||
{
|
||||
$appid = 'wx89c12dd426a55a2e';
|
||||
$app_secret = '33e66bcf944f9810abbb5ddd7825403d';
|
||||
$key = 'access_token' . $applet_id . $openid;
|
||||
|
||||
$access_token = Cache::get($key);
|
||||
|
||||
if (empty($access_token)) {
|
||||
|
||||
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$app_secret";
|
||||
$result = json_decode(Http::get($url), true);
|
||||
if (isset($result['access_token'])) {
|
||||
$access_token = $result['access_token'];
|
||||
Cache::set($key, $access_token, 3600);
|
||||
return $access_token;
|
||||
}
|
||||
}
|
||||
return $access_token;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 请求数据验证
|
||||
**/
|
||||
|
||||
@ -72,7 +72,7 @@ class Index
|
||||
//发送公众号消息
|
||||
|
||||
$wx = new Driver;
|
||||
$access_token = $wx->getAccessToken(10001, 2);
|
||||
$access_token = $wx->getWxAccessToken(10001, $openid);
|
||||
$url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $access_token;
|
||||
$queryarr = [
|
||||
'touser' => $openid,
|
||||
|
||||
6
extend/hema/wechat/logs/20231207.log
Normal file
6
extend/hema/wechat/logs/20231207.log
Normal file
@ -0,0 +1,6 @@
|
||||
[2023-12-07 10:51:52]
|
||||
"{\"errcode\":40003,\"errmsg\":\"invalid openid rid: 6571334b-0f222da0-712c3848\"}"
|
||||
|
||||
[2023-12-07 14:25:09]
|
||||
"{\"errcode\":41001,\"errmsg\":\"access_token missing rid: 65716545-36dcfa64-66d8f35c\"}"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user