微信小程序access_token自动更新
protected function get_access_token()
{
if(!cache('wx_access_token')){
【微信小程序access_token自动更新】$appid = "wx0fsfgs2664edde";
$appsecret = "7252bd2c6bc4400fgghfhgfh700c";
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$appsecret;
$res = $this->http_request($url);
$result = json_decode($res, true);
$access_token = $result["access_token"];
cache( 'wx_access_token', $access_token, (intval($result["expires_in"])-200) );
}
return cache('wx_access_token');
}
//将access_token存入memcached中
protected function http_request($url, $data = https://www.it610.com/article/null)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data))
{
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
推荐阅读
- 一个小故事,我的思考。
- 家乡的那条小河
- 一个人的碎碎念
- 野营记-第五章|野营记-第五章 讨伐梦魇兽
- 昨夜小楼听风
- 2021-02-17|2021-02-17 小儿按摩膻中穴-舒缓咳嗽
- 基于微信小程序带后端ssm接口小区物业管理平台设计
- 2019.4.18感恩日记
- 那件我们忽略的小事叫感恩
- 你有婚内虐待行为吗()