瀏覽代碼

手机号绑定修改

master
sunfengxiang 2 年之前
父節點
當前提交
de98a0cecb
共有 1 個文件被更改,包括 23 次插入20 次删除
  1. +23
    -20
      src/main/java/com/github/niefy/modules/wx/manage/SmsController.java

+ 23
- 20
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();
}
}

}

Loading…
取消
儲存