1.申请阿里云账号,获取签名模板和key和id
具体代码实现
package com.ezeyc.edpbfqz.api.controller;
import com.ezeyc.edpbase.util.RedisUtil;
import com.ezeyc.edpbfqz.domain.BfqzDrainage;
import com.ezeyc.edpbfqz.service.BfqzUserService;
import com.ezeyc.edpbfqz.service.DrainageService;
import com.ezeyc.edpcommon.pojo.ResultBody;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 描述:缤纷趣租-app用户中心接口控制器
* 小程序-引流服务接口
*
* @author hrj
* @date 2021-05-31 15:54:25
*/
@Api(tags = "C端-引流服务")
@RequestMapping("drainage")
@RestController
@RequiredArgsConstructor(onConstructor_ = {
@Autowired})
@Slf4j
public class DrainageController {
private final BfqzUserService userService;
private final RedisUtil redisUtil;
private final DrainageService service;
/**
* 发送验证码
* @param phone 手机号
* @return
*/
@PostMapping("sendCode")
public ResultBody sendCode(String phone) {
try {
return ResultBody.success(userService.sendCode(phone));
}catch (Exception e) {
return ResultBody.failed(e.getMessage());
}
}
/**
* 登录
* @param phone 手机号
* @param code 验证码
* @return
*/
@PostMapping("checkCode")
public ResultBody checkCode(String phone, String code) {
String oldCode = redisUtil.get(phone);
if (!code.equals(oldCode)) {
return ResultBody.failed("登录失败,请输入正确的验证码");
}
return ResultBody.success("OK");
}
@PostMapping("drainage")
public ResultBody drainage(BfqzDrainage bfqzDrainage) {
return ResultBody.success(service.drainage(bfqzDrainage));
}
}
2.实现类
@Override
public Object sendCode(String phone) {
if (StringUtils.isNotBlank(phone)) {
String oldCode = redisUtil.get(phone);
if (StringUtils.isNotBlank