コード例 #1
0
ファイル: WXUtil.cs プロジェクト: sunbirdwyk/wyk-base
        /// <summary>
        /// 根据微信授权code获取微信信息
        /// </summary>
        /// <param name="code">微信授权code</param>
        /// <param name="app_id">公众号appid</param>
        /// <param name="app_secret">公众号app_secret</param>
        /// <returns></returns>
        public static WXUserInfo userInfoByCode(string code, string app_id, string app_secret)
        {
            WXGetBase get = new WXGetBase();

            get.set("appid", app_id);
            get.set("secret", app_secret);
            get.set("code", code);
            get.set("grant_type", "authorization_code");
            var response = HttpUtil.get(WXUrls.WEB_AUTH_ACCESS_TOKEN, null, get.parameters);
            var result   = new WXResponseBase(response);

            if (!result.isSuccess())
            {
                return(null);
            }
            string access_token = result.getValueString("access_token");
            string open_id      = result.getValueString("openid");

            if (open_id.isNull() || access_token.isNull())
            {
                return(null);
            }
            get.clear();
            get.set("access_token", access_token);
            get.set("openid", open_id);
            get.set("lang", "zh_CN");
            response = HttpUtil.get(WXUrls.GET_USERINFO, null, get.parameters);
            result   = new WXResponseBase(response);
            if (result.isSuccess())
            {
                return(new WXUserInfo(result));
            }
            return(null);
        }
コード例 #2
0
ファイル: WXUtil.cs プロジェクト: sunbirdwyk/wyk-base
        /// <summary>
        /// 根据用户openid获取微信信息
        /// </summary>
        /// <param name="open_id">用户openid</param>
        /// <param name="access_token">公众号的access_token</param>
        /// <returns></returns>
        public static WXUserInfo userInfoByOpenId(string open_id, string access_token)
        {
            if (open_id.isNull())
            {
                return(null);
            }
            WXGetBase get = new WXGetBase();

            get.clear();
            get.set("access_token", access_token);
            get.set("openid", open_id);
            get.set("lang", "zh_CN");
            var response = HttpUtil.get(WXUrls.GET_USERINFO, null, get.parameters);
            var result   = new WXResponseBase(response);

            if (result.isSuccess())
            {
                return(new WXUserInfo(result));
            }
            return(null);
        }