|
|
@@ -4,6 +4,7 @@ import com.alibaba.druid.util.StringUtils;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springblade.auth.utils.ImgVerifyCode;
|
|
|
import org.springblade.common.cache.CacheNames;
|
|
|
import org.springblade.common.enums.CommonEnum;
|
|
|
@@ -27,6 +28,7 @@ import java.util.Objects;
|
|
|
@RequestMapping("/verification")
|
|
|
@AllArgsConstructor
|
|
|
@Api(value = "验证码", tags = "验证码相关接口")
|
|
|
+@Slf4j
|
|
|
public class verificationController {
|
|
|
|
|
|
private final RedisUtils redisUtils;
|
|
|
@@ -72,20 +74,32 @@ public class verificationController {
|
|
|
if (Objects.nonNull(redisCode)) {
|
|
|
return R.fail("验证码已发送,请勿重复发送");
|
|
|
}
|
|
|
-// String code = VerificationCodeUtil.getVerificationCode(NumberEnum.SIX.number);
|
|
|
- String code = "123456";
|
|
|
+ String code = VerificationCodeUtil.getVerificationCode(NumberEnum.SIX.number);
|
|
|
+ // String code = "123456";
|
|
|
System.out.println("验证码:" + code);
|
|
|
- String parameter = String.format(CommonEnum.SMS_MSG_TEMPLATE.info, code, "3");
|
|
|
- /*R<SmsResponse> responseR = smsClient.sendMessage("tencent-kbs", parameter, phone);
|
|
|
+ String parameter = String.format(CommonEnum.SMS_MSG_TEMPLATE.info, code, NumberEnum.FIVE.number);
|
|
|
+ R<SmsResponse> responseR = smsClient.sendMessage("tencent-kbs", parameter, phone);
|
|
|
+ if (R.isNotSuccess(responseR)) {
|
|
|
+ log.error("短信发送失败:{}",responseR);
|
|
|
+ return R.fail("短信发送失败,请稍后重试");
|
|
|
+ }
|
|
|
+ System.out.println(JSONObject.toJSONString(responseR));
|
|
|
SmsResponse smsResponse = responseR.getData();
|
|
|
if (ObjectUtils.isEmpty(smsResponse)) {
|
|
|
+ log.error("短信发送失败-data数据为空");
|
|
|
return R.fail("短信发送失败,请稍后重试");
|
|
|
}
|
|
|
- if (org.springframework.util.StringUtils.hasText(smsResponse.getMsg())) {
|
|
|
+ if (!org.springframework.util.StringUtils.hasText(smsResponse.getMsg())) {
|
|
|
+ log.error("短信发送失败-腾讯云短信返回数据为空");
|
|
|
return R.fail("短信发送失败,请稍后重试");
|
|
|
- }*/
|
|
|
- redisUtils.set(CacheNames.APP_LOGIN_CODE_KEY + redisKey, code, NumberEnum.THREE_HUNDRED.number);
|
|
|
- return R.success(code);
|
|
|
+ }
|
|
|
+ JSONObject msgJson = JSONObject.parseObject(smsResponse.getMsg());
|
|
|
+ if (msgJson.getInteger("result") != 0) {
|
|
|
+ log.error("短信发送失败-腾讯云短信发送失败:{}", smsResponse.getMsg());
|
|
|
+ return R.fail("短信发送失败,请稍后重试");
|
|
|
+ }
|
|
|
+ redisUtils.set(CacheNames.APP_LOGIN_CODE_KEY + redisKey, code, NumberEnum.FIVE_HUNDRED.number);
|
|
|
+ return R.success("发送成功,请留意手机短信");
|
|
|
}
|
|
|
|
|
|
}
|