From 08ee731f013d4406953d28be590864d43ccf61c8 Mon Sep 17 00:00:00 2001 From: "sky.huang" Date: Fri, 9 Jun 2023 17:18:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=20=E4=BA=91=E7=89=87?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E7=9F=AD=E4=BF=A1=20tpl=5Fvalue=20=E4=BC=A0?= =?UTF-8?q?=E9=80=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/script/impl/YunPianSmsScript.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/script/impl/YunPianSmsScript.java b/austin-handler/src/main/java/com/java3y/austin/handler/script/impl/YunPianSmsScript.java index 7ba8bd3..fc590a3 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/script/impl/YunPianSmsScript.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/script/impl/YunPianSmsScript.java @@ -4,6 +4,7 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.core.util.URLUtil; import cn.hutool.http.Header; import cn.hutool.http.HttpRequest; import com.alibaba.fastjson.JSON; @@ -22,7 +23,9 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.net.URLEncoder; import java.util.*; +import java.util.stream.Collectors; /** * @author 3y @@ -37,6 +40,9 @@ public class YunPianSmsScript implements SmsScript { @Autowired private AccountUtils accountUtils; + private static final String PARAMS_SPLIT_KEY = "{|}"; + + private static final String PARAMS_KV_SPLIT_KEY = "{:}"; @Override public List send(SmsParam smsParam) { @@ -78,7 +84,7 @@ public class YunPianSmsScript implements SmsScript { params.put("apikey", account.getApikey()); params.put("mobile", StringUtils.join(smsParam.getPhones(), StrUtil.C_COMMA)); params.put("tpl_id", account.getTplId()); - params.put("tpl_value", ""); + params.put("tpl_value", getTplValue(smsParam)); return params; } @@ -113,5 +119,17 @@ public class YunPianSmsScript implements SmsScript { } + private String getTplValue(SmsParam smsParam) { + String tplValue = ""; + if (StrUtil.isNotBlank(smsParam.getContent())) { + tplValue = StrUtil.split(smsParam.getContent(), PARAMS_SPLIT_KEY).stream().map(item -> { + List kv = StrUtil.splitTrim(item, PARAMS_KV_SPLIT_KEY, 2); + return String.join("=", URLUtil.encodeQuery(kv.get(0)), URLUtil.encodeQuery(kv.get(1))); + }).collect(Collectors.joining("&")); + } + return tplValue; + } + + }