小程序C#后台获取openID错误:40029 真正解决:
//拼接字符串不能再加单引号,否则40029错误2020/03/20
[WebMethod]
public string login(string appId, string secret, string code)
{
string serviceAddress =“https://api.weixin.qq.com/sns/jscode2session?appid=” + appId + “&secret=” + secret + “&js_code=” + js_code + “&grant_type=authorization_code&connect_redirect=1”;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceAddress);
request.Method = “GET”;
request.ContentType = “text/html;charset=UTF-8”;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
return retString;
}
如下接口,直接传递你的参数测试你的程序
https://www.sztaikan.com:83/price/WebServiceHR.asmx/login
参数:
data: {
code: code,
appId: appId,
secret: secret
},
测试结果如下