Page into the page can also get valid code, but share out, get not to code, ask this question how to solve it?
Reply content:
Page into the page can also get valid code, but share out, get not to code, ask this question how to solve it?
Just recently contacted development. Your page URL should be a method of your controller, share the URL should also be the method, in this method, the first thing is to get code, and then the URL to jump to the page you actually need to access. The way to do this is to add different parameters to the URL to differentiate the page from the access.
I used laravel to write the code, delete some of my business logic, you see a general:
AppID. ' &redirect_uri= '. $redirectUrl. ' &response_type=code&scope=snsapi_userinfo&state=state#wechat_redirect ';//authorization URL return redirec T ($url);//Jump to Start method}/** * Gets the user's OpenID and Access_token, and determines the type value of the jump page */Public function start (Request $request) {//Second step: Access to OpenID and Access_token via code (valid for two hours) $code = input::get (' code '); $type = Input::get (' type '); $openid = Input::get (' OpenID '); $REDIRECTURL = ' http://mysite.com ';//Set a default jump link, followed by a method to determine the type value, get a link to jump $result = $this->getaccesstoken ($cod e); if ($result) {///Third step: Get user information $result = $this->getuserinfo ($result [' OpenID '], $result [' Access_toke n ']); Fourth step: Jump to the access page link, the user OpenID written to the URL parameters $redirectUrl = $this->getredirecturl ($type, $openid);//To get the page that needs to jump according to the type value } return redirect ($REDIRECTURL); }/** * Get Access_token * @return Successful return result, failed to return false */PubliC function Getaccesstoken ($code) {$getAccessTokenUrl = ' https://api.weixin.qq.com/sns/oauth2/access_token?appid= ' . $this->appid. ' &secret= '. $this->appsecret. ' &code= '. $code. ' &grant_type=authorization_code '; $httpapi = new Commonhttpapi (); $result = $httpapi->call ($GETACCESSTOKENURL); return $result; /** * Get user information * @param unknown $openid * @param unknown $accessToken */Public function GetUserInfo ($openid, $accessToken) {$getUserInfoUrl = ' https://api.weixin.qq.com/sns/userinfo?access_token= '. $accessToken. ' &openid= '. $openid. ' &LANG=ZH_CN '; $httpapi = new Commonhttpapi (); $result = $httpapi->call ($GETUSERINFOURL); return $result; }}