Example #1
0
        public static bool GetOpenId(string phone, out string openId, out string errMsg)
        {
            openId = string.Empty;
            errMsg = string.Empty;
            IMobileTokenService mobileTokenService = BLLContainer.Resolve <IMobileTokenService>();
            var model = mobileTokenService.GetModels(p => p.Phone.Equals(phone)).FirstOrDefault <t_MobileToken>();

            if (model != null)
            {
                openId = model.OpenId;
                if (string.IsNullOrEmpty(openId))
                {
                    errMsg = "用户未绑定openId";
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                errMsg = "用户未不存在";
                return(false);
            }
        }
Example #2
0
        public static void UpdateOpenId(string phone, string openId)
        {
            IMobileTokenService mobileTokenService = BLLContainer.Resolve <IMobileTokenService>();
            var model = mobileTokenService.GetModels(p => p.Phone.Equals(phone)).FirstOrDefault <t_MobileToken>();

            if (model != null)
            {
                model.OpenId = openId;
                mobileTokenService.Update(model);
            }
        }
Example #3
0
        public static bool UpdateAliBuyerId(string phone, string buyerId)
        {
            IMobileTokenService mobileTokenService = BLLContainer.Resolve <IMobileTokenService>();
            var model = mobileTokenService.GetModels(p => p.Phone.Equals(phone)).FirstOrDefault <t_MobileToken>();

            if (model != null)
            {
                model.AliId = buyerId;
                return(mobileTokenService.Update(model));
            }
            return(false);
        }
Example #4
0
        public static void Init()
        {
            IMobileTokenService mobileTokenService = BLLContainer.Resolve <IMobileTokenService>();
            var models = mobileTokenService.GetModels(p => 1 == 1).ToList <t_MobileToken>();

            if (models.Count > 0)
            {
                for (int y = 0; y < models.Count; y++)
                {
                    MobileTokenCache.AddToken(models[y].Phone, models[y].Token);
                }
            }
        }
Example #5
0
        public static bool IsHasMobile(string aliId, out string mobile)
        {
            mobile = string.Empty;

            IMobileTokenService mobileTokenService = BLLContainer.Resolve <IMobileTokenService>();
            var model = mobileTokenService.GetModels(p => p.AliId.Equals(aliId)).FirstOrDefault <t_MobileToken>();

            if (model != null && !string.IsNullOrEmpty(model.Phone))
            {
                mobile = model.Phone;
                return(true);
            }
            return(false);
        }
Example #6
0
        private static void SetDBMobileToken(string Token, string Phone)
        {
            IMobileTokenService mobileTokenService = BLLContainer.Resolve <IMobileTokenService>();
            var           model = mobileTokenService.GetModels(p => p.Phone.Equals(Phone)).FirstOrDefault <t_MobileToken>();
            t_MobileToken mtk   = new t_MobileToken();

            if (model == null)
            {
                mtk.Token      = Token;
                mtk.CreateTime = DateTime.Now;
                mtk.Phone      = Phone;
                mtk.OpenId     = string.Empty;
                mobileTokenService.Add(mtk);
            }
            else
            {
                model.Token      = Token;
                model.UpdateTime = DateTime.Now;
                mobileTokenService.Update(model);
            }
        }
Example #7
0
        /// <summary>
        /// H5页面微信授权
        /// </summary>
        private void H5AuthCommon(string code)
        {
            string accsess_token = string.Empty;
            string refresh_token = string.Empty;
            string openId        = string.Empty;
            string errMsg        = string.Empty;

            try
            {
                if (TokenMana.GetTokenForScanQR(code, out accsess_token, out refresh_token, out openId, out errMsg))
                {
                    bool isReg = false;
                    IMobileTokenService mobileTokenService = BLLContainer.Resolve <IMobileTokenService>();
                    var mobileTokenModel = mobileTokenService.GetModels(p => p.OpenId.Equals(openId)).FirstOrDefault <t_MobileToken>();
                    if (mobileTokenModel != null)
                    {
                        IMemberTokenService memberTokenService = BLLContainer.Resolve <IMemberTokenService>();
                        var memberTokenModel = mobileTokenService.GetModels(p => p.OpenId.Equals(openId)).FirstOrDefault <t_MobileToken>();
                        if (memberTokenModel != null)
                        {
                            isReg = true;
                        }
                    }
                    string redirectUrl = string.Format("{0}?openId={1}&isReg={2}", CommonConfig.H5WeiXinAuthRedirectUrl, openId, Convert.ToInt32(isReg));
                    Response.Redirect(redirectUrl);
                }
                else
                {
                    LogHelper.SaveLog(TxtLogType.WeiXin, TxtLogContentType.Common, TxtLogFileType.Day, "errMsg:" + errMsg);
                    //重定向的错误页面
                    Response.Redirect(WeiXinConfig.RedirectErrorPage);
                }
            }
            catch (Exception e)
            {
                LogHelper.SaveLog(TxtLogType.WeiXin, TxtLogContentType.Exception, TxtLogFileType.Day, "Exception:" + e.Message);
            }
        }
 public MobileTokenController(IGenericRepository <MobileToken> repo, IMobileTokenService tokenService, IGenericRepository <Person> personRepo)
     : base(repo, personRepo)
 {
     _tokenService = tokenService;
 }