|
|
@@ -15,14 +15,16 @@ import com.github.niefy.common.utils.R; |
|
|
|
|
|
|
|
//参考https://www.jianshu.com/p/a0caa7ff2336 |
|
|
|
@RestController |
|
|
|
@RequestMapping("/manage/sms") |
|
|
|
@RequestMapping("/sms") |
|
|
|
@Api(tags = {"短信-绑定手机号"}) |
|
|
|
public class SmsController { |
|
|
|
@Autowired |
|
|
|
private WxUserService userService; |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/code") |
|
|
|
@ApiOperation(value = "获取短信验证码", notes = "获取短信验证码") |
|
|
|
// @ApiImplicitParam(name = "mobile", value = "手机号码", paramType = "query", required = true, dataType = "String") |
|
|
|
@PostMapping(value = "/code") |
|
|
|
public R getMobileCode(@RequestBody SMS sms) { |
|
|
|
String mobile = sms.getMobile(); |
|
|
|
if (StringUtils.isEmpty(mobile)) { |
|
|
@@ -30,11 +32,13 @@ public class SmsController { |
|
|
|
} |
|
|
|
Random random = new Random(); |
|
|
|
StringBuffer smscode = new StringBuffer(); |
|
|
|
for (int i = 0; i < 6; i++) { |
|
|
|
smscode.append(random.nextInt(10)); |
|
|
|
} |
|
|
|
smscode.append("123456"); |
|
|
|
// for (int i = 0; i < 6; i++) { |
|
|
|
// smscode.append(random.nextInt(10)); |
|
|
|
// } |
|
|
|
//发送短信 |
|
|
|
String code = SmsUtils.sendNoteMessgae(mobile, String.valueOf(smscode)); |
|
|
|
// String code = SmsUtils.sendNoteMessgae(mobile, String.valueOf(smscode)); |
|
|
|
String code = "OK"; |
|
|
|
if("OK".equals(code)){ |
|
|
|
//返回验证码和发送时间 |
|
|
|
return R.ok().put("smsCode",String.valueOf(smscode)+new Date().getTime()); |
|
|
@@ -63,16 +67,17 @@ 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(); |
|
|
|
} |
|
|
|
// 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(); |
|
|
|
} |
|
|
|
|
|
|
|
} |