package com.gk.hotwork.Sms.Supplier;
|
|
import cn.hutool.crypto.symmetric.AES;
|
import com.alibaba.fastjson.JSONObject;
|
import com.gk.hotwork.Domain.Exception.BusinessException;
|
import com.gk.hotwork.Domain.Utils.HttpUtils;
|
import com.gk.hotwork.Sms.Supplier.Abstract.Supplier;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.stereotype.Component;
|
|
import java.security.MessageDigest;
|
import java.security.NoSuchAlgorithmException;
|
import java.util.HashMap;
|
import java.util.Map;
|
/**
|
* @Description: 聚合
|
* @date 2022/5/18 16:49
|
*/
|
@Component("jh")
|
@ConfigurationProperties(prefix = "sms.supplier.jh")
|
public class Jh extends Supplier {
|
|
|
private AES aes = new AES("CBC", "PKCS7Padding",
|
// 密钥,不可更改
|
"kikokiko00012345".getBytes(),
|
// iv加盐
|
"wakuwaku00012345".getBytes());
|
|
public boolean sendSms(String mobile, String tplId, Map<String,Object> paramsContent) {
|
try {
|
Map<String, Object> params = new HashMap<>();
|
params.put("mobile", mobile);//接收短信的手机号码
|
params.put("tpl_id", tplId);//短信模板ID,请参考个人中心短信模板设置
|
StringBuilder sb = new StringBuilder();
|
for (Map.Entry<String, Object> entry : paramsContent.entrySet()) {
|
//包含特殊字符# 使用转义字符代替
|
String value = entry.getValue().toString().replace("#", "%23");
|
sb.append("&#").append(entry.getKey())
|
.append("#=").append(value);
|
}
|
params.put("tpl_value", sb.deleteCharAt(0).toString());
|
params.put("key", this.keyDecoder(this.getKey()));//应用APPKEY(应用详细页查询)
|
params.put("dtype", "json");//返回数据的格式,xml或json,默认json
|
String response = HttpUtils.net(this.getUrl(), params, "GET");
|
JSONObject jsonResult = JSONObject.parseObject(response);
|
String errorCode = jsonResult.getString("error_code");
|
String reason = jsonResult.getString("reason");
|
if ("0".equals(errorCode)) {
|
return true;
|
} else {
|
throw new BusinessException(reason);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
throw new BusinessException("系统错误");
|
}
|
}
|
|
@Override
|
public String keyDecoder(String key) {
|
return aes.decryptStr(key);
|
}
|
|
|
}
|