小程序app.js
wx.login({
success:res=>{
console.log(res.code);
}
})
用以上的res.code通过服务端获取openid报{"errcode":41008,"errmsg":"missing code, hints: [ req_id: rn6PNA0941hc52 ]"}
以下是c#的服务端代码
public string GetOpenIdByCode(string code)
{
string html = string.Empty;
string url = "https://api.weixin.qq.com/sns/jscode2session?appid=XXX&secret=XXX&code=" + code + "&grant_type=authorization_code";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "GET";
request.ContentType = "text/html;charset=UTF-8";
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream ioStream = response.GetResponseStream();
StreamReader sr = new StreamReader(ioStream, Encoding.UTF8);
html = sr.ReadToEnd();
sr.Close();
ioStream.Close();
response.Close();
return html;
}
看报错是说 请求微信接口 传了个空的code 看下后台收到前端传过来的code是个什么情况
前端把code,iv,data给后台,后台解密后返你openid,后台配置文件的appid和秘钥要与前端appid保持一致
有教程吗?
只有前端的,QQ476296134,我们后台是java
类似问题有些用户可以授权,有些不能,总是报{"errcode":41008,"errmsg":"missing code, hints: [ req_id: gJOBKnACe-aYjrVA ]"},请问是什么原因?