WxUserApi.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package com.caimei.controller.wechat;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.caimei.model.ResponseJson;
  4. import com.caimei.model.vo.WxClubUserVo;
  5. import com.caimei.service.wechat.RegisterService;
  6. import com.caimei.service.wechat.WxUserService;
  7. import io.swagger.annotations.Api;
  8. import io.swagger.annotations.ApiImplicitParam;
  9. import io.swagger.annotations.ApiImplicitParams;
  10. import io.swagger.annotations.ApiOperation;
  11. import lombok.RequiredArgsConstructor;
  12. import org.apache.commons.lang3.StringUtils;
  13. import org.springframework.web.bind.annotation.*;
  14. import java.util.Map;
  15. /**
  16. * 机构用户登录API
  17. *
  18. * @author : Aslee
  19. * @date : 2021/5/11
  20. */
  21. @Api(tags = "机构用户API")
  22. @RestController
  23. @RequiredArgsConstructor
  24. @RequestMapping("/wx/user")
  25. public class WxUserApi {
  26. private final WxUserService wxUserService;
  27. @ApiOperation("获取用户信息")
  28. @ApiImplicitParams({
  29. @ApiImplicitParam(name = "mobile", required = true, value = "手机号"),
  30. @ApiImplicitParam(name = "authUserId", required = false, value = "供应商用户id"),
  31. @ApiImplicitParam(name = "clubUserId", required = false, value = "机构用户id")
  32. })
  33. @GetMapping("/info")
  34. public ResponseJson<Map<String,Object>> register(String mobile, Integer authUserId, Integer clubUserId) {
  35. if (StringUtils.isEmpty(mobile) && null == clubUserId) {
  36. return ResponseJson.error("参数异常", null);
  37. }
  38. if (null == clubUserId && null == authUserId) {
  39. return ResponseJson.error("供应商用户id不能为空", null);
  40. }
  41. return wxUserService.getUserInfo(mobile, authUserId, clubUserId);
  42. }
  43. @ApiOperation("登录注册验证码发送")
  44. @ApiImplicitParam(name = "params", value = "mobile:手机号;authUserId:供应商用户id;type:1注册验证码,2忘记密码验证码")
  45. @PostMapping("/login/code/send")
  46. public ResponseJson sendForgetCode(@RequestBody String params) {
  47. JSONObject parseObject = JSONObject.parseObject(params);
  48. String mobile = parseObject.getString("mobile");
  49. Integer authUserId = parseObject.getInteger("authUserId");
  50. Integer type = parseObject.getInteger("type");
  51. if (StringUtils.isEmpty(mobile)) {
  52. return ResponseJson.error("手机号不能为空", null);
  53. }
  54. if (null == authUserId) {
  55. return ResponseJson.error("供应商用户id不能为空", null);
  56. }
  57. if (null == type) {
  58. return ResponseJson.error("验证码类型不能为空");
  59. }
  60. return wxUserService.sendLoginCode(mobile, authUserId, type);
  61. }
  62. @ApiOperation("修改密码")
  63. @ApiImplicitParam(name = "params", value = "mobile:手机号;verifyCode:验证码;password:新密码;authUserId:供应商用户id")
  64. @PostMapping("/password/update")
  65. public ResponseJson updatePassword(@RequestBody String params) {
  66. JSONObject parseObject = JSONObject.parseObject(params);
  67. String mobile = parseObject.getString("mobile");
  68. String verifyCode = parseObject.getString("verifyCode");
  69. String password = parseObject.getString("password");
  70. Integer authUserId = parseObject.getInteger("authUserId");
  71. if (StringUtils.isEmpty(mobile)) {
  72. return ResponseJson.error("手机号不能为空", null);
  73. }
  74. if (StringUtils.isEmpty(verifyCode)) {
  75. return ResponseJson.error("验证码不能为空", null);
  76. }
  77. if (StringUtils.isEmpty(password)) {
  78. return ResponseJson.error("新密码不能为空", null);
  79. }
  80. if (null == authUserId) {
  81. return ResponseJson.error("供应商用户id不能为空", null);
  82. }
  83. return wxUserService.updatePassword(mobile, verifyCode, password, authUserId);
  84. }
  85. @ApiOperation("校验token是否失效")
  86. @PostMapping("/token/check")
  87. public ResponseJson checkToken(){
  88. return ResponseJson.success("token有效");
  89. }
  90. }