This commit is contained in:
wangjinlei
2023-11-07 17:14:15 +08:00
parent 5b71036241
commit a152865cfe
10 changed files with 42 additions and 29 deletions

View File

@@ -0,0 +1,15 @@
package com.peanut.common.utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TelUtil {
public static boolean isPhone(String Phone_number) {
String regex = "^((13[0-9])|(14(0|[5-7]|9))|(15([0-3]|[5-9]))|(16(2|[5-7]))|(17[0-8])|(18[0-9])|(19([0-3]|[5-9])))\\d{8}$";
Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(Phone_number);
return m.matches();
}
}

View File

@@ -13,5 +13,6 @@ public class SMSConfig {
private String accessKeySecret;
private String singName;
private String templateCode;
private String sTemplateCode;//国际短信模版
}

View File

@@ -17,14 +17,9 @@ import com.peanut.modules.book.entity.*;
import com.peanut.modules.book.service.*;
import com.peanut.modules.book.to.PageIdDto;
import com.peanut.modules.sys.service.SysUserTokenService;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.models.auth.In;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -173,6 +168,7 @@ public class MyUserController {
@RequestMapping("/sms/sendcode")
public R registerSms(@RequestParam("phone") String phone) throws Exception {
//验证一分钟内是否已经发过
String redisCode = redisTemplate.opsForValue().get("RegistCode" + phone);
if (!StringUtils.isEmpty(redisCode)) {
long l = Long.parseLong(redisCode.split("_")[1]);
@@ -181,20 +177,21 @@ public class MyUserController {
return R.error(500,"短信验证码频率过高,请稍后再试!");
}
}
//生成随机五位数
Random random = new Random();
String i = random.nextInt(99999) + "";//生成字符串
String i = random.nextInt(99999) + "";
StringBuffer sb = new StringBuffer();
for (int j = 0; j < 5 - i.length(); j++) {
sb.append("0");//不足5位就行补0
sb.append("0");
}
i = sb.toString() + i;
// String code = UUID.randomUUID().toString().substring(0,5)+"_"+System.currentTimeMillis();
String code = i + "_"+System.currentTimeMillis();
//redis 缓存验证码
redisTemplate.opsForValue().set("RegistCode"+phone,code,5, TimeUnit.MINUTES);
//防止同一个手机号 60s 内再次发送
//发送
userService.sendCodeForRegister(phone,code);
return R.ok();

View File

@@ -394,9 +394,10 @@ public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> impl
private void sendCode(String phone, String code) throws Exception {
com.aliyun.dysmsapi20170525.Client client = Sample.createClient(smsConfig.getAccessKeyId(),smsConfig.getAccessKeySecret());
String tem = TelUtil.isPhone(phone)?smsConfig.getTemplateCode():smsConfig.getSTemplateCode();//通过手机号判断是否为国内手机号,并设置模版
SendSmsRequest sendSmsRequest = new SendSmsRequest()
.setSignName(smsConfig.getSingName())
.setTemplateCode(smsConfig.getTemplateCode())
.setTemplateCode(tem)
.setPhoneNumbers(phone)
.setTemplateParam("{\"code\":\""+ code +"\"}");
RuntimeOptions runtime = new RuntimeOptions();

View File

@@ -20,12 +20,12 @@ public class PointCategoryServiceImpl extends ServiceImpl<PointCategoryDao, Poin
public List<PointCategoryEntity> getCategoryList() {
LambdaQueryWrapper<PointCategoryEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PointCategoryEntity::getPid,0);
wrapper.orderByDesc(PointCategoryEntity::getSort);
wrapper.orderByAsc(PointCategoryEntity::getSort);
List<PointCategoryEntity> list = list(wrapper);
for (PointCategoryEntity p : list){
LambdaQueryWrapper<PointCategoryEntity> wrapper1 = new LambdaQueryWrapper<>();
wrapper1.eq(PointCategoryEntity::getPid,p.getId());
wrapper1.orderByDesc(PointCategoryEntity::getSort);
wrapper1.orderByAsc(PointCategoryEntity::getSort);
List<PointCategoryEntity> list1 = list(wrapper1);
p.setChildren(list1);
}

View File

@@ -36,12 +36,11 @@ public class PointServiceImpl extends ServiceImpl<PointDao, PointEntity> impleme
createIds(id,ids);
wrapper.in(PointEntity::getPointCategoryId,ids);
}
wrapper.orderByDesc(PointEntity::getSort);
wrapper.orderByAsc(PointEntity::getSort);
Page<PointEntity> pointEntityPage = getBaseMapper().selectPage(new Page<>(page, limit), wrapper);
for (PointEntity p : pointEntityPage.getRecords()){
p.setImageList(JSON.parseArray(p.getImages(),String.class));
PointCategoryEntity c_category = pointCategoryDao.selectById(p.getPointCategoryId());
System.out.println(c_category);
PointCategoryEntity f_category = pointCategoryDao.selectById(c_category.getPid());
p.setCategoryString(f_category.getTitle()+" > "+c_category.getTitle());
}
@@ -60,7 +59,7 @@ public class PointServiceImpl extends ServiceImpl<PointDao, PointEntity> impleme
public List<PointEntity> searchPoint(String keywords) {
LambdaQueryWrapper<PointEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.like(PointEntity::getTitle,keywords);
wrapper.orderByDesc(PointEntity::getSort);
wrapper.orderByAsc(PointEntity::getSort);
List<PointEntity> list = list(wrapper);
return list;
}
@@ -68,7 +67,7 @@ public class PointServiceImpl extends ServiceImpl<PointDao, PointEntity> impleme
private void createIds(Integer id, List<Integer> list){
LambdaQueryWrapper<PointCategoryEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PointCategoryEntity::getPid,id);
wrapper.orderByDesc(PointCategoryEntity::getSort);
wrapper.orderByAsc(PointCategoryEntity::getSort);
List<PointCategoryEntity> pointCategoryEntities = pointCategoryDao.selectList(wrapper);
for (PointCategoryEntity p :pointCategoryEntities){
createIds(p.getId(),list);

View File

@@ -65,9 +65,9 @@ aliyun:
sms:
accessKeyId: LTAI5tJbbw5fY97pnw635yq3
accessKeySecret: LTXQ9v3OYVwNVbDWWfVpbbcVDKErKi
singName: 疯子读书
singName: 疯子读书国际
templateCode: SMS_248840040
sTemplateCode: SMS_463780139
server:
port: 9200

View File

@@ -65,9 +65,9 @@ aliyun:
sms:
accessKeyId: LTAI5tJbbw5fY97pnw635yq3
accessKeySecret: LTXQ9v3OYVwNVbDWWfVpbbcVDKErKi
singName: 疯子读书
singName: 疯子读书国际
templateCode: SMS_248840040
sTemplateCode: SMS_463780139
server:
port: 9100

View File

@@ -11,7 +11,7 @@ connection-timeout: 6000000ms
spring:
# 环境 dev|test|prod
profiles:
active: dev
active: prod
# jackson时间格式化
jackson:
time-zone: GMT+8

View File

@@ -5,22 +5,22 @@ wxpay.mchId:1612860909
# ?? URL
wxpay.payUrl:https://api.mch.weixin.qq.com/v3/pay/transactions/app
# ????
wxpay.notifyUrl:https://testapi.nuttyreading.com/pay/payNotify
wxpay.notifyUrl:https://api.nuttyreading.com/pay/payNotify
# ?? url
wxpay.refundNotifyUrl:http://pjm6m9.natappfree.cc/pay/refundNotify
# key pem
#wxpay.keyPemPath:/usr/local/hs/peanut_book/target/classes/cent/apiclient_key.pem
wxpay.keyPemPath:/usr/local/hs/peanut_book/target/classes/cent/apiclient_key.pem
#wxpay.keyPemPath:C:/Users/Cauchy/IdeaProjects/nuttyreading-java/src/main/resources/cent/apiclient_key.pem
wxpay.keyPemPath:D:/hs/nuttyreading-java/src/main/resources/cent/apiclient_key.pem
#wxpay.keyPemPath:D:/hs/nuttyreading-java/src/main/resources/cent/apiclient_key.pem
# ???
wxpay.serialNo:679AECB2F7AC4183033F713828892BA640E4EEE3
# API v3 key
wxpay.apiV3Key:4aYFklzaULeGlr7oJPZ6rHWKcxjihZUF
# ????
#wxpay.wechatPayCertificateUrl:/usr/local/hs/peanut_book/target/classes/cent/wechatpay_7B5676E3CDF56680D0414A009CE501C844DBE2D6.pem
wxpay.wechatPayCertificateUrl:/usr/local/hs/peanut_book/target/classes/cent/wechatpay_7B5676E3CDF56680D0414A009CE501C844DBE2D6.pem
#wxpay.wechatPayCertificateUrl:C:/Users/Cauchy/IdeaProjects/nuttyreading-java/src/main/resources/cent/wechatpay_7B5676E3CDF56680D0414A009CE501C844DBE2D6.pem
wxpay.wechatPayCertificateUrl:D:/hs/nuttyreading-java/src/main/resources/cent/wechatpay_7B5676E3CDF56680D0414A009CE501C844DBE2D6.pem
# wxpay.wechatPayCertificateUrl:D:/hs/nuttyreading-java/src/main/resources/cent/wechatpay_7B5676E3CDF56680D0414A009CE501C844DBE2D6.pem
# ?? url
#wxpay.privateKeyUrl:/usr/local/hs/peanut_book/target/classes/cent/apiclient_key.pem
wxpay.privateKeyUrl:/usr/local/hs/peanut_book/target/classes/cent/apiclient_key.pem
#wxpay.privateKeyUrl:C:/Users/Cauchy/IdeaProjects/nuttyreading-java/src/main/resources/cent/apiclient_key.pem
wxpay.privateKeyUrl:D:/hs/nuttyreading-java/src/main/resources/cent/apiclient_key.pem
#wxpay.privateKeyUrl:D:/hs/nuttyreading-java/src/main/resources/cent/apiclient_key.pem