Esempio n. 1
0
        public static string CreateQrCodeResult(string accessToken, int expireSeconds, object sceneId)
        {
            //var urlFormat = string.Format("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={0}", accessToken);
            string urlFormat = string.Format(WxSysConfig.QrCode_Url(accessToken), accessToken);
            //log4net.LogHelper.WriteInfo(typeof(WxSysConfig), urlFormat);

            object data = null;

            if (expireSeconds > 0)
            {
                data = new
                {
                    expire_seconds = expireSeconds,
                    action_name    = "QR_SCENE",
                    action_info    = new
                    {
                        scene = new
                        {
                            scene_id = sceneId
                        }
                    }
                };
            }
            else
            {
                data = new
                {
                    action_name = "QR_LIMIT_SCENE",
                    action_info = new
                    {
                        scene = new
                        {
                            scene_id = sceneId
                        }
                    }
                };
            }

            JavaScriptSerializer jss = new JavaScriptSerializer();
            string json = jss.Serialize(data);

            return(DoPostJson(urlFormat, json));
        }
Esempio n. 2
0
        /// <summary>
        /// 公众号获取微信用户基本信息
        /// </summary>
        /// <param name="token"></param>
        /// <param name="openid"></param>
        /// <returns></returns>
        public static WeiXinUser GetWxUserInfo(string token, string openid)
        {
            WeiXinUser model = new WeiXinUser();
            //string url = string.Format("https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang=zh_CN", token, openid);
            string url = string.Format(WxSysConfig.User_infoURL(token), token, openid);

            string jsonstr = HttpGet(url);

            try
            {
                model          = new JavaScriptSerializer().Deserialize <WeiXinUser>(jsonstr);
                model.serverid = token;
            }
            catch (Exception ex)
            {
                log4net.LogHelper.WriteInfo(typeof(WxHelper), "GetWxUserInfo出错:" + url + "===" + ex.Message);
                return(null);
            }
            return(model);
        }