No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

789 líneas
30 KiB

  1. using Learun.Application.Base.SystemModule;
  2. using Learun.Application.Organization;
  3. using Learun.Application.TwoDevelopment.EducationalAdministration;
  4. using Learun.Cache.Base;
  5. using Learun.Cache.Factory;
  6. using Learun.Util;
  7. using Learun.Util.Operat;
  8. using Nancy;
  9. using Quanjiang.DigitalScholl.SendSms;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Configuration;
  13. using System.Linq;
  14. namespace Learun.Application.WebApi
  15. {
  16. /// <summary>
  17. /// 版 本 Learun-ADMS V7.0.0 数字化智慧校园
  18. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  19. /// 创建人:数字化智慧校园-框架开发组
  20. /// 日 期:2017.05.12
  21. /// 描 述:用户信息
  22. /// </summary>
  23. public class UserApi : BaseApi
  24. {
  25. /// <summary>
  26. /// 注册接口
  27. /// </summary>
  28. public UserApi()
  29. : base("/learun/adms/user")
  30. {
  31. Post["/login"] = Login;
  32. Post["/logincodeverify"] = LoginCodeVerify;
  33. Post["/sendcode"] = Sendcode;
  34. Post["/modifypw"] = ModifyPassword;
  35. Post["/modifypwiden"] = ModifyPasswordiden;
  36. Post["/unbundWeiXin"] = DoUnbundWeiXin;
  37. Post["/loginbyIdCard"] = LoginByIdCard;
  38. Post["/updateMobile"] = UpdateMobile;
  39. Post["/loginByMobile"] = LoginByMobile;
  40. Get["/info"] = Info;
  41. Get["/map"] = GetMap;
  42. Get["/img"] = GetImg;
  43. Get["/imgfordc"] = GetImgForDC;
  44. Get["/saveMap"] = GetSaveClassMap;
  45. }
  46. private UserIBLL userIBLL = new UserBLL();
  47. private PostIBLL postIBLL = new PostBLL();
  48. private RoleIBLL roleIBLL = new RoleBLL();
  49. private StuInfoBasicIBLL stuInfoBasicIBLL = new StuInfoBasicBLL();
  50. CdMajorIBLL majorIbll = new CdMajorBLL();
  51. private readonly ISms aliyunSms = new AliyunSms();
  52. private ICache redisCache = CacheFactory.CaChe();
  53. /// <summary>
  54. /// 短信验证码校验
  55. /// </summary>
  56. /// <param name="_"></param>
  57. /// <returns></returns>
  58. private Response LoginCodeVerify(dynamic _)
  59. {
  60. MobileVerify mobileVerify = this.GetReqData<MobileVerify>();
  61. if (string.IsNullOrEmpty(mobileVerify.codeType))
  62. {
  63. return Fail("未指定短信类型。");
  64. }
  65. if (string.IsNullOrEmpty(mobileVerify.mobile))
  66. {
  67. return Fail("手机号不能为空。");
  68. }
  69. var code = redisCache.Read<string>("sendcodeinapp_" + mobileVerify.codeType + "_" + mobileVerify.mobile, CacheId.sms);
  70. if (!string.IsNullOrEmpty(code) && code == mobileVerify.verifycode)
  71. {
  72. return Success("验证成功。");
  73. }
  74. else
  75. {
  76. return Fail("验证失败,验证码错误或已失效。");
  77. }
  78. }
  79. /// <summary>
  80. /// 发送短信验证码
  81. /// </summary>
  82. /// <param name="_"></param>
  83. /// <returns></returns>
  84. private Response Sendcode(dynamic _)
  85. {
  86. LoginModel loginModel = this.GetReqData<LoginModel>();
  87. if (string.IsNullOrEmpty(loginModel.codeType))
  88. {
  89. return Fail("未指定短信类型。");
  90. }
  91. UserEntity userEntity = null;
  92. userEntity = userIBLL.GetEntityByUserId(userInfo.userId);
  93. if (userEntity == null)
  94. {
  95. return Fail("用户不存在!");
  96. }
  97. if (loginModel.codeType == "unbindwx")
  98. {
  99. if (string.IsNullOrEmpty(userEntity.F_Mobile))
  100. {
  101. return Fail("用户手机号不存在!");
  102. }
  103. loginModel.username = userEntity.F_Mobile;
  104. }
  105. if (string.IsNullOrEmpty(loginModel.username))
  106. {
  107. return Fail("手机号不能为空。");
  108. }
  109. if (!CommonHelper.IsValidMobile(loginModel.username))
  110. {
  111. return Fail("手机号格式不正确!");
  112. }
  113. var listStr = new List<string>();
  114. var result = aliyunSms.SendSmsToSingle(loginModel.username, SmsType.LoginBind, listStr);
  115. if (result.Result.code == "OK")
  116. {
  117. redisCache.Write<string>("sendcodeinapp_" + loginModel.codeType + "_" + loginModel.username, result.Result.randomNum, new TimeSpan(0, 5, 0), CacheId.sms);
  118. //日志
  119. LogEntity logEntity = new LogEntity();
  120. logEntity.F_CategoryId = 3;
  121. logEntity.F_SourceObjectId = loginModel.codeType;
  122. logEntity.F_OperateTypeId = "sms";
  123. logEntity.F_OperateType = "sms";
  124. logEntity.F_OperateAccount = "system";
  125. logEntity.F_ExecuteResult = 200;
  126. logEntity.F_ExecuteResultJson = "短信发送成功:" + result.Result.message;
  127. logEntity.F_Description = "短信发送:" + loginModel.username + " 验证码:" + result.Result.randomNum;
  128. logEntity.WriteLog();
  129. return Success("短信发送成功:" + result.Result.message);
  130. }
  131. else
  132. {
  133. LogEntity logEntity = new LogEntity();
  134. logEntity.F_CategoryId = 4;
  135. logEntity.F_SourceObjectId = loginModel.codeType;
  136. logEntity.F_OperateTypeId = "sms";
  137. logEntity.F_OperateType = "sms";
  138. logEntity.F_OperateAccount = "system";
  139. logEntity.F_ExecuteResult = 400;
  140. logEntity.F_ExecuteResultJson = "短信发送失败:" + result.Result.message + result.Result.errorType;
  141. logEntity.F_Description = "短信发送:" + loginModel.username;
  142. logEntity.WriteLog();
  143. return Fail("短信发送失败:" + result.Result.message + result.Result.errorType);
  144. }
  145. }
  146. /// <summary>
  147. /// 登录接口
  148. /// </summary>
  149. /// <param name="_"></param>
  150. /// <returns></returns>
  151. private Response Login(dynamic _)
  152. {
  153. LoginModel loginModel = this.GetReqData<LoginModel>();
  154. #region 内部账户验证
  155. UserEntity userEntity = userIBLL.CheckLogin(loginModel.username, loginModel.password);
  156. #region 写入日志
  157. LogEntity logEntity = new LogEntity();
  158. logEntity.F_CategoryId = 1;
  159. logEntity.F_OperateTypeId = ((int)OperationType.Login).ToString();
  160. logEntity.F_OperateType = EnumAttribute.GetDescription(OperationType.Login);
  161. logEntity.F_OperateAccount = loginModel.username + "(" + userEntity.F_RealName + ")";
  162. logEntity.F_OperateUserId = !string.IsNullOrEmpty(userEntity.F_UserId) ? userEntity.F_UserId : loginModel.username;
  163. logEntity.F_Module = Config.GetValue("SoftName");
  164. logEntity.F_Description = "移动端";
  165. #endregion
  166. if (!userEntity.LoginOk)//登录失败
  167. {
  168. //写入日志
  169. logEntity.F_ExecuteResult = 0;
  170. logEntity.F_ExecuteResultJson = "登录失败:" + userEntity.LoginMsg;
  171. logEntity.WriteLog();
  172. return Fail(userEntity.LoginMsg);
  173. }
  174. else
  175. {
  176. //记录已登录标记
  177. userIBLL.UpdateHaveLogMark(userEntity.F_UserId);
  178. //记录ip
  179. userIBLL.UpdateIp(GetIP(), userEntity.F_UserId);
  180. string token = OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_App", this.loginMark, false);//写入缓存信息
  181. //写入日志
  182. logEntity.F_ExecuteResult = 1;
  183. logEntity.F_ExecuteResultJson = "登录成功";
  184. logEntity.WriteLog();
  185. //保存用户设备号
  186. userIBLL.UpdateDeviceId(userEntity.F_UserId, loginModel.deviceid);
  187. OperatorResult res = OperatorHelper.Instance.IsOnLine(token, this.loginMark);
  188. res.userInfo.password = null;
  189. res.userInfo.secretkey = null;
  190. var studententity = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(userEntity.F_Account);
  191. if (studententity != null)
  192. {
  193. res.userInfo.grade = studententity.Grade;
  194. var majorinfo = majorIbll.GetCdMajorEntityByMajorNo(studententity.MajorNo);
  195. if (majorinfo != null)
  196. {
  197. res.userInfo.majorno = majorinfo.ID ?? "";
  198. }
  199. }
  200. //是否强密码验证
  201. bool pwd = false;
  202. if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["verifypwd"]) && ConfigurationManager.AppSettings["verifypwd"] == "true" && loginModel.up == false)
  203. {
  204. pwd = true;
  205. }
  206. var jsonData = new
  207. {
  208. baseinfo = res.userInfo,
  209. post = postIBLL.GetListByPostIds(res.userInfo.postIds),
  210. role = roleIBLL.GetListByRoleIds(res.userInfo.roleIds),
  211. pwd = pwd
  212. };
  213. return Success(jsonData);
  214. }
  215. #endregion
  216. }
  217. /// <summary>
  218. /// 身份验证-登录接口
  219. /// </summary>
  220. /// <param name="_"></param>
  221. /// <returns></returns>
  222. private Response LoginByIdCard(dynamic _)
  223. {
  224. LoginModel loginModel = this.GetReqData<LoginModel>();
  225. #region 内部账户验证
  226. UserEntity userEntity = userIBLL.CheckLoginByIdCard(loginModel.username, loginModel.password);
  227. #region 写入日志
  228. LogEntity logEntity = new LogEntity();
  229. logEntity.F_CategoryId = 1;
  230. logEntity.F_OperateTypeId = ((int)OperationType.Login).ToString();
  231. logEntity.F_OperateType = EnumAttribute.GetDescription(OperationType.Login);
  232. logEntity.F_OperateAccount = loginModel.username + "(" + userEntity.F_RealName + ")";
  233. logEntity.F_OperateUserId = !string.IsNullOrEmpty(userEntity.F_UserId) ? userEntity.F_UserId : loginModel.username;
  234. logEntity.F_Module = Config.GetValue("SoftName");
  235. logEntity.F_Description = "移动端";
  236. #endregion
  237. if (!userEntity.LoginOk)//登录失败
  238. {
  239. //写入日志
  240. logEntity.F_ExecuteResult = 0;
  241. logEntity.F_ExecuteResultJson = "登录失败:" + userEntity.LoginMsg;
  242. logEntity.WriteLog();
  243. return Fail(userEntity.LoginMsg);
  244. }
  245. else
  246. {
  247. //新增新生判断
  248. var stuinfobasic = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(userEntity.F_EnCode);
  249. if (stuinfobasic != null && stuinfobasic.Grade != "22")
  250. {
  251. userEntity.LoginMsg = "只有新生支持身份证方式登录";
  252. return Fail(userEntity.LoginMsg);
  253. }
  254. //记录已登录标记
  255. userIBLL.UpdateHaveLogMark(userEntity.F_UserId);
  256. //记录ip
  257. userIBLL.UpdateIp(GetIP(), userEntity.F_UserId);
  258. string token = OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_App", this.loginMark, false);//写入缓存信息
  259. //写入日志
  260. logEntity.F_ExecuteResult = 1;
  261. logEntity.F_ExecuteResultJson = "登录成功";
  262. logEntity.WriteLog();
  263. //保存用户设备号
  264. userIBLL.UpdateDeviceId(userEntity.F_UserId, loginModel.deviceid);
  265. OperatorResult res = OperatorHelper.Instance.IsOnLine(token, this.loginMark);
  266. res.userInfo.password = null;
  267. res.userInfo.secretkey = null;
  268. var studententity = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(userEntity.F_Account);
  269. if (studententity != null)
  270. {
  271. res.userInfo.grade = studententity.Grade;
  272. var majorinfo = majorIbll.GetCdMajorEntityByMajorNo(studententity.MajorNo);
  273. if (majorinfo != null)
  274. {
  275. res.userInfo.majorno = majorinfo.ID ?? "";
  276. }
  277. }
  278. //是否强密码验证
  279. bool pwd = false;
  280. if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["verifypwd"]) && ConfigurationManager.AppSettings["verifypwd"] == "true" && loginModel.up == false)
  281. {
  282. pwd = true;
  283. }
  284. var jsonData = new
  285. {
  286. baseinfo = res.userInfo,
  287. post = postIBLL.GetListByPostIds(res.userInfo.postIds),
  288. role = roleIBLL.GetListByRoleIds(res.userInfo.roleIds),
  289. pwd = pwd
  290. };
  291. return Success(jsonData);
  292. }
  293. #endregion
  294. }
  295. /// <summary>
  296. /// 登录接口-首次登录-手机号
  297. /// </summary>
  298. /// <param name="_"></param>
  299. /// <returns></returns>
  300. private Response LoginByMobile(dynamic _)
  301. {
  302. LoginModel loginModel = this.GetReqData<LoginModel>();
  303. //短信验证码校验
  304. if (string.IsNullOrEmpty(loginModel.codeType))
  305. {
  306. return Fail("未指定短信类型。");
  307. }
  308. if (string.IsNullOrEmpty(loginModel.username))
  309. {
  310. return Fail("手机号不能为空。");
  311. }
  312. var code = redisCache.Read<string>("sendcodeinapp_" + loginModel.codeType + "_" + loginModel.username, CacheId.sms);
  313. if (!string.IsNullOrEmpty(code) && code == loginModel.verifycode)
  314. {
  315. //return Success("验证成功。");
  316. #region 内部账户验证
  317. UserEntity userEntity = userIBLL.GetEntityByMobile(loginModel.username);
  318. if (userEntity == null)
  319. {
  320. return Fail("用户不存在!");
  321. }
  322. if (userEntity.F_EnabledMark != 1)
  323. {
  324. return Fail("账户被系统锁定,请联系管理员!");
  325. }
  326. if (userEntity.F_HaveLogMark == true)
  327. {
  328. return Fail("当前用户非首次登录,请使用账号密码进行登录!");
  329. }
  330. userEntity.LoginOk = true;
  331. #region 写入日志
  332. LogEntity logEntity = new LogEntity();
  333. logEntity.F_CategoryId = 1;
  334. logEntity.F_OperateTypeId = ((int)OperationType.Login).ToString();
  335. logEntity.F_OperateType = EnumAttribute.GetDescription(OperationType.Login);
  336. logEntity.F_OperateAccount = loginModel.username + "(" + userEntity.F_RealName + ")";
  337. logEntity.F_OperateUserId = !string.IsNullOrEmpty(userEntity.F_UserId) ? userEntity.F_UserId : loginModel.username;
  338. logEntity.F_Module = Config.GetValue("SoftName");
  339. logEntity.F_Description = "移动端-首次登录";
  340. #endregion
  341. if (!userEntity.LoginOk)//登录失败
  342. {
  343. //写入日志
  344. logEntity.F_ExecuteResult = 0;
  345. logEntity.F_ExecuteResultJson = "登录失败:" + userEntity.LoginMsg;
  346. logEntity.WriteLog();
  347. return Fail(userEntity.LoginMsg);
  348. }
  349. else
  350. {
  351. //记录已登录标记
  352. userIBLL.UpdateHaveLogMark(userEntity.F_UserId);
  353. //记录ip
  354. userIBLL.UpdateIp(GetIP(), userEntity.F_UserId);
  355. string token = OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_App", this.loginMark, false);//写入缓存信息
  356. //写入日志
  357. logEntity.F_ExecuteResult = 1;
  358. logEntity.F_ExecuteResultJson = "登录成功";
  359. logEntity.WriteLog();
  360. //保存用户设备号
  361. userIBLL.UpdateDeviceId(userEntity.F_UserId, loginModel.deviceid);
  362. OperatorResult res = OperatorHelper.Instance.IsOnLine(token, this.loginMark);
  363. res.userInfo.password = null;
  364. res.userInfo.secretkey = null;
  365. var studententity = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(userEntity.F_Account);
  366. if (studententity != null)
  367. {
  368. res.userInfo.grade = studententity.Grade;
  369. var majorinfo = majorIbll.GetCdMajorEntityByMajorNo(studententity.MajorNo);
  370. if (majorinfo != null)
  371. {
  372. res.userInfo.majorno = majorinfo.ID ?? "";
  373. }
  374. }
  375. var jsonData = new
  376. {
  377. baseinfo = res.userInfo,
  378. post = postIBLL.GetListByPostIds(res.userInfo.postIds),
  379. role = roleIBLL.GetListByRoleIds(res.userInfo.roleIds),
  380. pwd = true
  381. };
  382. return Success(jsonData);
  383. }
  384. #endregion
  385. }
  386. else
  387. {
  388. return Fail("验证失败,验证码错误或已失效。");
  389. }
  390. }
  391. /// <summary>
  392. /// 获取用户信息
  393. /// </summary>
  394. /// <param name="_"></param>
  395. /// <returns></returns>
  396. private Response Info(dynamic _)
  397. {
  398. var data = userInfo;
  399. data.password = null;
  400. data.secretkey = null;
  401. var jsonData = new
  402. {
  403. baseinfo = data,
  404. post = postIBLL.GetListByPostIds(data.postIds),
  405. role = roleIBLL.GetListByRoleIds(data.roleIds)
  406. };
  407. return Success(jsonData);
  408. }
  409. /// <summary>
  410. /// 修改密码
  411. /// </summary>
  412. /// <param name="_"></param>
  413. /// <returns></returns>
  414. private Response ModifyPassword(dynamic _)
  415. {
  416. ModifyModel modifyModel = this.GetReqData<ModifyModel>();
  417. if (userInfo.isSystem)
  418. {
  419. return Fail("当前账户不能修改密码");
  420. }
  421. else
  422. {
  423. bool res = userIBLL.RevisePassword(modifyModel.newpassword, modifyModel.oldpassword);
  424. if (!res)
  425. {
  426. return Fail("原密码错误,请重新输入");
  427. }
  428. else
  429. {
  430. return Success("密码修改成功");
  431. }
  432. }
  433. }
  434. public Response ModifyPasswordiden(dynamic _)
  435. {
  436. ModifyModel modifyModel = this.GetReqData<ModifyModel>();
  437. if (userInfo.isSystem)
  438. {
  439. return Fail("当前账户不能修改密码");
  440. }
  441. else
  442. {
  443. bool res = userIBLL.RevisePasswordiden(modifyModel.newpassword, modifyModel.oldpassword);
  444. if (!res)
  445. {
  446. return Fail("原密码错误,请重新输入");
  447. }
  448. else
  449. {
  450. return Success("密码修改成功");
  451. }
  452. }
  453. }
  454. /// <summary>
  455. /// 解绑微信
  456. /// </summary>
  457. /// <param name="_"></param>
  458. /// <returns></returns>
  459. private Response DoUnbundWeiXin(dynamic _)
  460. {
  461. MobileVerify mobileVerify = this.GetReqData<MobileVerify>();
  462. if (string.IsNullOrEmpty(mobileVerify.codeType))
  463. {
  464. return Fail("未指定短信类型。");
  465. }
  466. if (mobileVerify.codeType == "unbindwx")
  467. {
  468. mobileVerify.mobile = userIBLL.GetEntityByUserId(userInfo.userId)?.F_Mobile;
  469. }
  470. if (string.IsNullOrEmpty(mobileVerify.mobile))
  471. {
  472. return Fail("手机号不能为空。");
  473. }
  474. var code = redisCache.Read<string>("sendcodeinapp_" + mobileVerify.codeType + "_" + mobileVerify.mobile, CacheId.sms);
  475. if (!string.IsNullOrEmpty(code) && code == mobileVerify.verifycode)
  476. {
  477. //return Success("验证成功。");
  478. userIBLL.DoUnbundWeiXin(userInfo.userId);
  479. return Success("解绑成功");
  480. }
  481. else
  482. {
  483. return Fail("验证失败,验证码错误或已失效。");
  484. }
  485. }
  486. /// <summary>
  487. /// 修改手机号
  488. /// </summary>
  489. /// <param name="_"></param>
  490. /// <returns></returns>
  491. private Response UpdateMobile(dynamic _)
  492. {
  493. MobileVerify mobileVerify = this.GetReqData<MobileVerify>();
  494. if (string.IsNullOrEmpty(mobileVerify.codeType))
  495. {
  496. return Fail("未指定短信类型。");
  497. }
  498. if (string.IsNullOrEmpty(mobileVerify.mobile))
  499. {
  500. return Fail("手机号不能为空。");
  501. }
  502. var code = redisCache.Read<string>("sendcodeinapp_" + mobileVerify.codeType + "_" + mobileVerify.mobile, CacheId.sms);
  503. if (!string.IsNullOrEmpty(code) && code == mobileVerify.verifycode)
  504. {
  505. //return Success("验证成功。");
  506. userIBLL.UpdateMobile(userInfo.userId, mobileVerify.mobile);
  507. return Success("修改成功");
  508. }
  509. else
  510. {
  511. return Fail("验证失败,验证码错误或已失效。");
  512. }
  513. }
  514. /// <summary>
  515. /// 获取所有员工账号列表
  516. /// </summary>
  517. /// <param name="_"></param>
  518. /// <returns></returns>
  519. private Response GetList(dynamic _)
  520. {
  521. var data = userInfo;
  522. data.password = null;
  523. data.secretkey = null;
  524. var jsonData = new
  525. {
  526. baseinfo = data,
  527. post = postIBLL.GetListByPostIds(data.postIds),
  528. role = roleIBLL.GetListByRoleIds(data.roleIds)
  529. };
  530. return Success(jsonData);
  531. }
  532. /// <summary>
  533. /// 获取用户映射表
  534. /// </summary>
  535. /// <param name="_"></param>
  536. /// <returns></returns>
  537. public Response GetMap(dynamic _)
  538. {
  539. string ver = this.GetReqData();// 获取模板请求数据
  540. var data = userIBLL.GetModelMap();
  541. string md5 = Md5Helper.Encrypt(data.ToJson(), 32);
  542. if (md5 == ver)
  543. {
  544. return Success("no update");
  545. }
  546. else
  547. {
  548. var jsondata = new
  549. {
  550. data = data,
  551. ver = md5
  552. };
  553. return Success(jsondata);
  554. }
  555. }
  556. public Response GetSaveClassMap(dynamic _)
  557. {
  558. string account = this.GetReqData<UserAccount>().account;
  559. var data = userIBLL.GetSaveClassMap();
  560. var students = stuInfoBasicIBLL.GetSaveClassStudents(account);
  561. data = data.Where(a => students.Contains(a.F_Account) && a.F_Account != account).ToList();
  562. var dic = new Dictionary<string, UserModel>();
  563. foreach (var item in data)
  564. {
  565. UserModel model = new UserModel()
  566. {
  567. companyId = item.F_CompanyId,
  568. departmentId = item.F_DepartmentId,
  569. name = item.F_RealName,
  570. id = item.F_UserId,
  571. };
  572. string img = "";
  573. if (!string.IsNullOrEmpty(item.F_HeadIcon))
  574. {
  575. string fileHeadImg = Config.GetValue("fileHeadImg");
  576. string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, item.F_UserId, item.F_HeadIcon);
  577. if (DirFileHelper.IsExistFile(fileImg))
  578. {
  579. img = item.F_HeadIcon;
  580. }
  581. }
  582. if (string.IsNullOrEmpty(img))
  583. {
  584. if (item.F_Gender == 0)
  585. {
  586. img = "0";
  587. }
  588. else
  589. {
  590. img = "1";
  591. }
  592. }
  593. model.img = img;
  594. dic.Add(item.F_UserId, model);
  595. }
  596. string md5 = Md5Helper.Encrypt(dic.ToJson(), 32);
  597. var jsondata = new
  598. {
  599. data = dic,
  600. var = md5
  601. };
  602. return Success(jsondata);
  603. }
  604. /// <summary>
  605. /// 获取人员头像图标
  606. /// </summary>
  607. /// <param name="_"></param>
  608. /// <returns></returns>
  609. public Response GetImg(dynamic _)
  610. {
  611. string userId = this.GetReqData();// 获取模板请求数据
  612. userIBLL.GetImg(userId);
  613. return Success("获取成功");
  614. }
  615. /// <summary>
  616. /// 获取人员头像图标
  617. /// </summary>
  618. /// <param name="_"></param>
  619. /// <returns></returns>
  620. public Response GetImgForDC(dynamic _)
  621. {
  622. string userId = this.GetReqData();// 获取模板请求数据
  623. userIBLL.GetImgForDC(userId);
  624. return Success("获取成功");
  625. }
  626. /// <summary>
  627. /// 获取IP
  628. /// </summary>
  629. /// <returns></returns>
  630. private string GetIP()
  631. {
  632. //string ip = string.Empty;
  633. //if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"]))
  634. // ip = Convert.ToString(System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]);
  635. //if (string.IsNullOrEmpty(ip))
  636. // ip = Convert.ToString(System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]);
  637. //return ip;
  638. string userIP = "未获取用户IP";
  639. try
  640. {
  641. if (System.Web.HttpContext.Current == null
  642. || System.Web.HttpContext.Current.Request == null
  643. || System.Web.HttpContext.Current.Request.ServerVariables == null)
  644. {
  645. return "";
  646. }
  647. string CustomerIP = "";
  648. //CDN加速后取到的IP simone 090805
  649. CustomerIP = System.Web.HttpContext.Current.Request.Headers["Cdn-Src-Ip"];
  650. if (!string.IsNullOrEmpty(CustomerIP))
  651. {
  652. return CustomerIP;
  653. }
  654. CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
  655. if (!string.IsNullOrEmpty(CustomerIP))
  656. {
  657. return CustomerIP;
  658. }
  659. if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
  660. {
  661. CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
  662. if (CustomerIP == null)
  663. {
  664. CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
  665. }
  666. }
  667. else
  668. {
  669. CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
  670. }
  671. if (string.Compare(CustomerIP, "unknown", true) == 0 || string.IsNullOrEmpty(CustomerIP))
  672. {
  673. return System.Web.HttpContext.Current.Request.UserHostAddress;
  674. }
  675. return CustomerIP;
  676. }
  677. catch { }
  678. return userIP;
  679. }
  680. }
  681. /// <summary>
  682. /// 登录信息
  683. /// </summary>
  684. public class LoginModel
  685. {
  686. /// <summary>
  687. /// 账号
  688. /// </summary>
  689. public string username { get; set; }
  690. /// <summary>
  691. /// 密码
  692. /// </summary>
  693. public string password { get; set; }
  694. /// <summary>
  695. /// 是否强密码
  696. /// </summary>
  697. public bool up { get; set; }
  698. /// <summary>
  699. /// 设备号
  700. /// </summary>
  701. public string deviceid { get; set; }
  702. public string openid { get; set; }
  703. /// <summary>
  704. /// 发送短信类型:忘记密码forgetpwd,首次登录firstlogin,绑定微信bindwx,解绑微信unbindwx,修改手机号modifymobile,;
  705. /// </summary>
  706. public string codeType { get; set; }
  707. /// <summary>
  708. /// 短信验证码
  709. /// </summary>
  710. public string verifycode { get; set; }
  711. }
  712. /// <summary>
  713. /// 修改密码
  714. /// </summary>
  715. public class ModifyModel
  716. {
  717. public string phone { set; get; }
  718. /// <summary>
  719. /// 新密码
  720. /// </summary>
  721. public string newpassword { get; set; }
  722. /// <summary>
  723. /// 旧密码
  724. /// </summary>
  725. public string oldpassword { get; set; }
  726. }
  727. public class MobileVerify
  728. {
  729. public string mobile { get; set; }
  730. public string verifycode { get; set; }
  731. /// <summary>
  732. /// 发送短信类型
  733. /// </summary>
  734. public string codeType { get; set; }
  735. }
  736. public class UserAccount
  737. {
  738. public string account { get; set; }
  739. }
  740. }