手机验证码登录

This commit is contained in:
齐天大圣 2023-11-24 17:24:10 +08:00
parent f6a9d94364
commit 92d425f57c
8 changed files with 204 additions and 14 deletions

View File

@ -85,12 +85,12 @@
<span v-if="scope.row.timeType == 2" >领券后第{{ scope.row.validityDay}}天生效</span>
</template>
</el-table-column>
<el-table-column label="生效时间" align="center" prop="effectiveDateType" >
<!-- <el-table-column label="生效时间" align="center" prop="effectiveDateType" >
<template slot-scope="scope">
<span v-if="scope.row.effectiveDateType == 0" >领取时间</span>
<span v-if="scope.row.effectiveDateType == 1" >指定{{scope.row. effectiveDateStart}}</span>
</template>
</el-table-column>
</el-table-column>-->
<el-table-column label="发放数量" align="center" prop="count" />
<el-table-column label="满足金额" align="center" prop="satisfiedAmount" />
<el-table-column label="二维码链接" align="center" prop="qrCodeLink" >
@ -218,20 +218,20 @@
<!-- <el-form-item label="满减金额" prop="fullDeduction">-->
<!-- <el-input v-model="form.fullDeduction" placeholder="请输入满减金额" />-->
<!-- </el-form-item>-->
<el-form-item label="生效时间" prop="effectiveDateType">
<!-- <el-form-item label="生效时间" prop="effectiveDateType">
<el-radio-group v-model="form.effectiveDateType">
<el-radio label="0">领取时间</el-radio>
<el-radio label="1">指定时间</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="生效时间" v-if="form.effectiveDateType == 1" prop="effectiveDateStart">
</el-form-item>-->
<!-- <el-form-item label="生效时间" v-if="form.effectiveDateType == 1" prop="effectiveDateStart">
<el-time-picker
arrow-control
v-model="form.effectiveDateStart"
placeholder="任意时间点">
</el-time-picker>
</el-form-item>
</el-form-item>-->
<el-form-item label="可用时段" prop="availablePeriod">
<el-checkbox-group v-model="form.availablePeriod">
<el-checkbox-button v-for="city in cities" :label="city" :key="city">{{city}}</el-checkbox-button>

View File

@ -165,6 +165,18 @@
<version>1.4</version>
</dependency>
<!-- 阿里云手机验证码-->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.5.16</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-dysmsapi</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>
<build>

View File

