public async Task <WxUserModel> FindWxUser(string id, string companyCode) { try { var user = new WxUserModel(); user = await _efRepositiry.FirstOrDefaultAsync <WxUserModel>(s => s.IsDeleted != 1 && s.Id == id); return(user); } catch (Exception ex) { _errLogger.Error($"--------------------------------------------------------------------------------"); _errLogger.Error($"[MSG]:{ex.Message};\n"); _errLogger.Error($"[Source]:{ex.Source}\n"); _errLogger.Error($"[StackTrace]:{ex.StackTrace}\n"); _errLogger.Error($"[StackTrace]:{ex.TargetSite.Name}\n"); _errLogger.Error($"[Method]: AuthRepository.FindWxUser \n"); _errLogger.Error($"[IEfRepository]: _efRepositiry is null? {_efRepositiry == null} \n"); _errLogger.Error($"[UnionId]: {id} \n"); _errLogger.Error($"[companyCode]: {companyCode} \n"); _errLogger.Error($"--------------------------------------------------------------------------------"); } return(null); }
/// <summary> /// 验证码是否正确 /// </summary> /// <param name="wxUserModel">传入Code、Mobile</param> /// <param name="workUser"></param> /// <returns></returns> public async Task <ReturnValueModel> VerifySmsCode(WxUserModel wxUserModel) { ReturnValueModel rvm = new ReturnValueModel(); //var wxUser = await _rep.FirstOrDefaultAsync<WxUserModel>(s => s.UnionId == wxUserModel.UnionId); //var timeLimit = (DateTime.Now - wxUser.CodeTime)?.Minutes; ////五分钟超时 //if (timeLimit > 5) //{ // rvm.Success = false; // rvm.Msg = "验证码过期,请重新发送验证码!"; // rvm.Result = timeLimit; //} //else //{ // if (wxUser.Code == wxUserModel.Code && wxUser.Mobile == wxUserModel.Mobile) // { // rvm.Success = true; // rvm.Msg = "验证成功!"; // rvm.Result = wxUser.Code; // } // else // { // rvm.Success = false; // rvm.Msg = "验证码错误,请重新输入!"; // rvm.Result = wxUserModel.Code; // } //} return(rvm); }
public IHttpActionResult SendCode(WxUserModel wxUserModel) { string mobile = wxUserModel?.Mobile; var ret = _wxRegisterService.SendVerifyCode(WorkUser, mobile); return(Ok(ret)); }
/// <summary> /// 创建微信用户 /// </summary> /// <returns></returns> public ReturnValueModel AddDocUser(WxUserModel wxUserModel) { ReturnValueModel rvm = new ReturnValueModel(); WxUserModel wxUser = new WxUserModel { Id = Guid.NewGuid().ToString(), UnionId = wxUserModel.UnionId, IsDeleted = 0, IsCompleteRegister = 0, IsVerify = 0, IsEnabled = 0, CreateTime = DateTime.Now }; _rep.Insert(wxUser); _rep.SaveChanges(); LoggerHelper.WriteLogInfo($"---- AddDocUser Begin 创建微信用户 ---------------"); LoggerHelper.WriteLogInfo($"[doctor.Id]:{wxUser?.Id}"); LoggerHelper.WriteLogInfo($"[doctor.UnionId]:{ wxUser?.UnionId }"); LoggerHelper.WriteLogInfo($"[doctor.IsVerify]:{ wxUser?.IsVerify }"); LoggerHelper.WriteLogInfo($"---- AddDocUser End 创建微信用户 ----------------"); rvm.Msg = "success"; rvm.Success = true; rvm.Result = new { wxUser = wxUser }; return(rvm); }
public IHttpActionResult VerifyCode(WxUserModel wxUserModel) { string code = wxUserModel?.Code; var ret = _wxRegisterService.VerifyCode(WorkUser, code); return(Ok(ret)); }
/// <summary> /// 签到接口 /// </summary> /// <param name="wxUser">医生信息</param> /// <param name="fkMeetingId">费卡文库的会议Id</param> /// <returns></returns> public ReturnValueModel SyncCheckIn(WxUserModel wxUser, string fkMeetingId) { CheckInSyncModel model = new CheckInSyncModel(); model.ActivityID = fkMeetingId; model.OpenId = wxUser.OpenId; model.UnionId = wxUser.UnionId; model.OpenName = wxUser.WxName; model.Name = wxUser.UserName; model.OneHCPID = wxUser.Id; model.OneHCPState = wxUser.status; model.OneHCPReason = wxUser.reason; model.YSID = wxUser.yunshi_doctor_id; return(SyncCheckIn(model)); }
/// <summary> /// 缓存微信用户信息 /// </summary> /// <returns></returns> public void CacheWxUser(WxUserModel wxUser) { if (wxUser == null) { return; } var cache = ContainerManager.Resolve <ICacheManager>(); var workUser = cache.Get <WorkUser>(wxUser.Id); if (workUser == null) { LoggerHelper.WriteLogInfo("WxRegisterService.CacheWxUser: workUser is null"); workUser = new WorkUser(); } workUser.WxUser = wxUser; cache.Set(wxUser.Id, workUser, 12); LoggerHelper.WriteLogInfo("WxRegisterService.CacheWxUser: wxUser.UserName:"******"WxRegisterService.CacheWxUser: wxUser.IsVerify:" + wxUser.IsVerify); }
/// <summary> /// 发送短信验证码 /// </summary> /// <param name="wxUserModel">传入手机号码</param> /// <param name="workUser"></param> /// <returns></returns> public async Task <ReturnValueModel> SendSms(WxUserModel wxUserModel) { ReturnValueModel rvm = new ReturnValueModel(); //var docModel = await _rep.FirstOrDefaultAsync<WxUserModel>(s => // s.UnionId == wxUserModel.UnionId || s.OpenId == wxUserModel.OpenId); //if (docModel != null) //{ // var code = RandomUtil.GenerateRandomCode(6); // SendSmsModel sm = new SendSmsModel // { // CompanyCode = "4033", // ParamName = JsonConvert.SerializeObject(new // { // code= code // }).Base64Encoding(), // PhoneNumbers = wxUserModel.Mobile, // SignName = "", // SystemId = "", // TemplateId = "" // }; // docModel.Mobile = wxUserModel.Mobile; // docModel.Code = code; // docModel.CodeTime = DateTime.Now; // var smsResult = SmsUtil.SendMessage(sm); // rvm.Msg = smsResult.Message; // rvm.Success = smsResult.ResultFlag; // rvm.Result = new // { // smsResult // }; // _rep.Update(docModel); // _rep.SaveChanges(); //} return(rvm); }
/// <summary> /// 新增修改 参会报名表 /// </summary> /// <param name="inputDto"></param> /// <returns></returns> public ReturnValueModel AddOrUpdate(RegistrationFormInputDto inputDto) { ReturnValueModel rvm = new ReturnValueModel { Success = true, Msg = "", }; if (string.IsNullOrEmpty(inputDto.Unionid)) { rvm.Success = false; rvm.Msg = "Unionid为空"; rvm.Result = "表单已过期请重新刷新页面"; return(rvm); } //LoggerHelper.WriteLogInfo("[AAAAAAA]" + inputDto.Unionid /*Json.ToJson(inputDto)*/); var user = _rep.FirstOrDefault <WxUserModel>(s => s.IsDeleted != 1 && s.UnionId == inputDto.Unionid); if (user == null) { user = new WxUserModel() { Id = Guid.NewGuid().ToString(), UserName = inputDto.UserName, RegistrationAge = inputDto.RegistrationAge, RegistrationGender = inputDto.RegistrationGender, Title = inputDto.Title, HospitalName = inputDto.HospitalName, DepartmentName = inputDto.DepartmentName, RegistrationIsBasicLevel = inputDto.RegistrationIsBasicLevel, Province = inputDto.Province, City = inputDto.City, Area = inputDto.Area, Mobile = $"{inputDto.Mobile}_H5", SourceAppId = inputDto.SourceAppId, SourceType = "5", //OpenId = inputDto.Openid, WxSceneId = inputDto.WxSceneId, UnionId = inputDto.Unionid, WxCity = inputDto.WxCity, WxName = inputDto.WxNickname, WxCountry = inputDto.WxCountry, WxGender = inputDto.WxSex.ToString(), WxPicture = inputDto.WxPicture, WxProvince = inputDto.WxProvince, CreateTime = DateTime.Now, IsDeleted = 0, IsEnabled = 0, IsVerify = 5, IsCompleteRegister = 1, IsSalesPerson = 0, }; _rep.Insert(user); _rep.SaveChanges(); } else { user.UserName = inputDto.UserName; user.RegistrationAge = inputDto.RegistrationAge; user.RegistrationGender = inputDto.RegistrationGender; user.Title = inputDto.Title; user.HospitalName = inputDto.HospitalName; user.DepartmentName = inputDto.DepartmentName; user.RegistrationIsBasicLevel = inputDto.RegistrationIsBasicLevel; user.Province = inputDto.Province; user.City = inputDto.City; user.Area = inputDto.Area; user.Mobile = $"{inputDto.Mobile}_H5"; user.SourceAppId = inputDto.SourceAppId; // user.OpenId = inputDto.Openid; user.WxSceneId = inputDto.WxSceneId; // user.UnionId = inputDto.Unionid; user.WxCity = inputDto.WxCity; user.WxName = inputDto.WxNickname; user.WxCountry = inputDto.WxCountry; user.WxGender = inputDto.WxSex.ToString(); user.WxPicture = inputDto.WxPicture; user.WxProvince = inputDto.WxProvince; user.UpdateTime = DateTime.Now; _rep.Update(user); _rep.SaveChanges(); } rvm.Result = user; return(rvm); }
/// <summary> /// 获取微信发现页面数据 /// </summary> /// <param name="workUser"></param> /// <returns></returns> public ReturnValueModel WxDisMainPage(WorkUser workUser) { System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start();//监视代码运行时间 ReturnValueModel rvm = new ReturnValueModel(); //LoggerHelper.WarnInTimeTest("***********************"); //LoggerHelper.WarnInTimeTest("Inner-[WxDisMainPage] Start:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss fff")); //LoggerHelper.WriteLogInfo("****************[WxDisMainPage]获取微信发现页面数据 开始**********************"); WxUserModel wxUser = null; //LoggerHelper.WriteLogInfo("[WxDisMainPage] workUser.WxUser.UnionId:" + (workUser?.WxUser?.UnionId ?? "空的!!!")); if (!string.IsNullOrEmpty(workUser?.WxUser?.UnionId)) { wxUser = _rep.FirstOrDefault <WxUserModel>(s => s.IsDeleted != 1 && s.UnionId == workUser.WxUser.UnionId); } //LoggerHelper.WriteLogInfo("[WxDisMainPage] unionID:" + (wxUser?.UnionId ?? "空的!!!")); //TODO激励语 var motivational = "路漫漫其修远兮,吾将上下而求索"; if (workUser != null) { motivational = ReturnInspire(workUser); } LoggerHelper.WriteLogInfo("[WxDisMainPage]:准备获取页面数据"); if (wxUser != null && wxUser.IsCompleteRegister == 1) { ////推荐会议主题 //var meets = _rep.Where<MeetInfo>(s => s.MeetDep == wxUser.DepartmentName) // .OrderByDescending(o => o.MeetStartTime).Take(2); LoggerHelper.WriteLogInfo("[WxDisMainPage]:获取页面数据"); DateTime dt = DateTime.Now; //当前时间 DateTime startWeek = Convert.ToDateTime(dt.AddDays(1 - Convert.ToInt32(dt.DayOfWeek.ToString("d"))).ToString("yyyy-MM-dd") + " 00:00:00"); //本周周一 DateTime endWeek = Convert.ToDateTime(startWeek.AddDays(6).ToString("yyyy-MM-dd") + " 23:59:59"); //本周周日 DateTime startMonth = Convert.ToDateTime(dt.AddDays(1 - dt.Day).ToString("yyyy-MM-dd") + " 00:00:00"); //本月月初 DateTime endMonth = Convert.ToDateTime(startMonth.AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd") + " 23:59:59"); //本月月末// var lastStartWeek = Convert.ToDateTime(DateTime.Now.AddDays(Convert.ToInt32(1 - Convert.ToInt32(DateTime.Now.DayOfWeek)) - 7).ToString("yyyy-MM- dd") + " 00:00:00"); //上周一 var lastEndWeek = Convert.ToDateTime(DateTime.Now.AddDays(Convert.ToInt32(1 - Convert.ToInt32(DateTime.Now.DayOfWeek)) - 7).AddDays(6).ToString("yyyy-MM-dd") + " 23:59:59"); //上周日 //当前年月 var currentYM = DateTime.Now.Year + "年" + DateTime.Now.Month + "月"; //var recordList = _rep.Table<MyLRecord>().Where(s => s.UnionId == workUser.WxUser.UnionId).ToList(); var recordList = _rep.Table <MyLRecord>().Where(s => s.WxUserId == workUser.WxUser.Id && s.IsDeleted != 1).ToList(); //本周学习时间 var thisLearnHours = getLearningHours(recordList, startWeek, endWeek); var lastLearnHours = getLearningHours(recordList, lastStartWeek, lastEndWeek); string learnDiffString = "增加"; if (thisLearnHours - lastLearnHours < 0) { learnDiffString = "减少"; } //上周学习时间 var learnCompare = "比上周" + learnDiffString + System.Math.Abs(thisLearnHours - lastLearnHours) + "小时"; //本周参会次数 线上学习 线下签到 var meetsignlist = (from a in _rep.Table <MyMeetOrder>() .Where(s => s.IsDeleted == 0 && s.CreateUser == workUser.WxUser.Id) select new MeetList { LDate = a.CreateTime }).Union(from a in _rep.Table <MeetSignUp>() .Where(s => s.IsDeleted == 0 && s.SignUpUserId == workUser.WxUser.Id) select new MeetList { LDate = a.SignInTime }).ToList(); var thisMeetingTimes = getMeetingTimes(meetsignlist, startWeek, endWeek); var lastMeetingTimes = getMeetingTimes(meetsignlist, lastStartWeek, lastEndWeek); string meetingDiffString = "增加"; if (thisMeetingTimes - lastMeetingTimes < 0) { meetingDiffString = "减少"; } //上周参会次数 var meetCompare = "比上周" + meetingDiffString + System.Math.Abs(thisMeetingTimes - lastMeetingTimes) + "次"; //TODO百分比 右连接 //var recordAllList = from t in _rep.Table<MyLRecord>().Where(t => t.LDate.Year == DateTime.Now.Year && t.LDate.Month == DateTime.Now.Month) // join f in _rep.Table<WxUserModel>().Where(s => s.IsDeleted != 1 && s.HospitalName != null) // on t.WxUserId equals f.Id // into joinRecord // from t3 in joinRecord.DefaultIfEmpty() // group t by new // { // //unionid = t.UnionId // wxuserid = t.WxUserId // } into g // select new // { // hours = g.Sum(s => s.LObjectDate), // //unionid = g.Key.unionid // wxuserid = g.Key.wxuserid // }; //var recordlist = from a in _rep.Table<MyLRecord>().Where(t => // t.LDate.Year == DateTime.Now.Year && t.LDate.Month == DateTime.Now.Month) select a; //var recordAllList = from t in _rep.Table<WxUserModel>().Where(s => s.IsDeleted != 1) // join f in _rep.Table<MyLRecord>() // on t.Id equals f.WxUserId into joinRecord // from t3 in joinRecord.DefaultIfEmpty() // select new // { // wxuserid = t3.WxUserId, // LObjectDate = t3.LObjectDate==null?0 : t3.LObjectDate // }; //var recordAllList2 = from a in recordAllList // group a by a.wxuserid // into temp // select new // { // hours = temp.Sum(s => s.LObjectDate), // wxuserid = temp.Key // }; #region 个人排名百分比 var list = (from a in _rep.Where <WxUserModel>(s => s.IsDeleted != 1) join b in _rep.Where <MyLRecord>(s => s.IsDeleted != 1) on a.Id equals b.WxUserId into JoinedModel from b in JoinedModel.DefaultIfEmpty() group new { b } by a into all select new { Id = all.Key.Id, //产品资料 DocLearnTime = all.Where(s => s.b.LObjectType == 1 || s.b.LObjectType == 2 || s.b.LObjectType == 4).Sum(s => s.b.LObjectDate).HasValue ? all.Where(s => s.b.LObjectType == 1 || s.b.LObjectType == 2 || s.b.LObjectType == 4).Sum(s => s.b.LObjectDate) : 0, }); list = list.OrderByDescending(s => s.DocLearnTime); #endregion var thisRecord = list.FirstOrDefault(s => s.Id == workUser.WxUser.Id); int recordAllCount = list.Select(s => s.Id).Distinct().Count(); int myIndex = recordAllCount; if (thisRecord != null) { myIndex = list.Where(s => s.Id != null).OrderByDescending(s => s.DocLearnTime).ToList().IndexOf(thisRecord) + 1; LoggerHelper.WarnInTimeTest("[recordAllList] 我的排名:" + myIndex); } LoggerHelper.WarnInTimeTest("[recordAllList] 总人数:" + recordAllCount); decimal learnPercent = 0; if (recordAllCount > 0) { //learnPercent = (int)Math.Ceiling((double)recordAllList.Count() - myIndex / recordAllList.Count()) * 100; //学习记录百分比 learnPercent = Math.Round(((decimal)((recordAllCount - myIndex)) / recordAllCount), 3) * 100; LoggerHelper.WriteLogInfo("[WxDisMainPage] 学习记录 recordAllCount:" + recordAllCount + ",myIndex:" + myIndex); } //判断注册时间 var isNewRegister = 1; //1 注册未满1周 if (!IsNewRegister(workUser.WxUser.creation_time)) { isNewRegister = 2; //2 注册已满1周 } rvm.Success = true; rvm.Msg = ""; rvm.Result = new { //meets = meets, isNewRegister = isNewRegister, currentYM = currentYM, motivational = motivational, thisLearnHours = thisLearnHours, learnCompare = learnCompare, meetCompare = meetCompare, thisMeetingTimes = thisMeetingTimes, learnPercent = learnPercent }; } else { rvm.Success = true; rvm.Msg = ""; rvm.Result = new { isNewRegister = 0, //未注册 motivational = motivational }; } //LoggerHelper.WriteLogInfo("[WxDisMainPage]:接口是否成功:" + ((rvm.Success == true) ? "success" : "false")); //LoggerHelper.WriteLogInfo("****************获取微信发现页面数据 结束**********************"); //LoggerHelper.WarnInTimeTest("Inner-[WxDisMainPage] End:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss fff")); stopwatch.Stop();//结束 rvm.ResponseTime = stopwatch.Elapsed.TotalMilliseconds; return(rvm); }
public Task DeleteAsync(WxUserModel user) { throw new NotImplementedException(); }
public Task <IList <UserLoginInfo> > GetLoginsAsync(WxUserModel user) { throw new NotImplementedException(); }
public Task RemoveLoginAsync(WxUserModel user, UserLoginInfo login) { throw new NotImplementedException(); }
public ReturnValueModel GetWxUserInfo(WxManageInputDto dto) { ReturnValueModel rvm = new ReturnValueModel { Msg = "success", Success = true }; //string _host1 = ConfigurationManager.AppSettings["HostUrl"]; //var authPath1 = $@"{_host1}/auth/token/Wx"; //var postStr1 = $@"username=8e1731d9-ce48-4ef1-9522-087c9bd5076a&grant_type=password"; //SysToken sysToken1 = HttpUtils.PostResponse<SysToken>(authPath1, postStr1, "application/x-www-form-urlencoded"); //var user1 = _rep.FirstOrDefault<WxUserModel>(s => s.IsDeleted != 1 && s.Id == "8e1731d9-ce48-4ef1-9522-087c9bd5076a"); //_wxRegisterService.CacheWxUser(user1);//必须添加到内存 //rvm.Result = sysToken1; //return rvm; if (string.IsNullOrEmpty(dto.AppId)) { rvm.Success = false; rvm.Msg = "The parameter 'appId' is required."; return(rvm); } var configure = _rep.FirstOrDefault <BotSaleConfigure>(o => o.IsDeleted == 0 && o.AppId == dto.AppId); if (configure == null) { rvm.Msg = "fail"; rvm.Success = false; rvm.Result = "获取BOT信息失败,请先配置BOT"; return(rvm); } System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start();//监视代码运行时间 var appId = configure.AppId; var appSecret = configure.AppSecret; var url = string.Format(WxUrls.UnionIdUrl, appId, appSecret, dto.code); var openModel = JsonConvert.DeserializeObject <OpenModel>(HttpUtils.HttpGet(url, "")); if (string.IsNullOrEmpty(openModel?.SessionKey)) { rvm.Success = false; rvm.Msg = "没有获取到SessionKey"; rvm.Result = null; LoggerHelper.WriteLogInfo("[GetUnionId]:错误------没有获取到SessionKey"); return(rvm); } var encryptedData = dto.encryptedData; var iv = dto.iv; var openid = openModel.OpenId; var wxUserInfo = dto.userInfo ?? new DecodedUserInfoModel(); var userinfo = new DecodedUserInfoModel() { openId = openid, nickName = wxUserInfo?.nickName, city = wxUserInfo?.nickName, country = wxUserInfo?.country, gender = wxUserInfo.gender, avatarUrl = wxUserInfo?.avatarUrl, province = wxUserInfo?.province, }; if (!string.IsNullOrEmpty(encryptedData) && !string.IsNullOrEmpty(iv)) { //var d= EncryptHelper.DecodeEncryptedData_1(openModel.SessionKey, dto.encryptedData, dto.iv); //userinfo = EncryptHelper.DecodeUserInfoBySessionKey(openModel.SessionKey, dto.encryptedData, dto.iv); //if (string.IsNullOrEmpty(userinfo?.unionId) || string.IsNullOrEmpty(userinfo?.openId)) //{ // LoggerHelper.WriteLogInfo("[GetUnionId]:错误------unionId无效或openid无效"); // rvm.Success = false; // rvm.Msg = "unionId无效或openid无效"; // rvm.Result = null; // return rvm; //} } var user = _rep.FirstOrDefault <WxUserModel>(s => s.IsDeleted != 1 && s.OpenId == openid); if (user == null) { user = new WxUserModel { Id = Guid.NewGuid().ToString(), UserName = "", OpenId = userinfo.openId, //UnionId = openModel.UnionId, //目前先使用OpenId,不知道为什么没获取到我的UnionId UnionId = userinfo.unionId, WxCity = userinfo.city, WxName = userinfo.nickName, WxCountry = userinfo.country, WxGender = userinfo.gender.ToString(), WxPicture = userinfo.avatarUrl, WxProvince = userinfo.province, //CreateTime = DateTime.Now, //IsDeleted = 0, //IsEnabled = 0, IsVerify = 0, IsCompleteRegister = 1,//必须要设置为1 IsSalesPerson = 1, CreateTime = DateTime.Now, //SourceAppId = wxUserInfoRequestModel.SourceAppId, // SourceType = "0", WxSceneId = dto.WxSceneId }; _rep.Insert(user); _rep.SaveChanges(); } else { user.OpenId = userinfo.openId ?? user.OpenId; user.UnionId = userinfo.unionId ?? user.UnionId; user.WxCity = userinfo.city ?? user.WxCity; user.WxName = userinfo.nickName ?? user.WxName; user.WxCountry = userinfo.country ?? user.WxCountry; user.WxGender = userinfo.gender.ToString() ?? user.WxGender; user.WxPicture = userinfo.avatarUrl ?? user.WxPicture; user.WxProvince = userinfo.province ?? user.WxProvince; user.UpdateTime = DateTime.Now; _rep.Update(user); _rep.SaveChanges(); } _wxRegisterService.CacheWxUser(user);//必须添加到内存 string _host = ConfigurationManager.AppSettings["HostUrl"]; var authPath = $@"{_host}/auth/token/Wx"; var postStr = $@"username={user.Id}&grant_type=password"; SysToken sysToken = HttpUtils.PostResponse <SysToken>(authPath, postStr, "application/x-www-form-urlencoded"); //string hostUrl = $"{HttpContext.Current.Request.Url.Scheme}://{HttpContext.Current.Request.Url.Authority}"; string OAuthServerUrl = ConfigurationManager.AppSettings["OAuthServerUrl"]; string OAuthAppId = ConfigurationManager.AppSettings["OAuthAppId"]; string OAuthServerState = ConfigurationManager.AppSettings["OAuthServerState"]; string OAuthServerScope = ConfigurationManager.AppSettings["OAuthServerScope"]; var _loginConfirmUrl = ConfigurationManager.AppSettings["loginConfirmUrl"]; //验证地址 var redirect_uri = $"{_loginConfirmUrl}/{user.Id}"; //登录获取Code地址 var authorizeurl = $"{OAuthServerUrl}/authorize?client_id={OAuthAppId}&scope={OAuthServerScope}&response_type=code&state={OAuthServerState}&redirect_uri={redirect_uri}"; rvm.Success = true; rvm.Msg = "success"; rvm.Result = new { openModel = openModel, sysToken = sysToken, user = user, authorizeurl = authorizeurl, sysTokenUrl = authPath, username = user.Id, grant_type = "password" }; stopwatch.Stop();//结束 rvm.ResponseTime = stopwatch.Elapsed.TotalMilliseconds; return(rvm); }
public IHttpActionResult RegisterDoctor(WxUserModel wxUserModel) { var ret = _wxRegisterService.UpdateDocHospitalOrDept(WorkUser, wxUserModel, true); return(Ok(ret)); }
///// <summary> ///// 更新微信用户的医院、科室信息 ///// </summary> ///// <param name="wxUserModel"></param> ///// <returns></returns> //public ReturnValueModel UpdateWxUser(WxUserModel wxUserModel) //{ // ReturnValueModel rvm = new ReturnValueModel(); // var wxUser = _rep.FirstOrDefault<WxUserModel>(s => s.IsDeleted != 1 && s.UnionId == wxUserModel.UnionId); // if (wxUser != null) // { // wxUser.HospitalName = wxUserModel.HospitalName; // wxUser.DepartmentName = wxUserModel.DepartmentName; // wxUser.UpdateTime = DateTime.Now; // wxUser.creation_time = DateTime.Now; // wxUser.IsCompleteRegister = 1; // if (wxUser.IsVerify == 0) wxUser.IsVerify = 5; //完成注册后变成认证中 // //创建手写签名 // RegisterModel model = new RegisterModel(); // model.UnionId = wxUser.UnionId; // //图片存储地址 // model.SignUpName = wxUser.Remark; // _rep.Insert(model); // _rep.Update(wxUser); // _rep.SaveChanges(); // rvm.Msg = "success"; // rvm.Success = true; // rvm.Result = new // { // wxUser = wxUser // }; // } // else // { // rvm.Msg = "fail"; // rvm.Success = false; // } // return rvm; //} /// <summary> /// 更新医生医院及科室 /// </summary> /// <param name="wxUserModel"> /// 微信用户信息: /// HospitalName, /// DepartmentName /// </param> /// <param name="isRegistering">是否想注册用户</param> /// <returns></returns> public ReturnValueModel UpdateDocHospitalOrDept(WorkUser workUser, WxUserModel wxUserModel, bool isRegistering) { ReturnValueModel rvm = new ReturnValueModel(); var id = workUser?.WxUser?.Id; var doc = _rep.FirstOrDefault <WxUserModel>(s => s.IsDeleted != 1 && s.Id == id); if (doc == null) { rvm.Success = false; rvm.Msg = "此用户未通过微信授权"; return(rvm); } if (doc.IsVerify == 1) { rvm.Success = false; rvm.Msg = "已认证用户无法修改个人信息"; return(rvm); } if (isRegistering && doc.IsCompleteRegister == 1) { LoggerHelper.WriteLogInfo($"---- UpdateDocHospitalOrDept Begin 重复注册了!! ----------"); LoggerHelper.WriteLogInfo($"[doctor.Id]:{doc?.Id}\n"); LoggerHelper.WriteLogInfo($"[doctor.UnionId]:{ doc?.UnionId }\n"); LoggerHelper.WriteLogInfo($"[doctor.WxName]:{ doc?.WxName }\n"); LoggerHelper.WriteLogInfo($"[doctor.IsVerify]:{ doc?.IsVerify }\n"); LoggerHelper.WriteLogInfo($"---- UpdateDocHospitalOrDept End -------------------------------------------"); } //认证失败的修改信息后,变成申诉中 if (!isRegistering && doc.IsVerify == 3 || doc.IsVerify == 2 || doc.IsVerify == 6) { LoggerHelper.WriteLogInfo($"---- UpdateDocHospitalOrDept Begin 认证失败的修改信息后,变成申诉中 ----------"); LoggerHelper.WriteLogInfo($"[doctor.Id]:{doc?.Id}\n"); LoggerHelper.WriteLogInfo($"[doctor.UnionId]:{ doc?.UnionId }\n"); LoggerHelper.WriteLogInfo($"[doctor.WxName]:{ doc?.WxName }\n"); LoggerHelper.WriteLogInfo($"[doctor.IsVerify]:{ doc?.IsVerify }\n"); LoggerHelper.WriteLogInfo($"---- UpdateDocHospitalOrDept End -------------------------------------------"); doc.IsVerify = 4; } //用户名 if (!string.IsNullOrEmpty(wxUserModel.UserName)) { string userName = wxUserModel.UserName; var isQua = IsQualified(userName); if (!isQua.Success) { return(isQua); } doc.UserName = userName; doc.Mobile = wxUserModel.Mobile;//手机号 } //医院名称 if (!string.IsNullOrEmpty(wxUserModel.HospitalName)) { var hospital = _rep.FirstOrDefault <HospitalInfo>(s => s.IsDeleted != 1 && s.HospitalName == wxUserModel.HospitalName); //医院名不存在就插入 if (hospital == null) { hospital = new HospitalInfo { Id = Guid.NewGuid().ToString().ToUpper(), CreateTime = DateTime.Now, CreateUser = workUser.WxUser.UnionId, HospitalName = wxUserModel.HospitalName, ComeFrom = "self", IsVerify = 0 }; _rep.Insert(hospital); _rep.SaveChanges(); } doc.HospitalName = wxUserModel.HospitalName; } //科室 if (!string.IsNullOrEmpty(wxUserModel.DepartmentName)) { doc.DepartmentName = wxUserModel.DepartmentName; } //职称 if (!string.IsNullOrEmpty(wxUserModel.Title)) { doc.Title = wxUserModel.Title; } //职务 if (!string.IsNullOrEmpty(wxUserModel.DoctorPosition)) { doc.DoctorPosition = wxUserModel.DoctorPosition; } //医生办公室电话 if (!string.IsNullOrEmpty(wxUserModel.doctor_office_tel)) { doc.doctor_office_tel = wxUserModel.doctor_office_tel; } //微信信息-城市 if (!string.IsNullOrEmpty(wxUserModel.WxCity)) { doc.WxCity = wxUserModel.WxCity; } //微信信息-微信名 if (!string.IsNullOrEmpty(wxUserModel.WxName)) { doc.WxName = wxUserModel.WxName; } //微信信息-国家 if (!string.IsNullOrEmpty(wxUserModel.WxCountry)) { doc.WxCountry = wxUserModel.WxCountry; } //微信信息-头像 if (!string.IsNullOrEmpty(wxUserModel.WxPicture)) { doc.WxPicture = wxUserModel.WxPicture; } //微信信息-性别 if (!string.IsNullOrEmpty(wxUserModel.WxGender)) { doc.WxGender = wxUserModel.WxGender; } //微信信息-省 if (!string.IsNullOrEmpty(wxUserModel.WxProvince)) { doc.WxProvince = wxUserModel.WxProvince; } if (!string.IsNullOrEmpty(wxUserModel.Province)) { doc.Province = wxUserModel.Province; } if (!string.IsNullOrEmpty(wxUserModel.City)) { doc.City = wxUserModel.City; } if (!string.IsNullOrEmpty(wxUserModel.Area)) { doc.Area = wxUserModel.Area; } doc.UpdateTime = DateTime.Now; _rep.Update(doc); _rep.SaveChanges(); //CacheWxUser(doc); rvm.Success = true; rvm.Msg = "success"; rvm.Result = new { doc }; return(rvm); }
/// <summary> /// 获取UnionID /// </summary> /// <param name="wxUserModel"></param> /// <param name="code"></param> /// <returns></returns> public ReturnValueModel GetUnionId(WxUserInfoRequestModel wxUserInfoRequestModel) { System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start();//监视代码运行时间 //LoggerHelper.WriteLogInfo("[GetUnionId]:******获取UnionID开始******"); ReturnValueModel rvm = new ReturnValueModel(); var appId = _config.GetAppIdHcp(); var appSecret = _config.GetAppSecretHcp(); var url = string.Format(WxUrls.UnionIdUrl, appId, appSecret, wxUserInfoRequestModel.code); var openModel = JsonConvert.DeserializeObject <OpenModel>(HttpUtils.HttpGet(url, "")); //LoggerHelper.WriteLogInfo("[GetUnionId]:openModel.SessionKey------" + openModel.SessionKey); if (string.IsNullOrEmpty(openModel?.SessionKey)) { rvm.Success = false; rvm.Msg = "没有获取到SessionKey"; rvm.Result = null; LoggerHelper.WriteLogInfo("[GetUnionId]:错误------没有获取到SessionKey"); return(rvm); } var encryptedData = wxUserInfoRequestModel.encryptedData; var iv = wxUserInfoRequestModel.iv; var openid = openModel.OpenId; var userinfo = new DecodedUserInfoModel() { openId = openid }; //如果用户授权获取信息 if (!string.IsNullOrEmpty(encryptedData) && !string.IsNullOrEmpty(iv)) { userinfo = EncryptHelper.DecodeUserInfoBySessionKey(openModel.SessionKey, wxUserInfoRequestModel.encryptedData, wxUserInfoRequestModel.iv); if (string.IsNullOrEmpty(userinfo?.unionId) || string.IsNullOrEmpty(userinfo?.openId)) { LoggerHelper.WriteLogInfo("[GetUnionId]:错误------unionId无效或openid无效"); rvm.Success = false; rvm.Msg = "unionId无效或openid无效"; rvm.Result = null; return(rvm); } } WxUserModel user = new WxUserModel(); if (!string.IsNullOrEmpty(userinfo.unionId)) { user = _rep.FirstOrDefault <WxUserModel>(s => s.IsDeleted != 1 && s.UnionId == userinfo.unionId); } else { user = _rep.FirstOrDefault <WxUserModel>(s => s.IsDeleted != 1 && s.OpenId == openid); } #region 文库验证 bool FKLogin = false; //是否显示FK登录页 var isSalerPerson = 0; //是否销售 var isReg = 0; //是否注册 var isVerify = 0; var edaUrl = ConfigurationManager.AppSettings["WKUrl"] ?? ""; //指定 1035 if (wxUserInfoRequestModel.WxSceneId.Equals("1035") && wxUserInfoRequestModel.SourceAppId.Equals("wxeeefb3bc11af968d")) { var edaResult = HttpUtils.HttpGet(edaUrl + $"?Method=LoginCheck&unionid={userinfo.unionId}", ""); //用户UnionID 访问文库接口判断是否有效 if (edaResult.Equals("0")) { //设置此人为销售 isSalerPerson = 1; isReg = 1; isVerify = 1; FKLogin = false; } else { isSalerPerson = 0; isReg = 0; isVerify = 0; FKLogin = true; //展示废卡登录页面 } } #endregion if (user == null) { user = new WxUserModel() { Id = Guid.NewGuid().ToString(), UserName = "", OpenId = userinfo.openId, //UnionId = openModel.UnionId, //目前先使用OpenId,不知道为什么没获取到我的UnionId UnionId = userinfo.unionId, WxCity = userinfo.city, WxName = userinfo.nickName, WxCountry = userinfo.country, WxGender = userinfo.gender.ToString(), WxPicture = userinfo.avatarUrl, WxProvince = userinfo.province, //CreateTime = DateTime.Now, IsDeleted = 0, IsEnabled = 0, IsVerify = isVerify, IsCompleteRegister = isReg, IsSalesPerson = isSalerPerson, CreateTime = DateTime.Now, SourceAppId = wxUserInfoRequestModel.SourceAppId, SourceType = wxUserInfoRequestModel.SourceType, WxSceneId = wxUserInfoRequestModel.WxSceneId, }; _rep.Insert(user); _rep.SaveChanges(); } else { //如果是销售 从费卡文库重新验证 /* * if ((user.IsSalesPerson ?? 0) == 1) * { * var edaResult = HttpUtils.HttpGet(edaUrl + $"?Method=LoginCheck&unionid={userinfo.unionId}", ""); * //用户UnionID 访问文库接口判断是否有效 * if (edaResult.Equals("0")) * { * user.IsSalesPerson = 1; * user.IsCompleteRegister = 1; * user.IsVerify = 1; * FKLogin = false; * } * else * { * user.IsSalesPerson = 0; * user.IsCompleteRegister = 0; * user.IsVerify = 0; * FKLogin = true; * } * * } */ user.OpenId = userinfo.openId ?? user.OpenId; user.UnionId = userinfo.unionId ?? user.UnionId; user.WxCity = userinfo.city ?? user.WxCity; user.WxName = userinfo.nickName ?? user.WxName; user.WxCountry = userinfo.country ?? user.WxCountry; user.WxGender = userinfo.gender.ToString() ?? user.WxGender; user.WxPicture = userinfo.avatarUrl ?? user.WxPicture; user.WxProvince = userinfo.province ?? user.WxProvince; user.UpdateTime = DateTime.Now; _rep.Update(user); _rep.SaveChanges(); } _wxRegisterService.CacheWxUser(user); var postStr = $@"username={user.Id}&grant_type=password"; var authPath = $@"{_host}/auth/token/Wx"; //sysToken = JsonConvert.DeserializeObject<SysToken>(HttpUtils.HttpPost(authPath, postStr, "application/x-www-form-urlencoded")); SysToken sysToken = HttpUtils.PostResponse <SysToken>(authPath, postStr, "application/x-www-form-urlencoded"); var issignup = 0; if (!string.IsNullOrEmpty(encryptedData) && !string.IsNullOrEmpty(iv)) { //判断该用户是否完成签名 issignup = _rep.Table <RegisterModel>().Where(s => s.WxUserId == user.Id).Count() > 0 ? 1 : 0; } #region 判断用户是否扫描了二维码 if (wxUserInfoRequestModel.SourceAppId != null) { //向访问记录表推送数据 QRcodeRecord addRecord = new QRcodeRecord(); addRecord.Id = Guid.NewGuid().ToString(); addRecord.AppId = wxUserInfoRequestModel.SourceAppId; addRecord.CreateTime = DateTime.Now; addRecord.CreateUser = user.Id; addRecord.UnionId = userinfo.unionId; addRecord.SourceType = wxUserInfoRequestModel.SourceType; addRecord.WxSceneId = wxUserInfoRequestModel.WxSceneId; //判断用户是否完成了注册 addRecord.Isregistered = issignup == 0 ? 0 : 1; _rep.Insert(addRecord); _rep.SaveChanges(); } #endregion #region 签到进入小程序记录 防止总总原因进入签到失败 if (!string.IsNullOrEmpty(wxUserInfoRequestModel?.ActivityID)) { try { var edaCheckInRecord = new EdaCheckInRecord() { Id = Guid.NewGuid().ToString(), ActivityID = wxUserInfoRequestModel.ActivityID, AppId = wxUserInfoRequestModel.SourceAppId, UnionId = userinfo.unionId, OpenId = userinfo.openId, //UserName = workUser?.WxUser?.UserName, WxName = userinfo.nickName, VisitTime = DateTime.Now }; _rep.Insert(edaCheckInRecord); _rep.SaveChanges(); } catch (Exception) { LoggerHelper.WriteLogInfo("防止总总原因进入签到-----失败"); } } #endregion rvm.Success = true; rvm.Msg = "success"; rvm.Result = new { openModel = openModel, sysToken = sysToken, user = user, issignup = issignup, // isSalerPerson=isSalerPerson, FKLogin = FKLogin }; stopwatch.Stop();//结束 rvm.ResponseTime = stopwatch.Elapsed.TotalMilliseconds; return(rvm); }
public IHttpActionResult IsQualified(WxUserModel wxUserModel) { var ret = _wxRegisterService.IsQualified(wxUserModel.UserName); return(Ok(ret)); }
/// <summary> /// 批量清洗医生 /// </summary> /// <param name="DoctorInfo"></param> /// <returns></returns> public ReturnValueModel AddUpdateDoctorInfo(List <YXDoctorViewModel> DoctorInfo) { LoggerHelper.WriteLogInfo($"---- AddUpdateDoctorInfo Begin 批量清洗医生 ---------------"); LoggerHelper.WriteLogInfo("List<YXDoctorViewModel> DoctorInfo: " + Newtonsoft.Json.JsonConvert.SerializeObject(DoctorInfo)); ReturnValueModel rvm = new ReturnValueModel(); List <WxUserModel> list = new List <WxUserModel>(); if (DoctorInfo == null || DoctorInfo.Count == 0) { rvm.Msg = "没有医生数据需要更新。"; rvm.Success = false; return(rvm); } foreach (var item in DoctorInfo) { var doctor = _rep.FirstOrDefault <WxUserModel>(s => s.Id == item.Id); if (doctor != null) { //item.Id = items.Id; string status = (item.status ?? "").Trim().ToLower(); switch (status) { case "active": doctor.IsVerify = 1; //已认证 break; case "inactive": if (doctor.IsVerify == 4) //原来是申诉中 { doctor.IsVerify = 6; //申诉拒绝 } else { doctor.IsVerify = 3; //认证失败 } break; case "undetermined": doctor.IsVerify = 2; //不确定 break; default: break; } //通过云势已认证用户 if (status == "active") { doctor.UserName = item.name; doctor.HospitalName = item.yunshi_hospital_name; //doctor.DepartmentName = item.standard_department; doctor.Title = item.job_title; doctor.WxGender = YsToGender(item.gender); doctor.School = item.graduated_school; doctor.Province = item.yunshi_province; doctor.City = item.yunshi_city; } doctor.hospital_code = item.hospital_code; doctor.hospital_name = item.hospital_name; doctor.doctor_code = item.doctor_code; doctor.doctor_name = item.doctor_name; doctor.department = item.department; doctor.job_title_SFE = item.job_title_SFE; doctor.position_SFE = item.position_SFE; //doctor.is_infor_customer = item.is_infor_customer == "是" ? true : false; doctor.is_infor_customer = string.Equals(item.is_infor_customer, "Y", StringComparison.OrdinalIgnoreCase) ? true : false; doctor.serial_number = item.serial_number; doctor.status = item.status; doctor.reason = item.reason; doctor.unique_doctor_id = item.unique_doctor_id; doctor.yunshi_hospital_id = item.yunshi_hospital_id; doctor.yunshi_hospital_name = item.yunshi_hospital_name; doctor.yunshi_doctor_id = item.yunshi_doctor_id; doctor.name = item.name; doctor.standard_department = item.standard_department; doctor.profession = item.profession; doctor.gender = item.gender; doctor.job_title = item.job_title; doctor.position = item.position; doctor.academic_title = item.academic_title; doctor.type = item.type; doctor.certificate_type = item.certificate_type; doctor.certificate_code = item.certificate_code; doctor.education = item.education; doctor.graduated_school = item.graduated_school; doctor.graduation_time = item.graduation_time; doctor.specialty = item.specialty; doctor.intro = item.intro; doctor.department_phone = item.department_phone; doctor.modifier = item.modifier; doctor.change_time = item.change_time; doctor.data_update_type = item.data_update_type; doctor.yunshi_province = item.yunshi_province; doctor.yunshi_city = item.yunshi_city; if (item.change_time != null) { doctor.change_time = item.change_time; } else { doctor.change_time = DateTime.Now; } doctor.data_update_type = item.data_update_type; _rep.Update(doctor); _rep.SaveChanges(); LoggerHelper.WriteLogInfo($"---- AddUpdateDoctorInfo Update Begin 批量清洗医生 ---------------"); LoggerHelper.WriteLogInfo($"[doctor.Id]:{doctor?.Id}\n"); LoggerHelper.WriteLogInfo($"[doctor.UnionId]:{ doctor?.UnionId }\n"); LoggerHelper.WriteLogInfo($"[doctor.IsVerify]:{ doctor?.IsVerify }\n"); LoggerHelper.WriteLogInfo($"---- AddUpdateDoctorInfo Update End ----------------------------"); } else { doctor = new WxUserModel() { Id = Guid.NewGuid().ToString(), IsVerify = 0, IsCompleteRegister = 0, IsDeleted = 0, IsEnabled = 0, hospital_code = item.hospital_code, hospital_name = item.hospital_name, doctor_code = item.doctor_code, doctor_name = item.doctor_name, department = item.department, job_title_SFE = item.job_title_SFE, position_SFE = item.position_SFE, //is_infor_customer = item.is_infor_customer == "是" ? true : false, is_infor_customer = string.Equals(item.is_infor_customer, "Y", StringComparison.OrdinalIgnoreCase) ? true : false, serial_number = item.serial_number, status = item.status, reason = item.reason, unique_doctor_id = item.unique_doctor_id, yunshi_hospital_id = item.yunshi_hospital_id, yunshi_hospital_name = item.yunshi_hospital_name, yunshi_doctor_id = item.yunshi_doctor_id, name = item.name, standard_department = item.standard_department, profession = item.profession, gender = item.gender, job_title = item.job_title, position = item.position, academic_title = item.academic_title, type = item.type, certificate_type = item.certificate_type, certificate_code = item.certificate_code, education = item.education, graduated_school = item.graduated_school, graduation_time = item.graduation_time, specialty = item.specialty, intro = item.intro, department_phone = item.department_phone, modifier = item.modifier, change_time = item.change_time, data_update_type = item.data_update_type, CreateTime = DateTime.Now }; string status = (item.status ?? "").Trim().ToLower(); switch (status) { case "active": doctor.IsVerify = 1; //已认证 break; case "inactive": if (doctor.IsVerify == 4) //原来是申诉中 { doctor.IsVerify = 6; //申诉拒绝 } else { doctor.IsVerify = 3; //认证失败 } break; case "undetermined": doctor.IsVerify = 2; //不确定 break; default: break; } if (status == "active") { doctor.UserName = item.name; doctor.HospitalName = item.yunshi_hospital_name; //doctor.DepartmentName = item.standard_department; doctor.Title = item.job_title; doctor.WxGender = YsToGender(item.gender); doctor.School = item.graduated_school; } list.Add(doctor); LoggerHelper.WriteLogInfo($"---- AddUpdateDoctorInfo Add Begin 批量清洗医生 ---------------"); LoggerHelper.WriteLogInfo($"[doctor.Id]:{doctor?.Id}\n"); LoggerHelper.WriteLogInfo($"[doctor.UnionId]:{ doctor?.UnionId }\n"); LoggerHelper.WriteLogInfo($"[doctor.IsVerify]:{ doctor?.IsVerify }\n"); LoggerHelper.WriteLogInfo($"---- AddUpdateDoctorInfo Add End ----------------------------"); } } if (list.Count() > 0) { _rep.BulkCopyInsert(list, "DoctorModel"); } _rep.SaveChanges(); rvm.Msg = "success"; rvm.Success = true; rvm.Result = new { //DoctorInfo = DoctorInfo msg = "批量更新医生成功!" }; LoggerHelper.WriteLogInfo($"---- AddUpdateDoctorInfo End 批量清洗医生 ---------------"); return(rvm); }