weixin_api/wxpay/xcx/GetOpenid.ashx.cs

(完整代码) 1KB

using LitJson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WxPayAPI;

namespace weixin_api.wxpay.xcx
{
    /// <summary>
    /// GetOpenid 的摘要说明
    /// </summary>
    public class GetOpenid : IHttpHandler
    {

        public string openid { get; set; }

        public void ProcessRequest(HttpContext context)
        {

            string code = HttpContext.Current.Request.QueryString["code"];
            WxPayData data = new WxPayData();
            data.SetValue("appid", WxPayConfig.GetConfig().GetAppID());
            data.SetValue("secret", WxPayConfig.GetConfig().GetAppSecret());
            data.SetValue("code", code);
            data.SetValue("grant_type", "authorization_code");
            string url = "https://api.weixin.qq.com/sns/oauth2/access_token?" + data.ToUrl();

            //请求url以获取数据  
            string result = HttpService.Get(url);

            Log.Debug(this.GetType().ToString(), "GetOpenidAndAccessTokenFromCode response : " + result);

            //保存access_token,用于收货地址获取  
            JsonData jd = JsonMapper.ToObject(result);
            //access_token = (string)jd["access_token"];  

            //获取用户openid  
            openid = (string)jd["openid"];
            context.Response.Write(openid);//获取H5调起JS API参数  

        } 

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。