一直显示40001错误,
function sendTemplateMsg()
{
//echo '112';
// 1.获取到access_token
$access_token = $this->getWxAccessToken();
$url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token;
// 2.组装数组
/* {
"touser":"OPENID",
"template_id":"ngqIpbwh8bUfcSsECmogfXcV14J0tQlEpBO27izEYtY",
"url":"http://weixin.qq.com/download",
"miniprogram":{
"appid":"xiaochengxuappid12345",
"pagepath":"index?foo=bar"
},
"data":{
"first": {
"value":"恭喜你购买成功!",
"color":"#173177"
},
}
}*/
$arrayres = array(
'touser'=>'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%',
'template_id'=>'qaTs4ocx9A15_tQLtagY48oP6OW6DpDJh6e5g64_McE',//模板ID(用于接口调用)
'url'=>'http://www.baidu.cn/',
'miniprogram'=>array(
'name'=>array('value'=>'hello zsong','color'=>"#173177"),
'money'=>array('value'=>120,'color'=>"#173177"),
'date'=>array('value'=>date('Y-m-d H:i:s'),'color'=>"#173177"),
),//miniprogram array
);
// 3.将数组转化成json
$postJson = json_encode($arrayres);
// 4.调用curl函数
$res = $this->http_curl($url,'post','json',$postJson);
var_dump($res);
}//sendTemplateMsg endfunction getWxAccessToken()
{
// 由于access_token有过期时间,所以将access_token存放到session/cookie中。
if ($_SESSION['access_token'] && $_SESSION['expire_time']>time()) {
//如果access_token没有过期
return $_SESSION['access_token'];
} else {
//如果access_token已经过期,需要重新获取access_token
$appid = '%%%%%%%%%%%%%%%%%%%%%%%';//测试账号的Id和secret:wx5104563ab1ceb261
$appsecret = '%%%%%%%%%%%%%%%%%%%%%%%%%%%';
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$appsecret;
$res = $this->http_curl($url,'get','json');
$access_token = $res['access_token'];
// 将获取之后的access_token存放到session
$_SESSION['access_token'] = $access_token;
$_SESSION['expire_time'] = time()+7000;
return $access_token;
}
}楼上的问题解决了吗 求大神解答
array(2) { ["errcode"]=> int(40001) ["errmsg"]=> string(81) "invalid
credential, access_token is invalid or not latest hint: [kHNwQA0894vr43!]" }