為啥,模板消息執行后,顯示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; } }
2018-10-18
樓上的問題解決了嗎? 求大神解答
2017-04-20