后台服务
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

764 linhas
30 KiB

  1. package com.iformall.controller;
  2. import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
  3. import com.alibaba.fastjson.JSON;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.google.code.kaptcha.Producer;
  6. import com.iformall.annotation.AuthIgnore;
  7. import com.iformall.annotation.TenantIgnore;
  8. import com.iformall.common.ErrorCode;
  9. import com.iformall.common.Result;
  10. import com.iformall.common.ResultData;
  11. import com.iformall.domain.po.*;
  12. import com.iformall.domain.po.sm.InviteCodeInfo;
  13. import com.iformall.enums.*;
  14. import com.iformall.service.*;
  15. import com.iformall.service.cuser.CUserServiceFactory;
  16. import com.iformall.service.sm.InviteCodeInfoService;
  17. import com.iformall.service.sm.InviteCodeService;
  18. import com.iformall.service.sm.UserConsumptionPackageService;
  19. import com.iformall.service.sm.UserCreateVideoNumService;
  20. import com.iformall.utils.Constant;
  21. import com.iformall.utils.IPUtil;
  22. import com.iformall.utils.PasswordHelper;
  23. import com.iformall.utils.RedisCacheUtils;
  24. import io.swagger.annotations.Api;
  25. import io.swagger.annotations.ApiImplicitParam;
  26. import io.swagger.annotations.ApiImplicitParams;
  27. import io.swagger.annotations.ApiOperation;
  28. import org.apache.commons.io.IOUtils;
  29. import org.apache.commons.lang3.StringUtils;
  30. import org.apache.shiro.SecurityUtils;
  31. import org.slf4j.Logger;
  32. import org.slf4j.LoggerFactory;
  33. import org.springframework.beans.factory.annotation.Autowired;
  34. import org.springframework.beans.factory.annotation.Qualifier;
  35. import org.springframework.data.redis.core.RedisTemplate;
  36. import org.springframework.web.bind.annotation.*;
  37. import org.springframework.web.context.request.RequestContextHolder;
  38. import org.springframework.web.context.request.ServletRequestAttributes;
  39. import javax.imageio.ImageIO;
  40. import javax.servlet.ServletOutputStream;
  41. import javax.servlet.http.HttpServletRequest;
  42. import javax.servlet.http.HttpServletResponse;
  43. import java.awt.image.BufferedImage;
  44. import java.io.IOException;
  45. import java.util.Date;
  46. import java.util.HashMap;
  47. import java.util.List;
  48. import java.util.Map;
  49. @RestController
  50. @RequestMapping("/api/user")
  51. @Api(description = "用户登陆相关接口")
  52. public class WxUserGrantController extends BaseController {
  53. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  54. @Autowired
  55. private Producer producer;
  56. @Autowired
  57. @Qualifier("objectCommonRedisTemplate")
  58. RedisTemplate<String, Object> redisTemplate;
  59. @Autowired
  60. private WxCUserBasicInfoService wxCUserBasicInfoService;
  61. @Autowired
  62. private WxMsgValidationcodeService wxMsgValidationcodeService;
  63. @Autowired
  64. WxLevelConfigService wxLevelConfigService;
  65. @Autowired
  66. WxCUserTagsService wxCUserTagsService;
  67. @Autowired
  68. WxAppinfoService wxAppinfoService;
  69. @Autowired
  70. WxAuthorizerInfoService wxAuthorizerInfoService;
  71. @Autowired
  72. WxMerchantService wxMerchantService;
  73. @Autowired
  74. WxCouponOrderService wxCouponOrderService;
  75. @Autowired
  76. WxCreditHistoryService wxCreditHistoryService;
  77. @Autowired
  78. WxMallService mallService;
  79. @Autowired
  80. private QrCodeService qrCodeService;
  81. @Autowired
  82. private UserCreateVideoNumService userCreateVideoNumService;
  83. @Autowired
  84. private InviteCodeService inviteCodeService;
  85. @Autowired
  86. private InviteCodeInfoService inviteCodeInfoService;
  87. @Autowired
  88. private UserConsumptionPackageService userConsumptionPackageService;
  89. @Autowired
  90. private WxCUserAuthorityService wxCUserAuthorityService;
  91. @AuthIgnore
  92. @ApiOperation("验证码")
  93. @GetMapping("/captcha.jpg")
  94. public void captcha(HttpServletResponse response) {
  95. logger.debug("[" + getIpAddr() + "] WxUserGrantController::captcha");
  96. response.setHeader("Cache-Control", "no-store, no-cache");
  97. response.setContentType("image/jpeg");
  98. //生成文字验证码
  99. String text = producer.createText();
  100. //生成图片验证码
  101. BufferedImage image = producer.createImage(text);
  102. //保存到redis
  103. String ipAddr = getIpAddr();
  104. String key = Constant.captchaPrev + ":" + ipAddr;
  105. RedisCacheUtils.cache(redisTemplate, key, text, 60);
  106. ServletOutputStream out = null;
  107. try {
  108. out = response.getOutputStream();
  109. ImageIO.write(image, "jpg", out);
  110. } catch (IOException e) {
  111. e.printStackTrace();
  112. } finally {
  113. IOUtils.closeQuietly(out);
  114. }
  115. }
  116. /**
  117. * 用户登录
  118. * 手机号+密码登陆
  119. *
  120. * @param map
  121. * @return
  122. */
  123. @AuthIgnore
  124. @PostMapping("/login")
  125. @ApiOperation(value = "用户登录", notes = "{\"phone\":\"string\",\"password\":\"string\",\"code\":\"string\"}")
  126. public ResultData loginByPhone(@RequestBody Map<String, String> map) {
  127. String ipAddr = getIpAddr();
  128. logger.debug("[" + ipAddr + "] WxUserGrantController::loginByPhone");
  129. String code = map.get("code");
  130. if (StringUtils.isBlank(code)) {
  131. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "请输入验证码");
  132. }
  133. String key = Constant.captchaPrev + ":" + ipAddr;
  134. String code1 = RedisCacheUtils.getCacheString(redisTemplate, key);
  135. // if (StringUtils.isBlank(code1)) {
  136. // return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码已过期");
  137. // }
  138. // if (!code1.equals(code)) {
  139. // return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码不正确");
  140. // }
  141. String phone = map.get("phone");
  142. String password = map.get("password");
  143. if (StringUtils.isBlank(phone) || StringUtils.isBlank(password)) {
  144. return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "手机号或密码为空");
  145. }
  146. WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(getTenantInfo(), phone);
  147. if (basicInfo == null) {
  148. return new ResultData(ErrorCode.USER_IS_EMPTY);
  149. }
  150. if(StringUtils.isBlank(basicInfo.getPassword())){
  151. return new ResultData(ErrorCode.USER_PASSWD_ERR.getCode(),"该用户未设置密码,请用其他方式登陆");
  152. }
  153. String encryptPassword = new PasswordHelper().encryptPassword(password);
  154. if (!encryptPassword.equals(basicInfo.getPassword())) {
  155. return new ResultData(ErrorCode.USER_PASSWD_ERR.getCode(), "手机号或密码错误");
  156. }
  157. wxCUserBasicInfoService.handleLoginUser(basicInfo);
  158. Map resultMap = new HashMap();
  159. // resultMap.put("phone", basicInfo.getPhone());
  160. resultMap.put("token", basicInfo.getToken());
  161. return new ResultData(resultMap);
  162. }
  163. /**
  164. * 用户登录
  165. * 邮箱+密码登陆
  166. *
  167. * @param map
  168. * @return
  169. */
  170. @AuthIgnore
  171. @PostMapping("/loginByEmail")
  172. @ApiOperation(value = "用户登录", notes = "{\"email\":\"string\",\"password\":\"string\",\"code\":\"string\"}")
  173. public ResultData loginByEmail(@RequestBody Map<String, String> map) {
  174. String ipAddr = getIpAddr();
  175. logger.debug("[" + ipAddr + "] WxUserGrantController::loginByEmail");
  176. String code = map.get("code");
  177. if (StringUtils.isBlank(code)) {
  178. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "请输入验证码");
  179. }
  180. String key = Constant.captchaPrev + ":" + ipAddr;
  181. String code1 = RedisCacheUtils.getCacheString(redisTemplate, key);
  182. if (StringUtils.isBlank(code1)) {
  183. return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码已过期");
  184. }
  185. if (!code1.equals(code)) {
  186. return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码不正确");
  187. }
  188. String email = map.get("email");
  189. String password = map.get("password");
  190. if (StringUtils.isBlank(email) || StringUtils.isBlank(password)) {
  191. return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "邮箱或密码为空");
  192. }
  193. WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByEmail(getTenantInfo(), email);
  194. if (basicInfo == null) {
  195. return new ResultData(ErrorCode.USER_IS_EMPTY);
  196. }
  197. if (EnumCUserBasicInfoStatus.NOT_ACTIVE.getCode().equals(basicInfo.getStatus())) {
  198. return new ResultData(ErrorCode.MEMBER_IS_NOT_ACTIVE);
  199. }
  200. String encryptPassword = new PasswordHelper().encryptPassword(password);
  201. if (!encryptPassword.equals(basicInfo.getPassword())) {
  202. return new ResultData(ErrorCode.USER_PASSWD_ERR.getCode(), "邮箱或密码错误");
  203. }
  204. wxCUserBasicInfoService.handleLoginUser(basicInfo);
  205. Map resultMap = new HashMap();
  206. // resultMap.put("phone", basicInfo.getPhone());
  207. resultMap.put("token", basicInfo.getToken());
  208. return new ResultData(resultMap);
  209. }
  210. /**
  211. * 用户登录
  212. * 手机+验证码登陆
  213. *
  214. * @param map
  215. * @return
  216. */
  217. @AuthIgnore
  218. @ApiOperation(value = "手机验证码登录", notes = "{\"phone\",\"string\",\"code\",\"string\"}")
  219. @PostMapping("/doLoginByPhone")
  220. public ResultData doLoginByPhone(@RequestBody Map<String, String> map, HttpServletResponse response) {
  221. String ipaddress = getIpAddr();
  222. logger.debug("[" + ipaddress + "] WxUserGrantController::doLoginByPhone");
  223. // String phone,String code,String pwd
  224. String phone = map.get("phone");
  225. String code = map.get("code");
  226. if (StringUtils.isBlank(phone)) {
  227. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "手机号不能为空");
  228. }
  229. if (StringUtils.isBlank(code)) {
  230. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空");
  231. }
  232. // check 验证码正确
  233. boolean isValidCode = false;
  234. try {
  235. isValidCode = wxMsgValidationcodeService.checkCodeValid(phone, code);
  236. } catch (Exception e) {
  237. return new ResultData(Result.ERROR, e.getMessage());
  238. }
  239. if (isValidCode) {
  240. WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(getTenantInfo(), phone);
  241. if (basicInfo == null) {
  242. basicInfo = wxCUserBasicInfoService.register(getTenantInfo(), phone, null);
  243. }
  244. wxCUserBasicInfoService.handleLoginUser(basicInfo);
  245. Map resultMap = new HashMap();
  246. // resultMap.put("phone", basicInfo.getPhone());
  247. resultMap.put("token", basicInfo.getToken());
  248. return new ResultData(resultMap);
  249. } else {
  250. return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND);
  251. }
  252. }
  253. /**
  254. * 获取用户信息
  255. * @return
  256. */
  257. @PostMapping("/getBasicInfo")
  258. @ApiOperation(value = "用户登录", notes = "")
  259. public ResultData getBasicInfo() {
  260. logger.debug("[" + getIpAddr() + "] WxUserGrantController::getBasicInfo");
  261. WxCUserBasicInfo basicInfo = getCUser();
  262. basicInfo.setPassword(null);
  263. basicInfo.setIdCard(null);
  264. return new ResultData(basicInfo);
  265. }
  266. @AuthIgnore
  267. @ApiOperation("发送手机验证码")
  268. @GetMapping("sendLoginPhoneCode")
  269. @ApiImplicitParams({
  270. @ApiImplicitParam(name = "phone", value = "手机号", dataType = "String", paramType = "query", required = true)})
  271. public ResultData sendLoginPhoneCode(String phone) {
  272. logger.debug("[" + getIpAddr() + "] WxUserGrantController::sendlogincode");
  273. if (StringUtils.isBlank(phone)) {
  274. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "请输入手机号");
  275. }
  276. WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode();
  277. wxMsgValidationcode.setPhone(phone);
  278. wxMsgValidationcode.setType(EnumMsgModel.VALIDATION_CODE.getCode());
  279. return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode);
  280. }
  281. /**
  282. * 需要效验用户及图片验证码
  283. *
  284. * @param phone
  285. * @return
  286. */
  287. @AuthIgnore
  288. @ApiOperation("发送修改密码验证码")
  289. @GetMapping("sendPhoneCode")
  290. @ApiImplicitParams({
  291. @ApiImplicitParam(name = "phone", value = "手机号", dataType = "String", paramType = "query", required = true)})
  292. public ResultData sendPhoneCode(String phone, String code) {
  293. String ipAddr = getIpAddr();
  294. logger.debug("[" + ipAddr + "] WxUserGrantController::sendPhoneCode");
  295. if (StringUtils.isBlank(phone)) {
  296. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "请输入手机号");
  297. }
  298. if (StringUtils.isBlank(code)) {
  299. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "请输入验证码");
  300. }
  301. String key = Constant.captchaPrev + ":" + ipAddr;
  302. String code1 = RedisCacheUtils.getCacheString(redisTemplate, key);
  303. if (StringUtils.isBlank(code1)) {
  304. return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码已过期");
  305. }
  306. if (!code1.equals(code)) {
  307. return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码不正确");
  308. }
  309. WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(getTenantInfo(), phone);
  310. if (basicInfo == null) {
  311. return new ResultData(ErrorCode.USER_IS_EMPTY.getCode(), "该手机号未注册");
  312. }
  313. WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode();
  314. wxMsgValidationcode.setPhone(phone);
  315. wxMsgValidationcode.setType(EnumMsgModel.VALIDATION_CODE.getCode());
  316. return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode);
  317. }
  318. @AuthIgnore
  319. @ApiOperation(value = "手机号注册", notes = "{\"phone\",\"string\",\"code\",\"string\"}")
  320. @PostMapping("/doRegisterByPhone")
  321. public ResultData doRegisterByPhone(@RequestBody Map<String, String> params, HttpServletResponse response) {
  322. String ipaddress = getIpAddr();
  323. logger.debug("[" + ipaddress + "] WxUserGrantController::doRegisterByPhone");
  324. // String phone,String code,String pwd
  325. String phone = params.get("phone");
  326. String password = params.get("password");
  327. String code = params.get("code");
  328. if (StringUtils.isBlank(phone)) {
  329. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "手机号不能为空");
  330. }
  331. if (StringUtils.isBlank(password)) {
  332. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "密码不能为空");
  333. }
  334. // if (StringUtils.isBlank(code)) {
  335. // return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空");
  336. // }
  337. WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(getTenantInfo(), phone);
  338. if (basicInfo != null) {
  339. return new ResultData(ErrorCode.MEMBER_IS_FOUND);
  340. }
  341. // check 验证码正确
  342. // boolean isValidCode = false;
  343. // try {
  344. // isValidCode = wxMsgValidationcodeService.checkCodeValid(phone,code);
  345. // } catch (Exception e) {
  346. // return new ResultData(Result.ERROR, e.getMessage());
  347. // }
  348. // if(isValidCode) {
  349. basicInfo = wxCUserBasicInfoService.register(getTenantInfo(), phone, password);
  350. Boolean aBoolean = userCreateVideoNumService.initializationUserCreateVideoNum(basicInfo.getId());
  351. if (!aBoolean) {
  352. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "初始化创建视频时间表失败");
  353. }
  354. return new ResultData();
  355. // } else {
  356. // return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND);
  357. // }
  358. }
  359. @AuthIgnore
  360. @ApiOperation(value = "邮箱注册", notes = "{\"email\",\"string\",\"code\",\"string\"}")
  361. @PostMapping("/doRegisterByEmail")
  362. public ResultData doRegisterByEmail(@RequestBody Map<String, String> params, HttpServletResponse response) {
  363. String ipaddress = getIpAddr();
  364. logger.debug("[" + ipaddress + "] WxUserGrantController::doRegisterByEmail");
  365. // String name,String username,String password
  366. String name = params.get("name");
  367. String email = params.get("email");
  368. String password = params.get("password");
  369. String code = params.get("code");
  370. if (StringUtils.isBlank(email)) {
  371. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "邮箱不能为空");
  372. }
  373. if (StringUtils.isBlank(password)) {
  374. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "密码不能为空");
  375. }
  376. // if (StringUtils.isBlank(code)) {
  377. // return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空");
  378. // }
  379. WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByEmail(getTenantInfo(), email);
  380. if (basicInfo != null) {
  381. return new ResultData(ErrorCode.MEMBER_IS_FOUND);
  382. }
  383. // check 验证码正确
  384. // boolean isValidCode = false;
  385. // try {
  386. // isValidCode = wxMsgValidationcodeService.checkCodeValid(phone,code);
  387. // } catch (Exception e) {
  388. // return new ResultData(Result.ERROR, e.getMessage());
  389. // }
  390. // if(isValidCode) {
  391. basicInfo = wxCUserBasicInfoService.registerEmail(getTenantInfo(), email, password);
  392. Boolean aBoolean = userCreateVideoNumService.initializationUserCreateVideoNum(basicInfo.getId());
  393. if (!aBoolean) {
  394. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "初始化创建视频时间表失败");
  395. }
  396. return new ResultData();
  397. // } else {
  398. // return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND);
  399. // }
  400. }
  401. @AuthIgnore
  402. @ApiOperation(value = "发送激活邮件", notes = "{\"email\",\"string\",\"code\",\"string\"}")
  403. @PostMapping("/sendRegisterEmail")
  404. public ResultData sendRegisterEmail(@RequestBody Map<String, String> params, HttpServletResponse response) {
  405. String ipaddress = getIpAddr();
  406. logger.debug("[" + ipaddress + "] WxUserGrantController::sendRegisterEmail");
  407. // String name,String username,String password
  408. String email = params.get("email");
  409. String code = params.get("code");
  410. if (StringUtils.isBlank(email)) {
  411. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "邮箱不能为空");
  412. }
  413. // if (StringUtils.isBlank(code)) {
  414. // return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空");
  415. // }
  416. WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByEmail(getTenantInfo(), email);
  417. if (basicInfo == null) {
  418. return new ResultData(ErrorCode.USER_IS_EMPTY);
  419. }
  420. if (!EnumCUserBasicInfoStatus.NOT_ACTIVE.getCode().equals(basicInfo.getStatus())) {
  421. return new ResultData(ErrorCode.MEMBER_IS_ACTIVE);
  422. }
  423. // check 验证码正确
  424. // boolean isValidCode = false;
  425. // try {
  426. // isValidCode = wxMsgValidationcodeService.checkCodeValid(phone,code);
  427. // } catch (Exception e) {
  428. // return new ResultData(Result.ERROR, e.getMessage());
  429. // }
  430. // if(isValidCode) {
  431. wxCUserBasicInfoService.sendTicketEmail(basicInfo, EnumMsgModel.EMAIL_ACTIVATION);
  432. return new ResultData();
  433. // } else {
  434. // return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND);
  435. // }
  436. }
  437. @AuthIgnore
  438. @ApiOperation(value = "激活", notes = "")
  439. @PostMapping("/doActivation")
  440. public ResultData doActivation(@RequestBody Map<String, String> params, HttpServletResponse response) {
  441. String ipaddress = getIpAddr();
  442. logger.debug("[" + ipaddress + "] WxUserGrantController::doActivation");
  443. //
  444. String ticket = params.get("ticket");
  445. String key = Constant.ticketPrev + ticket;
  446. Long userId = RedisCacheUtils.getCacheLong(redisTemplate, key);
  447. if (userId == null) {
  448. return new ResultData(ErrorCode.NET_TICKET_INVALID.getCode(), "ticket已过期");
  449. }
  450. WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.getById(userId);
  451. if (basicInfo == null) {
  452. return new ResultData(ErrorCode.USER_IS_EMPTY);
  453. }
  454. // if(!EnumCUserBasicInfoStatus.NOT_ACTIVE.getCode().equals(basicInfo.getStatus())){
  455. // return new ResultData(ErrorCode.MEMBER_IS_ACTIVE);
  456. // }
  457. wxCUserBasicInfoService.handleLoginUser(basicInfo);
  458. Map resultMap = new HashMap();
  459. // resultMap.put("username", basicInfo.getEmail());
  460. resultMap.put("token", basicInfo.getToken());
  461. return new ResultData(resultMap);
  462. }
  463. @AuthIgnore
  464. @ApiOperation(value = "手机验证码修改密码", notes = "{\"phone\",\"string\",\"code\",\"string\"}")
  465. @PostMapping("/updPass")
  466. public ResultData updPass(@RequestBody Map<String, String> params, HttpServletResponse response) {
  467. String ipaddress = getIpAddr();
  468. logger.debug("[" + ipaddress + "] WxUserGrantController::doLoginByPhone");
  469. // String phone,String code,String pwd
  470. String phone = params.get("phone");
  471. String code = params.get("code");
  472. String pwd = params.get("pwd");
  473. if (StringUtils.isBlank(phone)) {
  474. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "手机号不能为空");
  475. }
  476. if (StringUtils.isBlank(code)) {
  477. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空");
  478. }
  479. if (StringUtils.isBlank(pwd)) {
  480. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "密码不能为空");
  481. }
  482. WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(getTenantInfo(), phone);
  483. if (basicInfo == null) {
  484. return new ResultData(ErrorCode.USER_PHONE_IS_NOT_FOUND.getCode(), "手机号还未注册");
  485. }
  486. // check 验证码正确
  487. boolean isValidCode = false;
  488. try {
  489. isValidCode = wxMsgValidationcodeService.checkCodeValid(phone, code);
  490. } catch (Exception e) {
  491. return new ResultData(Result.ERROR, e.getMessage());
  492. }
  493. if (isValidCode) {
  494. String encryptPassword = new PasswordHelper().encryptPassword(pwd);
  495. WxCUserBasicInfo basicInfoUpd = new WxCUserBasicInfo();
  496. basicInfoUpd.setId(basicInfo.getId());
  497. basicInfoUpd.setPassword(encryptPassword);
  498. wxCUserBasicInfoService.update(basicInfoUpd);
  499. return new ResultData();
  500. } else {
  501. return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND);
  502. }
  503. }
  504. @ApiOperation(value = "旧密码修改密码", notes = "{\"oldpwd\",\"string\",\"newpwd\",\"string\"}")
  505. @PostMapping("/oldUpdPass")
  506. public ResultData oldUpdPass(@RequestBody Map<String, String> params, HttpServletResponse response) {
  507. String ipaddress = getIpAddr();
  508. logger.debug("[" + ipaddress + "] WxUserGrantController::oldUpdPass");
  509. WxCUserBasicInfo basicInfo = getCUser();
  510. //
  511. String oldpwd = params.get("oldpwd");
  512. // String code = params.get("code");
  513. String newpwd = params.get("newpwd");
  514. if (StringUtils.isBlank(oldpwd)) {
  515. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "旧密码不能为空");
  516. }
  517. // if (StringUtils.isBlank(code)) {
  518. // return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空");
  519. // }
  520. if (StringUtils.isBlank(newpwd)) {
  521. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "新密码不能为空");
  522. }
  523. String encryptPassword = new PasswordHelper().encryptPassword(oldpwd);
  524. if (!encryptPassword.equals(basicInfo.getPassword())) {
  525. return new ResultData(ErrorCode.PASSWORD_ERROR.getCode(), "旧密码错误");
  526. }
  527. // check 验证码正确
  528. // boolean isValidCode = false;
  529. // try {
  530. // isValidCode = wxMsgValidationcodeService.checkCodeValid(phone,code);
  531. // } catch (Exception e) {
  532. // return new ResultData(Result.ERROR, e.getMessage());
  533. // }
  534. // if(isValidCode) {
  535. String newEncryptPassword = new PasswordHelper().encryptPassword(newpwd);
  536. WxCUserBasicInfo basicInfoUpd = new WxCUserBasicInfo();
  537. basicInfoUpd.setId(basicInfo.getId());
  538. basicInfoUpd.setPassword(newEncryptPassword);
  539. wxCUserBasicInfoService.update(basicInfoUpd);
  540. return new ResultData();
  541. // } else {
  542. // return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND);
  543. // }
  544. }
  545. @AuthIgnore
  546. @ApiOperation(value = "发送修改密码邮件", notes = "{\"email\",\"string\",\"code\",\"string\"}")
  547. @PostMapping("/sendUpdPwdEmail")
  548. public ResultData sendUpdPwdEmail(@RequestBody Map<String, String> params, HttpServletResponse response) {
  549. String ipaddress = getIpAddr();
  550. logger.debug("[" + ipaddress + "] WxUserGrantController::sendUpdPwdEmail");
  551. // String name,String username,String password
  552. String email = params.get("email");
  553. String code = params.get("code");
  554. if (StringUtils.isBlank(email)) {
  555. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "邮箱不能为空");
  556. }
  557. // if (StringUtils.isBlank(code)) {
  558. // return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空");
  559. // }
  560. WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByEmail(getTenantInfo(), email);
  561. if (basicInfo == null) {
  562. return new ResultData(ErrorCode.USER_IS_EMPTY);
  563. }
  564. if (EnumCUserBasicInfoStatus.NOT_ACTIVE.getCode().equals(basicInfo.getStatus())) {
  565. return new ResultData(ErrorCode.MEMBER_IS_NOT_ACTIVE);
  566. }
  567. // check 验证码正确
  568. // boolean isValidCode = false;
  569. // try {
  570. // isValidCode = wxMsgValidationcodeService.checkCodeValid(phone,code);
  571. // } catch (Exception e) {
  572. // return new ResultData(Result.ERROR, e.getMessage());
  573. // }
  574. // if(isValidCode) {
  575. wxCUserBasicInfoService.sendTicketEmail(basicInfo, EnumMsgModel.EMAIL_UPD_PWD);
  576. return new ResultData();
  577. // } else {
  578. // return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND);
  579. // }
  580. }
  581. @AuthIgnore
  582. @ApiOperation(value = "修改密码", notes = "{\"username\",\"string\",\"code\",\"string\"}")
  583. @PostMapping("/doUpdPass")
  584. public ResultData doUpdPass(@RequestBody Map<String, String> params, HttpServletResponse response) {
  585. String ipaddress = getIpAddr();
  586. logger.debug("[" + ipaddress + "] WxUserGrantController::doUpdPass");
  587. //
  588. String ticket = params.get("ticket");
  589. String key = Constant.ticketPrev + ticket;
  590. Long userId = RedisCacheUtils.getCacheLong(redisTemplate, key);
  591. if (userId == null) {
  592. return new ResultData(ErrorCode.NET_TICKET_INVALID.getCode(), "已过期");
  593. }
  594. WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.getById(userId);
  595. if (basicInfo == null) {
  596. return new ResultData(ErrorCode.USER_IS_EMPTY);
  597. }
  598. String pwd = params.get("pwd");
  599. if (StringUtils.isBlank(pwd)) {
  600. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "密码不能为空");
  601. }
  602. String encryptPassword = new PasswordHelper().encryptPassword(pwd);
  603. WxCUserBasicInfo basicInfoUpd = new WxCUserBasicInfo();
  604. basicInfoUpd.setId(basicInfo.getId());
  605. basicInfoUpd.setPassword(encryptPassword);
  606. wxCUserBasicInfoService.update(basicInfoUpd);
  607. return new ResultData();
  608. }
  609. @ApiOperation("登出")
  610. @GetMapping("/logout")
  611. public ResultData logout() {
  612. logger.debug("[" + getIpAddr() + "] WxUserGrantController::logout");
  613. wxCUserBasicInfoService.logout(getCUser());
  614. return new ResultData();
  615. }
  616. @ApiOperation("生成邀请码")
  617. @GetMapping("/inviteCode")
  618. public ResultData inviteCode() {
  619. logger.debug("[" + getIpAddr() + "] WxUserGrantController::inviteCode");
  620. String code = inviteCodeService.inviteCode(getMemberId());
  621. return new ResultData(code);
  622. }
  623. @ApiOperation("使用邀请码")
  624. @GetMapping("/useCode")
  625. @ApiImplicitParam(name = "code", value = "code", dataType = "String", paramType = "query", required = true)
  626. public ResultData useCode(String code) {
  627. logger.debug("[" + getIpAddr() + "] WxUserGrantController::useCode");
  628. return inviteCodeInfoService.useCode(getCUser(), code);
  629. }
  630. @ApiOperation("是否使用邀请码判断")
  631. @GetMapping("/isUse")
  632. public ResultData isUse() {
  633. logger.debug("[" + getIpAddr() + "] WxUserGrantController::isUse");
  634. Boolean use = inviteCodeInfoService.isUse(getCUser());
  635. return new ResultData(use);
  636. }
  637. @ApiOperation("查询哪些用户使用了当前账户的邀请码")
  638. @GetMapping("/getUseCodeUser")
  639. public ResultData getUseCodeUser() {
  640. logger.debug("[" + getIpAddr() + "] WxUserGrantController::getUseCodeUser");
  641. List<InviteCodeInfo> useCodeUser = inviteCodeInfoService.getUseCodeUser(getCUser());
  642. return new ResultData(useCodeUser);
  643. }
  644. @ApiOperation("编辑用户头像和名称")
  645. @PostMapping("/updUserInfo")
  646. public ResultData updUserInfo(@RequestBody WxCUserBasicInfo wxCUserBasicInfo) {
  647. logger.debug("[" + getIpAddr() + "] WxUserGrantController::updUserInfo");
  648. wxCUserBasicInfoService.updUserInfo(wxCUserBasicInfo, getMemberId());
  649. return new ResultData();
  650. }
  651. @ApiOperation("获取用户头像和名称")
  652. @GetMapping("/getUserInfo")
  653. public ResultData getUserInfo() {
  654. logger.debug("[" + getIpAddr() + "] WxUserGrantController::getUserInfo");
  655. WxCUserBasicInfo userBasicInfo = wxCUserBasicInfoService.getById(getMemberId());
  656. return new ResultData(userBasicInfo);
  657. }
  658. @AuthIgnore
  659. @ApiOperation("套餐档次查询")
  660. @GetMapping("/getPackageInfo")
  661. public ResultData getPackageInfo() {
  662. logger.debug("[" + getIpAddr() + "] WxUserGrantController::getPackageInfo");
  663. return new ResultData(userConsumptionPackageService.getPackageInfo());
  664. }
  665. }