A question about URL redirection during WeChat development

Source: Internet
Author: User
First paste the code: {code ...} {code ...} the problem is as follows: you need to open a connection in the menu. the link looks like this: rusice. tunnel. qydev. co... locally, I use ugrok for penetration and win platform. Yes...

Post Code First:

Public function getWxopneURL () {$ code = I ('Get. code ', '', 'trim'); if (empty ($ code) {$ redirect_uri = urlencode (get_url (); $ url = 'https: // open.weixin.qq.com/connect/oauth2/authorize? Appid = '. $ this-> appid. '& redirect_uri = '. $ redirect_uri. '& response_type = code & scope = snsapi_base & state = oauth & connect_redirect = 1 # wechat_redirect'; file_put_contents ('URL. log', $ url); return header ("Location :". $ url);} // get access_token $ access_token = file_get_contents ("https://api.weixin.qq.com/sns/oauth2/access_token? Appid = ". $ this-> appid. "& secret = ". $ this-> key. "& code = ". $ code. "& grant_type = authorization_code"); $ access_token = json_decode ($ access_token, true); return $ access_token ['openid'];}
/*** Get the complete URL of the current page */function get_url ($ val = '', $ valb ='', $ var = array ()) {$ sys_protocal = isset ($ _ SERVER ['server _ port']) & $ _ SERVER ['server _ port'] = '2016 '? 'Https: // ': 'http: //'; if ($ valb = 'IMG ') {if (strstr ($ val, 'http :')) return $ val; return $ sys_protocal. (isset ($ _ SERVER ['http _ host'])? $ _ SERVER ['http _ host']: ''). $ val;} elseif ($ valb = 'URL') {$ var ['token'] = $ GLOBALS ['userinfo'] ['token']; if (strstr ($ val, 'http: ') return $ val; return $ sys_protocal. (isset ($ _ SERVER ['http _ host'])? $ _ SERVER ['http _ host']: ''). U ($ val, $ var);} if ($ GLOBALS ['userinfo']) {$ var = $ _ GET; if (count (explode ('emp _ car ', $ _ SERVER ['request _ URI ']) = 1) {$ var ['token'] = $ GLOBALS ['userinfo'] ['token'];} $ relate_url = U ('', $ var);} else {$ php_self = $ _ SERVER ['php _ SELF ']? $ _ SERVER ['php _ SELF ']: $ _ SERVER ['script _ name']; $ path_info = isset ($ _ SERVER ['path _ info'])? $ _ SERVER ['path _ info']: ''; $ relate_url = isset ($ _ SERVER ['request _ URI '])? $ _ SERVER ['request _ URI ']: $ php_self. (isset ($ _ SERVER ['query _ string'])? '? '. $ _ SERVER ['query _ string']: $ path_info);} return $ sys_protocal. (isset ($ _ SERVER ['http _ host'])? $ _ SERVER ['http _ host']: ''). $ relate_url ;}

==========================================
The problem is as follows:
You need to open a connection in the menu,
The link looks like this:

Http://rusice.tunnel.qydev.co...

Locally, I use ugrok for penetration and win platform. Yes.
But put it on the server today in the linux environment. The problem occurs.

The captured url is as follows:

https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxdd658ea6d4dbc597&redirect_uri=http%3A%2F%2Fwx.mytbu.cn%2Findex.php%3Fg%3DActivity%26m%3DDoVote&response_type=code&scope=snsapi_base&state=oauth&connect_redirect=1#wechat_redirect

Later, I tried it. without parameters, only domain names are possible.
It is also possible to include a parameter, but it will not work if there are two parameters. This problem has been found for a whole day. I hope someone can help me. thank you!

Reply content:

Post Code First:

Public function getWxopneURL () {$ code = I ('Get. code ', '', 'trim'); if (empty ($ code) {$ redirect_uri = urlencode (get_url (); $ url = 'https: // open.weixin.qq.com/connect/oauth2/authorize? Appid = '. $ this-> appid. '& redirect_uri = '. $ redirect_uri. '& response_type = code & scope = snsapi_base & state = oauth & connect_redirect = 1 # wechat_redirect'; file_put_contents ('URL. log', $ url); return header ("Location :". $ url);} // get access_token $ access_token = file_get_contents ("https://api.weixin.qq.com/sns/oauth2/access_token? Appid = ". $ this-> appid. "& secret = ". $ this-> key. "& code = ". $ code. "& grant_type = authorization_code"); $ access_token = json_decode ($ access_token, true); return $ access_token ['openid'];}
/*** Get the complete URL of the current page */function get_url ($ val = '', $ valb ='', $ var = array ()) {$ sys_protocal = isset ($ _ SERVER ['server _ port']) & $ _ SERVER ['server _ port'] = '2016 '? 'Https: // ': 'http: //'; if ($ valb = 'IMG ') {if (strstr ($ val, 'http :')) return $ val; return $ sys_protocal. (isset ($ _ SERVER ['http _ host'])? $ _ SERVER ['http _ host']: ''). $ val;} elseif ($ valb = 'URL') {$ var ['token'] = $ GLOBALS ['userinfo'] ['token']; if (strstr ($ val, 'http: ') return $ val; return $ sys_protocal. (isset ($ _ SERVER ['http _ host'])? $ _ SERVER ['http _ host']: ''). U ($ val, $ var);} if ($ GLOBALS ['userinfo']) {$ var = $ _ GET; if (count (explode ('emp _ car ', $ _ SERVER ['request _ URI ']) = 1) {$ var ['token'] = $ GLOBALS ['userinfo'] ['token'];} $ relate_url = U ('', $ var);} else {$ php_self = $ _ SERVER ['php _ SELF ']? $ _ SERVER ['php _ SELF ']: $ _ SERVER ['script _ name']; $ path_info = isset ($ _ SERVER ['path _ info'])? $ _ SERVER ['path _ info']: ''; $ relate_url = isset ($ _ SERVER ['request _ URI '])? $ _ SERVER ['request _ URI ']: $ php_self. (isset ($ _ SERVER ['query _ string'])? '? '. $ _ SERVER ['query _ string']: $ path_info);} return $ sys_protocal. (isset ($ _ SERVER ['http _ host'])? $ _ SERVER ['http _ host']: ''). $ relate_url ;}

==========================================
The problem is as follows:
You need to open a connection in the menu,
The link looks like this:

Http://rusice.tunnel.qydev.co...

Locally, I use ugrok for penetration and win platform. Yes.
But put it on the server today in the linux environment. The problem occurs.

The captured url is as follows:

https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxdd658ea6d4dbc597&redirect_uri=http%3A%2F%2Fwx.mytbu.cn%2Findex.php%3Fg%3DActivity%26m%3DDoVote&response_type=code&scope=snsapi_base&state=oauth&connect_redirect=1#wechat_redirect

Later, I tried it. without parameters, only domain names are possible.
It is also possible to include a parameter, but it will not work if there are two parameters. This problem has been found for a whole day. I hope someone can help me. thank you!

Is the trusted domain name configured for authorized logon?

This is a url parsing rule problem, because & m = is the interface parameter by default.
redirect_uri=http://wx.mytbu.cn/index.php?g=Activity&m=DoVote ?The following parameter g is considered as the index. php parameter of your page, while&The following m is considered to be the parameter of the previous interface authorize page.

After two days, the problem is finally solved. it turns out that the callback domain name needs to be configured. I found a modification entry below for half a day... Is this a pitfall?

What's worse is the official demo bug.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.