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

RowlingJoe 2017-07-21 02:15:44
这是通过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
...全文
1538 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ShanShanYouWen 2018-05-25
  • 打赏
  • 举报
回复
url不对 https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=SCOPE&state=STATE#wechat_redirect 你的url是小程序的

3,143

社区成员

发帖
与我相关
我的任务
社区描述
微信开发即微信公众平台开发,将企业信息、服务、活动等内容通过微信网页的方式进行表现,通过二次开发可以将公众账号由一个媒体型营销工具转化成提供服务的产品。
社区管理员
  • 微信开发
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