From de98a0cecb036d9ac3b215b5cb93ef3a05516eda Mon Sep 17 00:00:00 2001 From: sunfengxiang Date: Wed, 18 Jan 2023 14:08:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E6=9C=BA=E5=8F=B7=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/wx/manage/SmsController.java | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/github/niefy/modules/wx/manage/SmsController.java b/src/main/java/com/github/niefy/modules/wx/manage/SmsController.java index bd678eb..7862805 100644 --- a/src/main/java/com/github/niefy/modules/wx/manage/SmsController.java +++ b/src/main/java/com/github/niefy/modules/wx/manage/SmsController.java @@ -1,17 +1,20 @@ package com.github.niefy.modules.wx.manage; +import com.github.niefy.common.utils.R; import com.github.niefy.common.utils.StringUtils; -import com.github.niefy.common.utils.SmsUtils; import com.github.niefy.modules.wx.entity.SMS; import com.github.niefy.modules.wx.entity.WxUser; import com.github.niefy.modules.wx.service.WxUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + import java.util.Date; import java.util.Random; -import com.github.niefy.common.utils.R; //参考https://www.jianshu.com/p/a0caa7ff2336 @RestController @@ -39,25 +42,26 @@ public class SmsController { //发送短信 // String code = SmsUtils.sendNoteMessgae(mobile, String.valueOf(smscode)); String code = "OK"; - if("OK".equals(code)){ + if ("OK".equals(code)) { //返回验证码和发送时间 - return R.ok().put("smsCode",String.valueOf(smscode)+new Date().getTime()); - }else { + return R.ok().put("smsCode", String.valueOf(smscode) + new Date().getTime()); + } else { return R.error("短信发送失败"); } } @ApiOperation(value = "验证短信验证码", notes = "验证短信验证码") -// @ApiImplicitParams({@ApiImplicitParam(name = "mobile", value = "手机号码", paramType = "query", required = true, dataType = "String"), @ApiImplicitParam(name = "code", value = "验证码", paramType = "query", required = true, dataType = "String")}) +// @ApiImplicitParams({@ApiImplicitParam(name = "mobile", value = "手机号码", paramType = "query", required = true, dataType = "String"), +// @ApiImplicitParam(name = "code", value = "验证码", paramType = "query", required = true, dataType = "String")}) @PostMapping(value = "/verifyCode") public R smsLogin(@RequestBody SMS sms) { String openId = sms.getOpenId(); String mobile = sms.getMobile(); String smsCode = sms.getCode(); String code_codeTime = sms.getCodeTime(); - String code = code_codeTime.substring(0,6); + String code = code_codeTime.substring(0, 6); long codeTime = Long.parseLong(code_codeTime.substring(6)); - if (new Date().getTime()>(codeTime+(5*60*1000))) { + if (new Date().getTime() > (codeTime + (5 * 60 * 1000))) { return R.error("验证码已过期"); } if (!code.equals(smsCode)) { @@ -67,17 +71,16 @@ public class SmsController { return R.error("手机号不能为空"); } //根据手机号码查找是否存在 -// WxUser wxUser = userService.findByPhone(mobile); -// if(wxUser != null){ -// return R.error("手机号已绑定"); -// }else { -// WxUser wxUsernew = new WxUser(); -// wxUsernew.setOpenid(openId); -// wxUsernew.setPhone(mobile); -// userService.saveOrUpdate(wxUsernew); -// return R.ok(); -// } - return R.ok(); + WxUser wxUser = userService.findByPhone(mobile); + if (wxUser != null) { + return R.error("手机号已绑定"); + } else { + WxUser wxUsernew = new WxUser(); + wxUsernew.setOpenid(openId); + wxUsernew.setPhone(mobile); + userService.saveOrUpdate(wxUsernew); + return R.ok(); + } } }