Esempio n. 1
0
        public static User GetUserInfoByCodeOrCookie(HttpContextBase context, string code = null)
        {
            JahomDBContext jahomDBContext = new JahomDBContext();

            if (string.IsNullOrEmpty(code))
            {
                var userStr = CookieHelper.GetCookie(context);
                if (!string.IsNullOrEmpty(userStr))
                {
                    return(JsonConvert.DeserializeObject <User>(userStr));
                }
                return(null);
            }
            else
            {
                var  openId = AccessTokenManage.GetOpenIdByCode(code);
                User user   = jahomDBContext.User.FirstOrDefault(u => u.OpenId == openId);
                if (user != null)
                {
                    CookieHelper.SetCookie(context, JsonConvert.SerializeObject(user));
                }
                else
                {
                    user = new User()
                    {
                        OpenId = openId
                    };
                }

                return(user);
            }
        }
Esempio n. 2
0
        public static string CreateUrl(string inputId, string codeType)
        {
            string dataFormat      = persitenceStr.Replace("#", inputId + "&" + codeType);
            string tokenName       = AccessTokenManage.GetAccessTokenName();
            string responseContent = string.Empty;
            string urlCreateQR     = string.Format(urlQRCode, tokenName);

            HttpManager.Request(urlCreateQR, out responseContent, WebRequestMethods.Http.Post, data: dataFormat);
            Ticket tick      = Newtonsoft.Json.JsonConvert.DeserializeObject <Ticket>(responseContent);
            string strTicket = System.Web.HttpUtility.UrlEncode(tick.ticket);
            string url       = string.Format(urlGetTwoDimensionCodeByTickt, strTicket);

            return(url);
        }
Esempio n. 3
0
        public static void InitButton()
        {
            var menuPath = AppDomain.CurrentDomain.BaseDirectory + "Common/Menu.txt";
            var munuStr  = File.ReadAllText(menuPath);
            var munuUri  = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}";

            string url             = string.Format(munuUri, AccessTokenManage.GetAccessTokenName());
            var    responseContent = string.Empty;

            HttpManager.Request(url, out responseContent, WebRequestMethods.Http.Post, data: munuStr);
            var res = Newtonsoft.Json.JsonConvert.DeserializeObject <WCResult>(responseContent);

            if (res.errcode == "40001")          //token失效码
            {
                url = string.Format(munuUri, AccessTokenManage.GetAccessTokenName(true));
                HttpManager.Request(url, out responseContent, WebRequestMethods.Http.Post, data: munuStr);
            }
        }
Esempio n. 4
0
        public static string GetJsapiTicket()
        {
            var jsapiTicketRedisStr = HttpRuntime.Cache.Get(ConstString.AppId);

            if (jsapiTicketRedisStr == null)
            {
                string responseContent = string.Empty;
                string tokenName       = AccessTokenManage.GetAccessTokenName();
                string url             = string.Format(urlJsapiTicket, tokenName);
                bool   res             = HttpManager.Request(url, out responseContent, WebRequestMethods.Http.Post, data: "");
                var    ticketObj       = Newtonsoft.Json.JsonConvert.DeserializeObject <Ticket>(responseContent);
                if (ticketObj.ErrorCode == 0)
                {
                    jsapiTicketRedisStr = ticketObj.ticket;
                    HttpRuntime.Cache.Insert(ConstString.AppId, jsapiTicketRedisStr, null, DateTime.Now.AddSeconds(Convert.ToInt32(ticketObj.expires_in) - 100), Cache.NoSlidingExpiration);
                }
            }

            return(jsapiTicketRedisStr.ToString());
        }