@ -28,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -161,7 +162,9 @@ public class ActiveExchangeServiceImpl implements ActiveExchangeService {
MaxoutVO maxoutVO = new MaxoutVO();
// 会员等级判断符合油号判断
if (activeFullminus.getDieselUserLevel().contains(String.valueOf(userGradeService.selectUserGradeById(transferDTO.getGradeId()).getId())) &&
activeFullminus.getAdaptOil().contains(String.valueOf(transferDTO.getOilName()))){
activeFullminus.getAdaptOil().contains(String.valueOf(transferDTO.getOilName())) &&
activeFullminus.getActiveStartTime().getTime()<=new Date().getTime() &&
new Date().getTime()<=activeFullminus.getActiveEndTime().getTime()){
BeanUtils.copyProperties(activeFullminus,maxoutVO);
LambdaQueryWrapper<ActiveDiscountChild> queryWrappers = new LambdaQueryWrapper<>();
queryWrappers.eq(ActiveDiscountChild::getActiveFullminusId,activeFullminus.getId());
@ -186,7 +189,9 @@ public class ActiveExchangeServiceImpl implements ActiveExchangeService {
MaxoutVO maxoutVO = new MaxoutVO();
// 会员等级判断符合油号判断
if (activeDiscount.getDieselUserLevel().contains(String.valueOf(userGradeService.selectUserGradeById(transferDTO.getGradeId()).getId())) &&
activeDiscount.getAdaptOil().contains(String.valueOf(transferDTO.getOilName()))){
activeDiscount.getAdaptOil().contains(String.valueOf(transferDTO.getOilName()))&&
activeDiscount.getActiveStartTime().getTime()<=new Date().getTime() &&
new Date().getTime()<=activeDiscount.getActiveEndTime().getTime()){
BeanUtils.copyProperties(activeDiscount,maxoutVO);
LambdaQueryWrapper<ActiveDiscountChild> queryWrappers = new LambdaQueryWrapper<>();
queryWrappers.eq(ActiveDiscountChild::getActiveDiscountId,activeDiscount.getId());
@ -218,7 +223,23 @@ public class ActiveExchangeServiceImpl implements ActiveExchangeService {
cardFavorableLambdaQueryWrapper.le(CardFavorable::getSatisfiedAmount,transferDTO.getOilPrice() * transferDTO.getOilLiters());
List<CardFavorable> list1 = cardFavorableService.list(cardFavorableLambdaQueryWrapper);
if (list1.size()>0){
BeanUtils.copyProperties(list1.get(0), exchangeFavorableVO);
CardFavorable cardFavorable = list1.get(0);
if (cardFavorable.getTimeType().equals("0") &&
new Date().getTime()<=cardFavorable.getCreateTime().getTime()+ 86400000L * cardFavorable.getValidityZero() ){
BeanUtils.copyProperties(cardFavorable, exchangeFavorableVO);
}
if (cardFavorable.getTimeType().equals("1") &&
new Date().getTime()<=cardFavorable.getEffectiveDate().getTime()+ 86400000L * cardFavorable.getValidityOne() ){
BeanUtils.copyProperties(cardFavorable, exchangeFavorableVO);
}
if (cardFavorable.getTimeType().equals("2") &&
new Date().getTime() >= cardFavorable.getCreateTime().getTime() + Integer.parseInt(cardFavorable.getValidityDay()) * 86400000L &&
new Date().getTime() <= cardFavorable.getCreateTime().getTime() + Integer.parseInt(cardFavorable.getValidityDay()) * 86400000L + 86400000L * cardFavorable.getValidityTwo()){
BeanUtils.copyProperties(cardFavorable, exchangeFavorableVO);
}
/*if (){
}*/
exchangeFavorableVOArrayList.add(exchangeFavorableVO);
}
}

View File

@ -7,9 +7,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuint.business.marketingActivity.cardExchange.mapper.CardExchangeRecordMapper;
import com.fuint.business.marketingActivity.cardExchange.entity.CardExchangeRecord;
import com.fuint.business.marketingActivity.cardExchange.service.CardExchangeRecordService;
import com.fuint.business.store.service.StoreService;
import com.fuint.common.util.TokenUtil;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* 兑换券领取记录表(CardExchangeRecord)表服务实现类
*
@ -18,7 +22,8 @@ import org.springframework.stereotype.Service;
*/
@Service("cardExchangeRecordService")
public class CardExchangeRecordServiceImpl extends ServiceImpl<CardExchangeRecordMapper, CardExchangeRecord> implements CardExchangeRecordService {
@Resource
private StoreService storeService;
/**
* 分页查询
* @param page
@ -27,6 +32,11 @@ public class CardExchangeRecordServiceImpl extends ServiceImpl<CardExchangeRecor
*/
@Override
public IPage select(Page page, CardExchangeRecord cardExchangeRecord) {
//获取当前店铺的id和连锁店id
if (ObjectUtils.isNotEmpty(TokenUtil.getNowAccountInfo().getStoreId())) {
cardExchangeRecord.setStoreId(TokenUtil.getNowAccountInfo().getStoreId());
cardExchangeRecord.setChainStorId(storeService.getById(TokenUtil.getNowAccountInfo().getStoreId()).getChainStoreId());
}
//构建查询条件
LambdaQueryWrapper<CardExchangeRecord> queryWrapper = new LambdaQueryWrapper<>();
if(ObjectUtils.isNotEmpty(cardExchangeRecord.getExchangeName())){
@ -41,6 +51,7 @@ public class CardExchangeRecordServiceImpl extends ServiceImpl<CardExchangeRecor
if(ObjectUtils.isNotEmpty(cardExchangeRecord.getTicketCode())) {
queryWrapper.eq(CardExchangeRecord::getTicketCode,cardExchangeRecord.getTicketCode());
}
queryWrapper.eq(CardExchangeRecord::getStoreId,cardExchangeRecord.getStoreId());
queryWrapper.orderByDesc(CardExchangeRecord::getCreateTime);
return page(page, queryWrapper);
}
@ -53,6 +64,11 @@ public class CardExchangeRecordServiceImpl extends ServiceImpl<CardExchangeRecor
*/
@Override
public IPage selectIsUsed(Page page, CardExchangeRecord cardExchangeRecord) {
//获取当前店铺的id和连锁店id
if (ObjectUtils.isNotEmpty(TokenUtil.getNowAccountInfo().getStoreId())) {
cardExchangeRecord.setStoreId(TokenUtil.getNowAccountInfo().getStoreId());
cardExchangeRecord.setChainStorId(storeService.getById(TokenUtil.getNowAccountInfo().getStoreId()).getChainStoreId());
}
//构建查询条件
LambdaQueryWrapper<CardExchangeRecord> queryWrapper = new LambdaQueryWrapper<>();
if(ObjectUtils.isNotEmpty(cardExchangeRecord.getExchangeName())){
@ -70,6 +86,7 @@ public class CardExchangeRecordServiceImpl extends ServiceImpl<CardExchangeRecor
if (ObjectUtils.isNotEmpty(cardExchangeRecord.getStartTime()) && ObjectUtils.isNotEmpty(cardExchangeRecord.getEndTime()) ) {
queryWrapper.between(CardExchangeRecord::getCancelTime,cardExchangeRecord.getStartTime(),cardExchangeRecord.getEndTime());
}
queryWrapper.eq(CardExchangeRecord::getStoreId,cardExchangeRecord.getStoreId());
queryWrapper.orderByDesc(CardExchangeRecord::getCreateTime);
return page(page, queryWrapper);
}

View File

@ -31,7 +31,9 @@ public class ShiroConfig {
filter.setFilters(filters);
LinkedHashMap<String,String> filterMap=new LinkedHashMap<>();
filterMap.put("/backendApi/login/doLogin","anon");
filterMap.put("/backendApi/login/sendMsg","anon");
filterMap.put("/clientApi/captcha/getCode","anon");
filterMap.put("/backendApi/login/loginByPhone","anon");
filterMap.put("/static/**","anon");
//会员模板导出
filterMap.put("/excel/export","anon");

View File

@ -0,0 +1,38 @@
package com.fuint.common.util;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
/**
* 短信发送工具类
*/
public class SMSUtils {
/**
* 发送短信
* @param signName 签名
* @param templateCode 模板
* @param phoneNumbers 手机号
* @param param 参数
*/
public static void sendMessage(String signName, String templateCode,String phoneNumbers,String param){
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "", "");
IAcsClient client = new DefaultAcsClient(profile);
SendSmsRequest request = new SendSmsRequest();
request.setSysRegionId("cn-hangzhou");
request.setPhoneNumbers(phoneNumbers);
request.setSignName(signName);
request.setTemplateCode(templateCode);
request.setTemplateParam("{\"code\":\""+param+"\"}");
try {
SendSmsResponse response = client.getAcsResponse(request);
System.out.println("短信发送成功"+response);
}catch (ClientException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,49 @@
package com.fuint.common.util;
import java.util.Random;
public class ValidateCodeUtils {
/**
* 随机生成验证码
* @param a
* @return
*/
public static String verificationCode(int a) {
// 定义一个空字符串
String verification_code = "";
// 创建Random对象
Random r = new Random();
for (int i = 0; i < a; i++) {
// 确定字符类型(0代表数字1代表大写字母2代表小写字母)
int type = r.nextInt(3);
switch (type) {
case 0:
// 随机生成一个0~9数字
verification_code += r.nextInt(10);
break;
case 1:
// 随机生成一个65~90的数字然后强转为大写字母
verification_code += (char) (r.nextInt(26) + 65);
break;
case 2:
// 随机生成一个97~122的数字然后强转为小写字母
verification_code += (char) (r.nextInt(26) + 97);
break;
}
}
return verification_code;
}
/**
* 随机生成指定长度字符串验证码
* @param length 长度
* @return
*/
public static String generateValidateCode4String(int length){
Random rdm = new Random();
String hash1 = Integer.toHexString(rdm.nextInt());
String capstr = hash1.substring(0, length);
return capstr;
}
}

View File

@ -1,15 +1,17 @@
package com.fuint.module.backendApi.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.api.R;
import com.fuint.common.dto.AccountInfo;
import com.fuint.common.dto.UserDto;
import com.fuint.common.enums.AdminRoleEnum;
import com.fuint.common.service.*;
import com.fuint.common.util.TokenUtil;
import com.fuint.common.util.TreeUtil;
import com.fuint.common.util.*;
import com.fuint.common.vo.RouterVo;
import com.fuint.framework.annoation.OperationServiceLog;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.module.backendApi.request.LoginRequest;
import com.fuint.common.util.Constants;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.ResponseObject;
import com.fuint.module.backendApi.response.LoginResponse;
@ -23,11 +25,15 @@ import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import com.fuint.common.domain.TreeNode;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* 后台登录接口
@ -64,6 +70,9 @@ public class BackendLoginController extends BaseController {
@Resource
private CaptchaService captchaService;
@Autowired
public RedisTemplate redisTemplate;
/**
* 后台登录
* */
@ -110,8 +119,50 @@ public class BackendLoginController extends BaseController {
}
/**
* 获取登录信息接口
* 后台登录
* */
@ApiOperation(value = "发送手机验证码")
@RequestMapping(value="/sendMsg", method = RequestMethod.POST)
@OperationServiceLog(description = "发送手机验证码")
public ResponseObject sendMsg(@RequestBody UserDto userDto) {
//获取手机号
String phone = userDto.getMobile();
if(StringUtils.isNotEmpty(phone)){
//生成随机的四位验证码
String code = ValidateCodeUtils.verificationCode(4);
//调用阿里云提供的短信服务API完成发送短信
SMSUtils.sendMessage("蓝鲸智慧油站","SMS_154950909",phone,code);
//需要将生成的验证码保存到redis,过期时间60s
redisTemplate.opsForValue().set(phone,code,60, TimeUnit.SECONDS);
return getSuccessResult("手机验证码发送成功");
}
return getFailureResult("短信发送失败");
}
/**
*
* @param map
* @param session
* @return
*/
@PostMapping("/loginByPhone")
public ResponseObject loginByPhone(@RequestBody Map map) {
//获取手机号 1234
String phone = map.get("mobile").toString();
//获取验证码
String code = map.get("code").toString();
//从redis中获取保存的验证码
Object codeInRedis = redisTemplate.opsForValue().get(phone);
//进行验证码的比对
if (codeInRedis != null && codeInRedis.equals(code)) {
//如果能够比对成功说明登录成功
return getSuccessResult("登录成功!");
}
return getFailureResult("登录失败,请输入正确的验证码");
}
/**
* 获取登录信息接口
* */
@ApiOperation(value = "获取登录信息")
@RequestMapping(value = "/getInfo", method = RequestMethod.GET)
public ResponseObject getInfo(HttpServletRequest request) throws BusinessCheckException {