微信公众号开发时出现40029 错误,不合法的oauth_code该怎么解决呢?用的是c#。

RowlingJoe RowlingJoe 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
这是通过code获取openid 的代码

#region 通过code换取openid
/// <summary>
/// 根据code获取用户的openid
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
public static string CodeByOpenid(string code)
{
Log("0");
string OpenID = string.Empty;
string getUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code";
getUrl = string.Format(getUrl, APPID, AppSecret, code);
Uri uri = new Uri(getUrl);
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(uri);
webReq.Method = "POST";
//获取返回信息
Log("1");
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
StreamReader streamReader = new StreamReader(response.GetResponseStream(), Encoding.Default);
string returnJason = streamReader.ReadToEnd();
Log(returnJason);
JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, object> json = (Dictionary<string, object>)serializer.DeserializeObject(returnJason);
object value;
if (json.TryGetValue("openid", out value))
{
OpenID = value.ToString();
}
return OpenID;
}
#endregion
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
RowlingJoe
微信开发 3,161 成员 3,828 内容