commit
36840c2e88
@ -0,0 +1,46 @@
|
||||
package com.java3y.austin.common.dto.account.sms;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* <span>Form File</span>
|
||||
* <p>Description</p>
|
||||
* <p>Company:QQ 752340543</p>
|
||||
*
|
||||
* @author topsuder
|
||||
* @version v1.0.0
|
||||
* @DATE 2022/11/24-14:39
|
||||
* @Description
|
||||
* @see com.java3y.austin.common.dto.account austin
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class LinTongSmsAccount extends SmsAccount{
|
||||
/**
|
||||
* api相关
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 账号相关
|
||||
*/
|
||||
private String userName;
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 标识渠道商Id
|
||||
*/
|
||||
private Integer supplierId;
|
||||
|
||||
/**
|
||||
* 标识渠道商名字
|
||||
*/
|
||||
private String supplierName;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.java3y.austin.handler.domain.sms;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* <span>Form File</span>
|
||||
* <p>Description</p>
|
||||
* <p>Company:QQ 752340543</p>
|
||||
*
|
||||
* @author topsuder
|
||||
* @version v1.0.0
|
||||
* @DATE 2022/11/24-15:58
|
||||
* @Description
|
||||
* @see com.java3y.austin.handler.domain.sms austin
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class LinTongSendMessage {
|
||||
String phone;
|
||||
String content;
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.java3y.austin.handler.domain.sms;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <span>Form File</span>
|
||||
* <p>Description</p>
|
||||
* <p>Company:QQ 752340543</p>
|
||||
*
|
||||
* @author topsuder
|
||||
* @version v1.0.0
|
||||
* @DATE 2022/11/24-15:24
|
||||
* @Description
|
||||
* @see com.java3y.austin.handler.domain.sms austin
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class LinTongSendResult {
|
||||
|
||||
Integer code;
|
||||
|
||||
String message;
|
||||
@JSONField(name = "data")
|
||||
List<DataDTO> dataDTOS;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class DataDTO{
|
||||
Integer code;
|
||||
String message;
|
||||
Long msgId;
|
||||
String phone;
|
||||
}
|
||||
}
|
@ -0,0 +1,136 @@
|
||||
package com.java3y.austin.handler.script.impl;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.http.Header;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.java3y.austin.common.dto.account.sms.LinTongSmsAccount;
|
||||
import com.java3y.austin.common.enums.SmsStatus;
|
||||
import com.java3y.austin.handler.domain.sms.LinTongSendMessage;
|
||||
import com.java3y.austin.handler.domain.sms.LinTongSendResult;
|
||||
import com.java3y.austin.handler.domain.sms.SmsParam;
|
||||
import com.java3y.austin.handler.script.SmsScript;
|
||||
import com.java3y.austin.support.domain.SmsRecord;
|
||||
import com.java3y.austin.support.utils.AccountUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <span>Form File</span>
|
||||
* <p>Description</p>
|
||||
* <p>Company:QQ 752340543</p>
|
||||
*
|
||||
* @author topsuder
|
||||
* @version v1.0.0
|
||||
* @DATE 2022/11/24-14:29
|
||||
* @Description
|
||||
* @see com.java3y.austin.handler.script.impl austin
|
||||
*/
|
||||
@Slf4j
|
||||
@Component("LinTongSmsScript")
|
||||
public class LinTongSmsScript implements SmsScript {
|
||||
|
||||
@Autowired
|
||||
private AccountUtils accountUtils;
|
||||
|
||||
/**
|
||||
* 发送短信
|
||||
*
|
||||
* @param smsParam
|
||||
* @return 渠道商接口返回值
|
||||
*/
|
||||
@Override
|
||||
public List<SmsRecord> send(SmsParam smsParam) {
|
||||
|
||||
try {
|
||||
LinTongSmsAccount linTongSmsAccount = accountUtils.getSmsAccountByScriptName(smsParam.getScriptName(), LinTongSmsAccount.class);
|
||||
String request = assembleReq(smsParam, linTongSmsAccount);
|
||||
String response = HttpRequest.post(linTongSmsAccount.getUrl()).body(request)
|
||||
.header(Header.ACCEPT.getValue(),"application/json")
|
||||
.header(Header.CONTENT_TYPE.getValue(),"application/json;charset=utf-8")
|
||||
.timeout(2000)
|
||||
.execute().body();
|
||||
LinTongSendResult linTongSendResult = JSON.parseObject(response, LinTongSendResult.class);
|
||||
return assembleSmsRecord(smsParam, linTongSendResult, linTongSmsAccount);
|
||||
}catch (Exception e){
|
||||
log.error("LinTongSmsAccount#send fail:{},params:{}", Throwables.getStackTraceAsString(e), JSON.toJSONString(smsParam));
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉取回执
|
||||
*
|
||||
* @param id 渠道账号的ID
|
||||
* @return 渠道商回执接口返回值
|
||||
*/
|
||||
@Override
|
||||
public List<SmsRecord> pull(Integer id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 组装发送短信参数
|
||||
*/
|
||||
private String assembleReq(SmsParam smsParam, LinTongSmsAccount account) {
|
||||
Map<String, Object> map = new HashMap<>(5);
|
||||
final long time = DateUtil.date().getTime();
|
||||
String sign = SecureUtil.md5( account.getUserName()+time+SecureUtil.md5(account.getPassword()));
|
||||
map.put("userName", account.getUserName());
|
||||
//获取当前时间戳
|
||||
map.put("timestamp", time);
|
||||
List<LinTongSendMessage> linTongSendMessages = new ArrayList<>(smsParam.getPhones().size());
|
||||
for (String phone : smsParam.getPhones()) {
|
||||
linTongSendMessages.add(LinTongSendMessage.builder().phone(phone).content(smsParam.getContent()).build());
|
||||
}
|
||||
map.put("messageList", linTongSendMessages);
|
||||
map.put("sign", sign);
|
||||
return JSONUtil.toJsonStr(map);
|
||||
}
|
||||
|
||||
private List<SmsRecord> assembleSmsRecord(SmsParam smsParam, LinTongSendResult response, LinTongSmsAccount account) {
|
||||
if (response == null || ArrayUtil.isEmpty(response.getDataDTOS())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<SmsRecord> smsRecordList = new ArrayList<>();
|
||||
|
||||
for (LinTongSendResult.DataDTO datum : response.getDataDTOS()) {
|
||||
SmsRecord smsRecord = SmsRecord.builder()
|
||||
.sendDate(Integer.valueOf(DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN)))
|
||||
.messageTemplateId(smsParam.getMessageTemplateId())
|
||||
.phone(Long.valueOf(datum.getPhone()))
|
||||
.supplierId(account.getSupplierId())
|
||||
.supplierName(account.getSupplierName())
|
||||
.msgContent(smsParam.getContent())
|
||||
.seriesId(datum.getMsgId().toString())
|
||||
.chargingNum(1)
|
||||
.status(datum.getCode()==0 ? SmsStatus.SEND_SUCCESS.getCode() : SmsStatus.SEND_FAIL.getCode())
|
||||
.reportContent(datum.getMessage())
|
||||
.created(Math.toIntExact(DateUtil.currentSeconds()))
|
||||
.updated(Math.toIntExact(DateUtil.currentSeconds()))
|
||||
.build();
|
||||
|
||||
smsRecordList.add(smsRecord);
|
||||
}
|
||||
|
||||
return smsRecordList;
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
discardMsgIds = []
|
||||
deduplicationRule = {"deduplication_10":{"num":1,"time":300},"deduplication_20":{"num":5}}
|
||||
msgTypeSmsConfig = [{"message_type_10":[{"weights":99,"scriptName":"TencentSmsScript"},{"weights":1,"scriptName":"YunPianSmsScript"}]},{"message_type_20":[{"weights":99,"scriptName":"TencentSmsScript"},{"weights":1,"scriptName":"YunPianSmsScript"}]},{"message_type_30":[{"weights":20,"scriptName":"TencentSmsScript"}]},{"message_type_40":[{"weights":20,"scriptName":"TencentSmsScript"}]}]
|
||||
msgTypeSmsConfig = [{"message_type_10":[{"weights":99,"scriptName":"TencentSmsScript"},{"weights":1,"scriptName":"YunPianSmsScript"}]},{"message_type_20":[{"weights":99,"scriptName":"TencentSmsScript"},{"weights":1,"scriptName":"YunPianSmsScript"}]},{"message_type_30":[{"weights":20,"scriptName":"TencentSmsScript"}]},{"message_type_40":[{"weights":20,"scriptName":"TencentSmsScript"}]},{"message_type_50":[{"weights":20,"scriptName":"LinTongSmsScript"}]}]
|
||||
flowControl = {"flow_control_40":1}
|
Loading…
Reference in new issue