WeChat Webサイトのログイン許可
WeChatの公式開発文書:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842
質問があれば、QQ:631931078または352167311を追加してください.
// : , code
string code = "", state = "";
string userAgent = Request.UserAgent;
if (userAgent.ToLower().Contains("micromessenger"))
{
code = SjuneRequest.GetQueryString("code");
state = SjuneRequest.GetQueryString("state");
if (code == "")
{
Response.Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid= appid&redirect_uri=http://www.cambro.cn/home/index.aspx&response_type=code&scope=snsapi_base&state=STATE&connect_redirect=1#wechat_redirect", false);
}
// : code access_token
else if (code != "")
{
string url = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", " appid", " code", code);
string response = HttpGet(url);
TokenRequest result = JsonConvert.DeserializeObject(response);
// , openid , , , ,
openid , , session, 。 ,
openid session, , openid ,
,
if (result.openid != "" && result.openid != null)
{
if (new BLL.Member_Info().ExistWXOpenid(result.openid))
{
Model.Member_Info model = new BLL.Member_Info().GetModelByOpenId(result.openid);
new BLL.Member_Log().Add(new Model.Member_Log()
{
MemberId = model.Id,
LogVaule = "【 】 ",
AddTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
AddIp = Utils.IP()
});
Session["qt_UserInfo"] = model;
Session.Timeout = 60;
//
}
else
{// id, session,
Session["UserOpenId"] = result.openid;
}
}
}
else
{
esponse.Redirect("https://www.baidu.com");
}
}
質問があれば、QQ:631931078または352167311を追加してください.