fix
This commit is contained in:
@@ -16,7 +16,7 @@ import java.util.List;
|
||||
@Data
|
||||
public class PlayClerkUserAlbumVo {
|
||||
|
||||
@NotNull(message = "照片不能为空")
|
||||
@Size(min = 1, max = 5, message = "照片必须为1-5张")
|
||||
// @NotNull(message = "照片不能为空")
|
||||
// @Size(min = 1, max = 5, message = "照片必须为1-5张")
|
||||
private List<String> album;
|
||||
}
|
||||
|
||||
@@ -78,8 +78,8 @@ public class PlayClerkUserByWxAddVo {
|
||||
private String audio;
|
||||
|
||||
|
||||
@NotNull(message = "album不能为空")
|
||||
@Size(min = 1, max = 5, message = "照片必须为1-5张")
|
||||
// @NotNull(message = "album不能为空")
|
||||
// @Size(min = 1, max = 5, message = "照片必须为1-5张")
|
||||
private List<String> album;
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.starry.admin.utils;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.starry.common.redis.RedisCache;
|
||||
import com.starry.common.utils.StringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -10,6 +13,7 @@ import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @Author: huchuansai
|
||||
@@ -25,7 +29,7 @@ public class SmsUtils {
|
||||
// 发送短信验证码接口
|
||||
public void sendSmsApi(String phone) {
|
||||
String code = RandomUtil.randomNumbers(4);
|
||||
sendSms(phone, code, "CST_paqequfcmkuv11286");
|
||||
sendSmsV2(phone, code);
|
||||
String key = "sms:phone:" + phone;
|
||||
// 存放到redis里
|
||||
redisCache.setCacheObject(key, code, 10L, java.util.concurrent.TimeUnit.MINUTES);
|
||||
@@ -33,17 +37,17 @@ public class SmsUtils {
|
||||
|
||||
// 校验短信验证码是否正确
|
||||
public void checkSmsCode(String phone, String code) {
|
||||
//if(StringUtils.isEmpty(code)){
|
||||
// throw new RuntimeException("短信验证码必填");
|
||||
//}
|
||||
//String key = "sms:phone:" + phone;
|
||||
//Object data = redisCache.getCacheObject(key);
|
||||
//if (Objects.isNull(data)) {
|
||||
// throw new RuntimeException("短信验证码无效或已过期");
|
||||
//}
|
||||
//if (!code.equals(data.toString())) {
|
||||
// throw new RuntimeException("短信验证码错误");
|
||||
//}
|
||||
if(StringUtils.isEmpty(code)){
|
||||
throw new RuntimeException("短信验证码必填");
|
||||
}
|
||||
String key = "sms:phone:" + phone;
|
||||
Object data = redisCache.getCacheObject(key);
|
||||
if (Objects.isNull(data)) {
|
||||
throw new RuntimeException("短信验证码无效或已过期");
|
||||
}
|
||||
if (!code.equals(data.toString())) {
|
||||
throw new RuntimeException("短信验证码错误");
|
||||
}
|
||||
}
|
||||
|
||||
private static void sendSms(String phone, String code, String templateId) {
|
||||
@@ -69,8 +73,35 @@ public class SmsUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
sendSms("13210055630", "5566", "CST_paqequfcmkuv11286");
|
||||
public static void sendSmsV2(String phone, String code) {
|
||||
String host = "https://dfsns.market.alicloudapi.com";
|
||||
String path = "/data/send_sms";
|
||||
String method = "POST";
|
||||
String appcode = "18639b38538849e1bc8a3413a8d0c0e5";
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Authorization", "APPCODE " + appcode);
|
||||
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
||||
Map<String, String> querys = new HashMap<>();
|
||||
Map<String, String> bodys = new HashMap<>();
|
||||
bodys.put("content", "code:" + code);
|
||||
bodys.put("template_id", "CST_kdnetfmdrsqe11552"); //注意,CST_ptdie100该模板ID仅为调试使用,调试结果为"status": "OK" ,即表示接口调用成功,然后联系客服报备自己的专属签名模板ID,以保证短信稳定下发
|
||||
bodys.put("phone_number", phone);
|
||||
|
||||
try {
|
||||
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
|
||||
HttpEntity entity = response.getEntity();
|
||||
String result = EntityUtils.toString(entity, "UTF-8");
|
||||
log.info("send sms code result:" + result);
|
||||
if (!"ok".equalsIgnoreCase(JSONObject.parseObject(result).getString("status"))) {
|
||||
throw new RuntimeException("发送短信验证码失败,错误信息:" + result);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
sendSmsV2("13210055630", "1234");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user