Esempio n. 1
0
        public static WechatJsTicket RefrenshJsapi_ticket(string access_token, string userAgent)
        {
            string url = string.Format("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={0}&type=jsapi", access_token);

            HttpWebResponse response = WechatHttpWebResponseUtility.CreateGetHttpResponse(url, null, userAgent, null);

            //Stream stream = response.GetResponseStream();
            //StreamReader sr = new StreamReader(stream);
            //string result = sr.ReadToEnd();
            string         result = WechatHttpWebResponseUtility.HttpResponseToString(response);
            WechatJsTicket ticket = JsonConvert.DeserializeObject <WechatJsTicket>(result);

            if (string.IsNullOrEmpty(ticket.ticket))
            {
                WechatError err = new WechatError();
                err = JsonConvert.DeserializeObject <WechatError>(result);
                string error = "appid或者appsecret错误,无法获取access_token 微信错误代码:" + err.errcode + "微信错误信息:" + err.errmsg;
                WechatLogHelper.Error(error);
            }
            else
            {
                string ticketExpiredTime = System.DateTime.Now.AddMinutes(115).ToString("yyyy-MM-dd HH:mm:ss");

                ConfigTools.WriteKey("WechatJsapi_ticket", ticket.ticket);
                ConfigTools.WriteKey("WechatJsapi_ticketExpiredTime", ticketExpiredTime);
            }


            return(ticket);
        }
Esempio n. 2
0
        public static WechatUserInfo GetUserInfo(string access_token, string userAgent, string openid)
        {
            WechatUserInfo userinfo = new WechatUserInfo();

            string url = string.Format("https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang=zh_CN", access_token, openid);

            HttpWebResponse response = WechatHttpWebResponseUtility.CreateGetHttpResponse(url, null, userAgent, null);

            string result = WechatHttpWebResponseUtility.HttpResponseToString(response);

            userinfo = JsonConvert.DeserializeObject <WechatUserInfo>(result);

            return(userinfo);
        }