public void VerifyLogin(string code, string encryptedData, string iv) { if (string.IsNullOrEmpty(code) || string.IsNullOrEmpty(encryptedData) || string.IsNullOrEmpty(iv)) { result.info = ErrorType.MISS_PARAMETER; return; } string data = WeChatHelper.GetSession_key(code); var obj = JsonHelper.Deserialize <dynamic>(data); if (obj.openid != null) { //获取成功 int res = 1; // //获取普通用户 Nbh_Users User = Nbh_UsersServices.Instance.GetNbhUsers(Convert.ToString(obj.openid)); //获取营业员 var Waiter = Nbh_UsersServices.Instance.GetUserWaiter(Convert.ToString(obj.openid)); if (User == null && Waiter == null) {//不存在 WxUserInfo wxUser = WeChatHelper.Decrypt(encryptedData, iv, Convert.ToString(obj.session_key)); User = new Nbh_Users() { OpenId = obj.openid, UnionId = obj.unionid == null ? "0" : obj.unionid, Nick_Name = wxUser.nickName, City = wxUser.city, User_Sex = Convert.ToInt32(wxUser.gender), Province = wxUser.province, Pic_Url = wxUser.avatarUrl, Status = 0, Register_Time = DateTime.Now, Last_Login = DateTime.Now, IsPlatform = 1 }; res = Nbh_UsersServices.Instance.Register(User); } if (res == 1) { if (Waiter != null) { LoginStatus.Waiter_Id = Convert.ToInt32(Waiter.WAITER_ID); LoginStatus.UserType = 1; LoginStatus.HallId = Convert.ToInt32(Waiter.HALL_ID); } LoginStatus.User_Id = User.User_ID; LoginStatus.sessionId = Guid.NewGuid().ToString("N"); LoginStatus.OpenId = obj.openid; LoginStatus.SessionKey = obj.session_key; //将信息存入redis RedisHelper.SetCharValue(CacheType.UserInfo, LoginStatus.sessionId, JsonHelper.ToJsonString(LoginStatus)); result.success = true; result.data = new { sessionId = LoginStatus.sessionId, UserType = LoginStatus.UserType, IsPlatform = User.IsPlatform }; } else { result.info = "用户注册失败"; } } else { result.info = obj.errmsg; } }