This commit is contained in:
huchuansai
2025-09-01 10:02:14 +08:00
parent dd57c27269
commit fcf8b2d4e8
3 changed files with 49 additions and 18 deletions

View File

@@ -16,7 +16,7 @@ import java.util.List;
@Data @Data
public class PlayClerkUserAlbumVo { public class PlayClerkUserAlbumVo {
@NotNull(message = "照片不能为空") // @NotNull(message = "照片不能为空")
@Size(min = 1, max = 5, message = "照片必须为1-5张") // @Size(min = 1, max = 5, message = "照片必须为1-5张")
private List<String> album; private List<String> album;
} }

View File

@@ -78,8 +78,8 @@ public class PlayClerkUserByWxAddVo {
private String audio; private String audio;
@NotNull(message = "album不能为空") // @NotNull(message = "album不能为空")
@Size(min = 1, max = 5, message = "照片必须为1-5张") // @Size(min = 1, max = 5, message = "照片必须为1-5张")
private List<String> album; private List<String> album;

View File

@@ -1,8 +1,11 @@
package com.starry.admin.utils; package com.starry.admin.utils;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson2.JSONObject;
import com.starry.common.redis.RedisCache; import com.starry.common.redis.RedisCache;
import com.starry.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -10,6 +13,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
/** /**
* @Author: huchuansai * @Author: huchuansai
@@ -25,7 +29,7 @@ public class SmsUtils {
// 发送短信验证码接口 // 发送短信验证码接口
public void sendSmsApi(String phone) { public void sendSmsApi(String phone) {
String code = RandomUtil.randomNumbers(4); String code = RandomUtil.randomNumbers(4);
sendSms(phone, code, "CST_paqequfcmkuv11286"); sendSmsV2(phone, code);
String key = "sms:phone:" + phone; String key = "sms:phone:" + phone;
// 存放到redis里 // 存放到redis里
redisCache.setCacheObject(key, code, 10L, java.util.concurrent.TimeUnit.MINUTES); redisCache.setCacheObject(key, code, 10L, java.util.concurrent.TimeUnit.MINUTES);
@@ -33,17 +37,17 @@ public class SmsUtils {
// 校验短信验证码是否正确 // 校验短信验证码是否正确
public void checkSmsCode(String phone, String code) { public void checkSmsCode(String phone, String code) {
//if(StringUtils.isEmpty(code)){ if(StringUtils.isEmpty(code)){
// throw new RuntimeException("短信验证码必填"); throw new RuntimeException("短信验证码必填");
//} }
//String key = "sms:phone:" + phone; String key = "sms:phone:" + phone;
//Object data = redisCache.getCacheObject(key); Object data = redisCache.getCacheObject(key);
//if (Objects.isNull(data)) { if (Objects.isNull(data)) {
// throw new RuntimeException("短信验证码无效或已过期"); throw new RuntimeException("短信验证码无效或已过期");
//} }
//if (!code.equals(data.toString())) { if (!code.equals(data.toString())) {
// throw new RuntimeException("短信验证码错误"); throw new RuntimeException("短信验证码错误");
//} }
} }
private static void sendSms(String phone, String code, String templateId) { private static void sendSms(String phone, String code, String templateId) {
@@ -69,8 +73,35 @@ public class SmsUtils {
} }
} }
public static void main(String[] args) { public static void sendSmsV2(String phone, String code) {
sendSms("13210055630", "5566", "CST_paqequfcmkuv11286"); 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");
}
} }