一、網頁授權
下載文件放置在項目根目錄。
1、js獲取公衆號中用戶code
//獲取公衆號code
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null){
return unescape(r[2]);
}
return null;
}
2、java後臺獲取用戶code
3、code獲取用戶信息openid
String url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx6ff234c5c2e1d45&secret=d56ab881d00d32423523234326fd6e1ecb&code="+code+"&grant_type=authorization_code";