package com.ruoyi.chargingPile.controller;
|
|
import com.ruoyi.account.api.feignClient.AppUserClient;
|
import com.ruoyi.account.api.model.TAppUser;
|
import com.ruoyi.chargingPile.api.model.TChargingPile;
|
import com.ruoyi.chargingPile.service.TChargingPileNotificationService;
|
import com.ruoyi.common.core.constant.Constants;
|
import com.ruoyi.common.core.constant.MsgConstants;
|
import com.ruoyi.common.core.utils.HttpUtils;
|
import com.ruoyi.common.core.utils.MsgUtil;
|
import com.ruoyi.common.core.web.domain.AjaxResult;
|
import com.ruoyi.common.redis.service.RedisService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.util.Objects;
|
import java.util.concurrent.TimeUnit;
|
|
@RestController
|
@RequestMapping("/code")
|
public class CodeController {
|
|
@Autowired
|
private RedisService redisService;
|
@Autowired
|
private AppUserClient appUserClient;
|
@Autowired
|
private TChargingPileNotificationService chargingPileNotificationService;
|
|
/**
|
* 获取验证码
|
*
|
* @param phone 手机号
|
* @return 结果
|
*/
|
@ApiOperation(value = "获取验证码",notes = "获取验证码",tags = {"更换手机号获取验证码"})
|
@GetMapping("/getCode")
|
public AjaxResult getCode(@RequestParam("phone") String phone)
|
{
|
TAppUser appUser = appUserClient.selectByPhone(phone).getData();
|
if (Objects.nonNull(appUser)){
|
return AjaxResult.error("该手机号已绑定账号");
|
}
|
String code = MsgUtil.createCode();
|
redisService.setCacheObject(phone+ Constants.UPDATE_PHONE,code,5L, TimeUnit.MINUTES);
|
String reqStr = MsgUtil.codeMsg(phone, code);
|
String result = HttpUtils.post(MsgConstants.SEND_URL, reqStr);
|
// 记录短信发送
|
chargingPileNotificationService.saveData(1,-1,-1,phone,"验证码:"+code+",用于更换手机号。请勿转发。");
|
return AjaxResult.success(result);
|
}
|
|
/**
|
* 获取验证码
|
*
|
* @param phone 手机号
|
* @return 结果
|
*/
|
@ApiOperation(value = "获取验证码",notes = "获取验证码",tags = {"申请建桩获取验证码"})
|
@GetMapping("/getApplyCode")
|
public AjaxResult getApplyCode(@RequestParam("phone") String phone)
|
{
|
String code = MsgUtil.createCode();
|
redisService.setCacheObject(phone+ Constants.APPLY_CHARGING,code,5L, TimeUnit.MINUTES);
|
String reqStr = MsgUtil.applyCodeMsg(phone, code);
|
String result = HttpUtils.post(MsgConstants.SEND_URL, reqStr);
|
// 记录短信发送
|
chargingPileNotificationService.saveData(1,-1,-1,phone,"验证码:"+code+",用于申请建桩。请勿转发。");
|
return AjaxResult.success(result);
|
}
|
|
}
|