|
@@ -26,21 +26,35 @@ import java.nio.charset.Charset;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.regex.Pattern;
|
|
|
-
|
|
|
+@Component
|
|
|
public class HwSmsUtil {
|
|
|
|
|
|
//无需修改,用于格式化鉴权头域,给"X-WSSE"参数赋值
|
|
|
private static final String WSSE_HEADER_FORMAT = "UsernameToken Username=\"%s\",PasswordDigest=\"%s\",Nonce=\"%s\",Created=\"%s\"";
|
|
|
//无需修改,用于格式化鉴权头域,给"Authorization"参数赋值 8823102504763 7133b7ce87a84896a143b02edf5a4757
|
|
|
private static final String AUTH_HEADER_VALUE = "WSSE realm=\"SDP\",profile=\"UsernameToken\",type=\"Appkey\"";
|
|
|
- private static final String SENDER = "8824011624825";
|
|
|
- private static final String TEMPLATE_ID = "0b30545363dd4d3d910ed73aa23dfe92";
|
|
|
-// @Value("${hw.sender:#{null}}")
|
|
|
-// private String senderNo;8824011624825
|
|
|
-// static String SENDER; 0b30545363dd4d3d910ed73aa23dfe92
|
|
|
-// @Value("${hw.templateid:#{null}}")
|
|
|
-// private String templateId;
|
|
|
-// static String TEMPLATE_ID;
|
|
|
+// private static final String SENDER = "8824011624825";
|
|
|
+// private static final String TEMPLATE_ID = "0b30545363dd4d3d910ed73aa23dfe92";
|
|
|
+ @Value("${hwSms.sender:#{null}}")
|
|
|
+ private String senderNo;
|
|
|
+ @Value("${hwSms.templateid:#{null}}")
|
|
|
+ private String templateId;
|
|
|
+ @Value("${hwSms.appkey:#{null}}")
|
|
|
+ private String appkey;
|
|
|
+ @Value("${hwSms.appSecret:#{null}}")
|
|
|
+ private String appSecret;
|
|
|
+ private static String SENDER;
|
|
|
+ private static String TEMPLATE_ID;
|
|
|
+ private static String APPKEY;
|
|
|
+ private static String APPSECRET;
|
|
|
+
|
|
|
+ @PostConstruct
|
|
|
+ public void init() {
|
|
|
+ SENDER = senderNo;
|
|
|
+ TEMPLATE_ID = templateId;
|
|
|
+ APPKEY = appkey;
|
|
|
+ APPSECRET = appSecret;
|
|
|
+ }
|
|
|
//
|
|
|
// @PostConstruct
|
|
|
// public void init() {
|
|
@@ -68,9 +82,9 @@ public class HwSmsUtil {
|
|
|
*/
|
|
|
public static JSONObject sendSms(String templateId,String sender, List<String> code, String phone) throws Exception{
|
|
|
//必填,请参考"开发准备"获取如下数据,替换为实际值
|
|
|
- String url = "https://smsapi.cn-south-1.myhuaweicloud.com:443/sms/batchSendSms/v1"; //APP接入地址+接口访问URI
|
|
|
- String appKey = "iZA4u69023CpkvGGxrXxrBuNMp1B"; //APP_Key
|
|
|
- String appSecret = "CRZrS3exn54u6xL9he0s7Vi4ihR3"; //APP_Secret
|
|
|
+ String url = "https://smsapi.cn-south-1.myhuaweicloud.com:443/sms/batchSendSms/v1";
|
|
|
+ String appKey = APPKEY;
|
|
|
+ String appSecret = APPSECRET;
|
|
|
if (StringUtils.isBlank(templateId)) {
|
|
|
templateId = TEMPLATE_ID;
|
|
|
}
|