//声明CODE,获取小程序传过来的CODE $code = $_GET["code"]; //配置appid $appid = "请输入appid"; //配置appscret $secret = "请输入appscret"; //api接口 $api = "https://api.weixin.qq.com/sns/jscode2session?appid={$appid}&secret={$secret}&js_code={$code}&grant_type=authorization_code"; //获取GET请求 function httpGet($url){ $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 500); curl_setopt($curl, CURLOPT_S
半年前开发的公众号突然获取不到access_token,于是查了以下才发现是写法的问题,以前的环境这么写没问题,修改成以下方式即可解决修改前:$code = $res['code']; $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='. $this->appid .'&secret='. $this->secret .'&code='. $code .'&grant_type=authorization_code'; $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch); curl_close($ch); $tokens = js
SK
Devil in My Mind.