"errcode":40163
这样获取微信登陆用户的openid市一开始可以 但后面一直报40163 刚接触这个 各位大神帮忙看看
$(document).ready(function () {
debugger
//alert("WID");
var code = Gn.Request.Params("Code") == null ? "" : Gn.Request.Params("Code");
if (code == "") {
var currentUrl = window.location;
var appId = appId ;
window.location = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appId + "&redirect_uri=" + encodeURI(currentUrl) + "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
} else {
Gn.postSync("Wechart/GetOpenId", { code: code }, function (data) {
WID = data.OpenId;
//alert("WID");
});
}
Gn.client.clear();
Gn.Account();
// $(".logo img").attr("src", "App_Themes/Default/image/login logo.jpg");
BinDing.init();
});
public ClientData GetOpenId(string code)
{
var appid = SysConfig.GetSysConfigValue("appID");
var secret = SysConfig.GetSysConfigValue("cropSecret");
var wechart_token_url = SysConfig.GetSysConfigValue("wechart_token_url");
LogInfo log = new LogInfo();
var client = new System.Net.WebClient();
client.Encoding = System.Text.Encoding.UTF8;
var serializer = new JavaScriptSerializer();
//获取openid
var tokenUrl = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code",
appid, secret, code);
var tokenData = client.DownloadString(tokenUrl);
string openid = "";
var openidResult = serializer.Deserialize<Dictionary<string, string>>(tokenData);
log.Write(tokenData);
if (!openidResult.TryGetValue("openid", out openid))
{
return new ClientData() { OpenId = "0" };
}
else
{
return new ClientData() { OpenId = openid };
}
}