在获取code之后请求access_token时总是返回40029错误码,我搜了一下发现是code重复使用的问题,但是我不知道怎么解决,求大神指点。
//获取网页授权(详细信息) function getUserDetail(){ //1.获取code $appid="*******"; $redirect_uri=urlencode("http://*******/imooc.php/Index/getUserInfo"); $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appid."&redirect_uri=".$redirect_uri."&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"; header('location:'.$url); } function getUserInfo(){ //2.获取网页授权的access_token $appid="*******"; $appsecret="*******"; echo $code=$_GET['code']; echo "<br />"; $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$appsecret."&code=".$code."&grant_type=authorization_code"; $res=$this->http_curl($url,'get'); var_dump($res); echo "<br />"; echo $access_token=$res["access_token"]; $openid =$res['openid']; //3.拉去用户的详细信息 $url="https://api.weixin.qq.com/sns/userinfo?access_token=".$access_token."&openid=".$openid."&lang=zh_CN"; $res = $this->http_curl($url,'get'); var_dump($res); }