小程序
小游戏
企业微信
微信支付
扫描小程序码分享
小程序调用wx.login获取了code参数,此参数能否直接传给 服务器用来查询用户信息,如果能,需要注意哪些事项。
现在我们拿此code后台查询不到信息,报40029
1 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
//小程序调用wx.login获取的code
string code = "xxxxx";
//小程序唯一标识(开发者持有的appid)
string appid = "xxxxxxx";
//小程序的 app secret(开发者持有的app secret)
string secret = "xxxxxxxxxxxxxxx";
//发送Http Get请求
string url = string.Format("https://api.weixin.qq.com/sns/jscode2session?appid={0}&secret={1}&js_code={2}&grant_type=authorization_code", appid, secret, code);
==========================发送请求代码。略。=====================================
/// <summary>
/// 返回结果实体:微信Api返回参数
/// </summary>
public class WxApiResult
{
/// 用户唯一标识
public string openid { get; set; }
/// 会话密钥
public string session_key { get; set; }
/// 用户在开放平台的唯一标识符
public string unionid { get; set; }
/// 错误状态码
public string errcode { get; set; }
/// 错误信息
public string errmsg { get; set; }
}
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
//小程序调用wx.login获取的code
string code = "xxxxx";
//小程序唯一标识(开发者持有的appid)
string appid = "xxxxxxx";
//小程序的 app secret(开发者持有的app secret)
string secret = "xxxxxxxxxxxxxxx";
//发送Http Get请求
string url = string.Format("https://api.weixin.qq.com/sns/jscode2session?appid={0}&secret={1}&js_code={2}&grant_type=authorization_code", appid, secret, code);
==========================发送请求代码。略。=====================================
/// <summary>
/// 返回结果实体:微信Api返回参数
/// </summary>
public class WxApiResult
{
/// <summary>
/// 用户唯一标识
/// </summary>
public string openid { get; set; }
/// <summary>
/// 会话密钥
/// </summary>
public string session_key { get; set; }
/// <summary>
/// 用户在开放平台的唯一标识符
/// </summary>
public string unionid { get; set; }
/// <summary>
/// 错误状态码
/// </summary>
public string errcode { get; set; }
/// <summary>
/// 错误信息
/// </summary>
public string errmsg { get; set; }
}