一,微信获取认证信息分两种类型
微信官方文档 https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842
本文采用第一种.
二 前端代码
首先获取code,然后重定向到当前页.
<script>
if(!GetQueryString("code")){
window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxxxx&redirect_uri=http://xxxxxx/xxxx/xxxx.html&response_type=code&scope=snsapi_base&state=123#wechat_redirect";
}
function GetQueryString(name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);//search,查询?后面的参数,