|
@@ -2,24 +2,34 @@ package com.care.client.controller;
|
|
|
|
|
|
import com.care.client.service.PassportService;
|
|
|
import com.care.client.vo.MemberInitParams;
|
|
|
+import com.care.common.entity.CareMemberInfo;
|
|
|
+import com.care.common.service.CareMemberInfoService;
|
|
|
+import com.care.common.service.SmsSendService;
|
|
|
import com.care.common.util.CheckUtils;
|
|
|
import com.care.common.util.Result;
|
|
|
-import io.swagger.annotations.Api;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
-import io.swagger.annotations.ApiParam;
|
|
|
+import com.google.common.cache.Cache;
|
|
|
+import com.google.common.cache.CacheBuilder;
|
|
|
+import io.swagger.annotations.*;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.Random;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@Api(tags = "登录")
|
|
|
@RestController
|
|
|
@RequestMapping("/pinanbao")
|
|
|
public class PassportController {
|
|
|
|
|
|
-
|
|
|
@Resource
|
|
|
private PassportService passportService;
|
|
|
+ @Resource
|
|
|
+ private SmsSendService smsSendService;
|
|
|
+ @Resource
|
|
|
+ private CareMemberInfoService careMemberInfoService;
|
|
|
+
|
|
|
+ public final Cache<String, String> smsTimeoutCache = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build();
|
|
|
|
|
|
@ApiOperation(value = "小程序登录", notes = "小程序授权登录")
|
|
|
@ApiParam(name = "params", value = "登录参数")
|
|
@@ -39,6 +49,57 @@ public class PassportController {
|
|
|
return passportService.login(params);
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation(value = "新用户注册", notes = "新用户注册")
|
|
|
+ @GetMapping("registerPhone")
|
|
|
+ @ApiImplicitParams(value = {
|
|
|
+ @ApiImplicitParam(paramType = "query", name = "phone", value = "电话号码"),
|
|
|
+ @ApiImplicitParam(paramType = "query", name = "vcode", value = "验证码"),
|
|
|
+ @ApiImplicitParam(paramType = "query", name = "password", value = "密码 "),
|
|
|
+ })
|
|
|
+ public Result<Object> registerPhone(@RequestHeader(value = "token") String token,
|
|
|
+ @RequestParam(value = "phone", required = true) String phone,
|
|
|
+ @RequestParam(value = "vcode", required = true) String vcode,
|
|
|
+ @RequestParam(value = "password", required = true) String password) {
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(phone)) {
|
|
|
+ return Result.error("请输入手机号");
|
|
|
+ }
|
|
|
+ if (!StringUtils.equalsIgnoreCase(vcode, smsTimeoutCache.getIfPresent(phone))) {
|
|
|
+ return Result.error("请输入正确的验证码");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(password)) {
|
|
|
+ return Result.error("请输入密码");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(phone) && StringUtils.isNotBlank(password)) {
|
|
|
+ CareMemberInfo careMemberInfo = new CareMemberInfo();
|
|
|
+ careMemberInfo.setPhone(phone);
|
|
|
+ careMemberInfo.setPassword(password);
|
|
|
+ boolean flag = careMemberInfoService.save(careMemberInfo);
|
|
|
+ if (flag) {
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.error("绑定手机号码失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "新用户注册-获取验证码", notes = "新用户注册-获取验证码")
|
|
|
+ @GetMapping("getVCode")
|
|
|
+ @ApiImplicitParams(value = {
|
|
|
+ @ApiImplicitParam(paramType = "query", name = "phone", value = "电话号码"),
|
|
|
+ })
|
|
|
+ public Result<String> getVCode(@RequestParam(value = "phone", required = true) String phone) {
|
|
|
+
|
|
|
+ String vcode = String.format("%04d",new Random().nextInt(9999));
|
|
|
+ boolean flag = smsSendService.sendSmsCode4RegisterPhone(phone, vcode);
|
|
|
+ if (flag) {
|
|
|
+ smsTimeoutCache.put(phone, vcode);
|
|
|
+ return Result.success();
|
|
|
+ } else {
|
|
|
+ return Result.error("获取验证码失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@ApiOperation(value = "小程序登出", notes = "小程序登出")
|
|
|
@PostMapping("logout")
|