亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為啥,模板消息執行后,顯示access_token無效?

一直顯示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?end
function?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;
		}
	}


正在回答

2 回答

樓上的問題解決了嗎? 求大神解答

0 回復 有任何疑惑可以回復我~
array(2)?{?["errcode"]=>?int(40001)?["errmsg"]=>?string(81)?"invalid?
credential,?access_token?is?invalid?or?not?latest?hint:?[kHNwQA0894vr43!]"?}


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為啥,模板消息執行后,顯示access_token無效?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號