前端js:
点击查看代码
var local = encodeURIComponent(window.location.href);
var appid = $("#appId").text();//公众号
var url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + appid + '&redirect_uri=' + local + '&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect';
window.location.href = url;
var appid = $("#appId").text();//公众号
var url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + appid + '&redirect_uri=' + local + '&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect';
window.location.href = url;
后端:
public async Task<ActionResult> PayAsync(string code)
{- - -
string openid = "";
var urls3 = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", appId, appSecret, code);
var httpRequestHelper = new HttpRequestHelper(urls3);
string resultTexts = await httpRequestHelper.HttpGetRequest();
AuthAccessTokenResult result1 = JsonConvert.DeserializeObject<AuthAccessTokenResult>(resultTexts);
if (result1 != null)
{
openid = result1.openid;
}
}
标签:redirect,openid,code,string,c#,微信,appid,var
From: https://www.cnblogs.com/sylAll/p/17465699.html