Example #1
0
        private void SendOrderMessage(string msg)
        {
            WeChatDefault wxDefault = new WeChatDefault();
            var           appId     = _settingService.GetSettingByKey <string>(WeChatSettingNames.AppId);
            var           appSecret = _settingService.GetSettingByKey <string>(WeChatSettingNames.AppSecret);

            var    token = wxDefault.GetAccessToken(_cacheManager, appId, appSecret);
            string url   = string.Format(msgUrl, token.access_token);
            HttpWebResponseUtility client = new HttpWebResponseUtility();

            client.CreatePostHttpResponse(url: url, data: msg);
        }
Example #2
0
        /// <summary>
        /// 用户信息
        /// </summary>
        /// <returns></returns>
        public ActionResult Info()
        {
            var           key       = string.Format(CustomerCacheNames.CACHE_CUSTOMER_TO_WECHAT, this.CustomerId);
            var           customer  = _customerService.GetCustomerId(this.CustomerId);
            WeChatDefault wxDefault = new WeChatDefault();
            var           userInfo  = _cacheManager.GetCache(key).Get(this.CustomerId.ToString(), () => wxDefault.GetWeChatUserInfo(_settingService, _cacheManager, customer.OpenId));

            var model = customer.MapTo <CustomerModel>();

            model.NickName       = customer.NickName;
            model.CustomerAvatar = userInfo.headimgurl;
            return(View(model));
        }
Example #3
0
        public ActionResult Center()
        {
            var           model     = new CustomerCenterModel();
            WeChatDefault wxDefault = new WeChatDefault();
            var           customer  = _customerService.GetCustomerId(this.CustomerId);
            var           key       = string.Format(CustomerCacheNames.CACHE_CUSTOMER_TO_WECHAT, this.CustomerId);
            var           userInfo  = _cacheManager.GetCache(key).Get(this.CustomerId.ToString(), () => wxDefault.GetWeChatUserInfo(_settingService, _cacheManager, customer.OpenId));

            model.CustomerId     = this.CustomerId;
            model.CustomerAvatar = userInfo.headimgurl;
            model.CustomerName   = userInfo.nickname;
            model.Promoter       = customer.GetCustomerAttributeValue <bool>(CustomerAttributeNames.IsPromoter);
            model.BindMobile     = String.IsNullOrWhiteSpace(customer.Mobile);

            return(View(model));
        }
Example #4
0
        public ActionResult MyQRCode()
        {
            var customer   = _customerService.GetCustomerId(this.CustomerId);
            var expireTime = customer.GetCustomerAttributeValue <DateTime>(CustomerAttributeNames.QRCodeExpireTime);

            var expire = _settingService.GetSettingByKey <int>(WeChatSettingNames.Expire);
            var model  = new CustomerQRModel();

            model.CustomerID = this.CustomerId;

            if (expireTime > DateTime.Now)
            {
                model.QR_Url = customer.GetCustomerAttributeValue <string>(CustomerAttributeNames.MyQR_Code);
            }
            else
            {
                WeChatDefault wx = new WeChatDefault();

                var appId     = _settingService.GetSettingByKey <string>(WeChatSettingNames.AppId);
                var appSecret = _settingService.GetSettingByKey <string>(WeChatSettingNames.AppSecret);

                var accessToken = GetAccessToken(appId, appSecret);
                //var accessToken = _cacheManager.GetCache(ArtSolutionConsts.CACHE_ACCESS_TOKEN)
                //    .Get(ArtSolutionConsts.CACHE_ACCESS_TOKEN, () => GetAccessToken(appId, appSecret));

                string url = string.Format(QRCode_Url, accessToken.access_token);
                expireTime = DateTime.Now.AddSeconds(expire * 24 * 60 * 60);

                var result = wx.QRCode(_cacheManager, appId, appSecret, expire * 24 * 60 * 60, false, this.CustomerId);
                customer.SaveCustomerAttribute <DateTime>(CustomerAttributeNames.QRCodeExpireTime, expireTime);
                customer.SaveCustomerAttribute <string>(CustomerAttributeNames.MyQR_Code, result);

                model.QR_Url = result;
            }
            model.CreateTime = expireTime;
            model.Expire     = expire;

            WeChatDefault wechat = new WeChatDefault();
            var           config = wechat.WxConfig(_settingService, _cacheManager, this.Request.Url.Host + this.Request.Url.PathAndQuery);

            ViewData["Settings"] = config;
            return(View(model));
        }