This commit is contained in:
linfso 2024-08-13 09:26:06 +08:00
parent ace0ed0a12
commit f6831aa6d1
3 changed files with 206 additions and 183 deletions

View File

@ -43,6 +43,7 @@ package com.xdadan.erp.emis.service;
import com.xdadan.erp.emis.service.IEmisWaybillService;
import com.xdadan.erp.emis.service.sms.AliyunSMSService;
import com.xdadan.erp.emis.service.sms.CMCCSMSService;
import com.xdadan.erp.emis.service.sms.Sms253Service;
import com.xdadan.erp.emis.utils.HTTPHelperV3;
import com.xdadan.erp.emis.utils.Kd100Helper;
import com.xdadan.erp.emis.utils.WaybillHelper;
@ -150,7 +151,10 @@ public class EmisBaseService {
private AliyunSMSService aliyunSMSService;
@Autowired
private CMCCSMSService cmccSMSService;
private Sms253Service sms253Service;
// @Autowired
// private CMCCSMSService cmccSMSService;
@Autowired
private EmisSiteSettleRecordMapper emisSiteSettleRecordMapper;
@ -1440,52 +1444,58 @@ public class EmisBaseService {
// 发件短信
if ("1".equals(dt.getSmsType())) {
EmisWaybill waybill = getWaybillByBillCode(dt.getBillCode());
// EmisWaybill waybill = getWaybillByBillCode(dt.getBillCode());
// "尊敬的客户:您寄往${Nationalcity}的包裹已寄出,运单号${name}。如有疑问,详询服务热线4000257080,感谢您使用探路速运!";
String nationalcity=waybill.getReceiveCountryName()+""+waybill.getReceiveProvinceName();
JSONObject jObjParam = new JSONObject();
jObjParam.put("Nationalcity",nationalcity);
jObjParam.put("name",dt.getBillCode());
aliyunSMSService.sendMessage("探路速运", dt.getPhone(),"SMS_465316363", jObjParam.toJSONString());
// String nationalcity=waybill.getReceiveCountryName()+""+waybill.getReceiveProvinceName();
// JSONObject jObjParam = new JSONObject();
// jObjParam.put("Nationalcity",nationalcity);
// jObjParam.put("name",dt.getBillCode());
// aliyunSMSService.sendMessage("探路速运", dt.getPhone(),"SMS_465316363", jObjParam.toJSONString());
// cmccSMSService.sendMessage(DBUtil.getSeqNoByLen(10),dt.getPhone(),dt.getContent());
String content="【探路速运】"+dt.getContent();
sms253Service.sendMessage( dt.getPhone(),content);
}
// 签收短信
else if ("2".equals(dt.getSmsType())) {
EmisWaybill waybill = getWaybillByBillCode(dt.getBillCode());
// 尊敬的客户:您寄往${Nationalcity}的快递${name}已被签收,感谢您使用探路速运。
String nationalcity=waybill.getReceiveCountryName()+""+waybill.getReceiveProvinceName();
JSONObject jObjParam = new JSONObject();
jObjParam.put("Nationalcity",nationalcity);
jObjParam.put("name",dt.getBillCode());
aliyunSMSService.sendMessage("探路速运", dt.getPhone(), "SMS_465341331", jObjParam.toJSONString());
// EmisWaybill waybill = getWaybillByBillCode(dt.getBillCode());
//// 尊敬的客户:您寄往${Nationalcity}的快递${name}已被签收,感谢您使用探路速运。
// String nationalcity=waybill.getReceiveCountryName()+""+waybill.getReceiveProvinceName();
// JSONObject jObjParam = new JSONObject();
// jObjParam.put("Nationalcity",nationalcity);
// jObjParam.put("name",dt.getBillCode());
// aliyunSMSService.sendMessage("探路速运", dt.getPhone(), "SMS_465341331", jObjParam.toJSONString());
// cmccSMSService.sendMessage(DBUtil.getSeqNoByLen(10),dt.getPhone(),dt.getContent());
String content="【探路速运】"+dt.getContent();
sms253Service.sendMessage( dt.getPhone(),content);
}
// 问题件
else if ("3".equals(dt.getSmsType())) {
EmisWaybill waybill = getWaybillByBillCode(dt.getBillCode());
// EmisWaybill waybill = getWaybillByBillCode(dt.getBillCode());
// "尊敬的用户:您的运单${name}从${Sendingcountry}寄往${Receivingcountry}因${Problemtype}的问题导致货物时效延误预计送达时间${time},详询400-025-7080感谢您对探路速运的支持!";
EmisProblemType emisProblemType=getEmisProblemTypeByType(waybill.getProblemType());
// EmisProblemType emisProblemType=getEmisProblemTypeByType(waybill.getProblemType());
//
// String sendingcountry=waybill.getSendCountryName();
// String receivingcountry=waybill.getReceiveCountryName();
// JSONObject jObjParam = new JSONObject();
// jObjParam.put("Sendingcountry",sendingcountry);
// jObjParam.put("Receivingcountry",receivingcountry);
// jObjParam.put("name",waybill.getBillCode());
// jObjParam.put("Problemtype",emisProblemType.getTypeName());
// jObjParam.put("time",DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,waybill.getEstimateDate()));
String sendingcountry=waybill.getSendCountryName();
String receivingcountry=waybill.getReceiveCountryName();
JSONObject jObjParam = new JSONObject();
jObjParam.put("Sendingcountry",sendingcountry);
jObjParam.put("Receivingcountry",receivingcountry);
jObjParam.put("name",waybill.getBillCode());
jObjParam.put("Problemtype",emisProblemType.getTypeName());
jObjParam.put("time",DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,waybill.getEstimateDate()));
aliyunSMSService.sendMessage("探路速运", dt.getPhone(),"SMS_465386407", jObjParam.toJSONString());
// aliyunSMSService.sendMessage("探路速运", dt.getPhone(),"SMS_465386407", jObjParam.toJSONString());
// cmccSMSService.sendMessage(DBUtil.getSeqNoByLen(10),dt.getPhone(),dt.getContent());
String content="【探路速运】"+dt.getContent();
sms253Service.sendMessage( dt.getPhone(),content);
}
else{
continue;
@ -1499,7 +1509,8 @@ public class EmisBaseService {
}
dt.setFee("0");
dt.setSmsChannel("aliyun");
// dt.setSmsChannel("aliyun");
dt.setSmsChannel("sms253");
dt.setTaskDate(new Date());
emisSmsSendRecordMapper.updateEmisSmsSendRecord(dt);
log.error("===>End 发送短信");

View File

@ -1,13 +1,7 @@
package com.xdadan.erp.emis.service.sms;
import com.alibaba.fastjson.JSONObject;
import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
import com.xdadan.erp.system.service.ISysConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
@ -17,109 +11,109 @@ import org.springframework.stereotype.Service;
@Service("CMCCSMSService")
public class CMCCSMSService {
@Autowired
private ISysConfigService configService;
/**
* 发送短信
*/
public int sendMessage(String seqNo,String phone,String content) throws EmisBizError {
String jsonParamStr=configService.selectConfigByKey("sys.cmcc.sms");
JSONObject jObjAliyunParam=JSONObject.parseObject(jsonParamStr);
String url=jObjAliyunParam.getString("url");
String userAccount=jObjAliyunParam.getString("userAccount");
String password=jObjAliyunParam.getString("password");
String ecname=jObjAliyunParam.getString("ecname");
String signCode=jObjAliyunParam.getString("signCode");
/*
SDK java http://112.35.4.197:15000
单位名称:接口联调账号
用户名 :JStlz
密 码 :Passwd@#123
签名编码:bM16CfN2B
服务代码:10657204006
黑名单 普通短信 有发送能力
时效:1个月 10条/天
{
"url":"http://112.35.4.197:15000",
"userAccount":"JStlz",
"password":"Passwd@#123",
"ecname":"接口联调账号",
"ecname":"接口联调账号",
"signCode":"bM16CfN2B",
"serviceCode":"10657204006",
"desc":"黑名单 普通短信 有发送能力",
"timeDesc":"1个月 10条/天"
}
*/
return innerSendNormal(seqNo,
url,userAccount,password,ecname,signCode,
phone,content);
}
public static int innerSendNormal(
String seqNo,
String url,String userAccount,String password,
String ecname,String signCode,String phone,String content
) throws EmisBizError {
try {
// Client client = Client.getInstance( );
// // 登录地址需另外提供
// boolean isLoggedin = client.login( url, userAccount, password, ecname );
// if( !isLoggedin ) {
// log.error("移动短信渠道登录失败");
// throw new EmisBizError(EmisBizErrorType.FAIL,"移动短信渠道登录失败");
// @Autowired
// private ISysConfigService configService;
//
// /**
// * 发送短信
// */
// public int sendMessage(String seqNo,String phone,String content) throws EmisBizError {
// String jsonParamStr=configService.selectConfigByKey("sys.cmcc.sms");
// JSONObject jObjAliyunParam=JSONObject.parseObject(jsonParamStr);
// String url=jObjAliyunParam.getString("url");
// String userAccount=jObjAliyunParam.getString("userAccount");
// String password=jObjAliyunParam.getString("password");
// String ecname=jObjAliyunParam.getString("ecname");
// String signCode=jObjAliyunParam.getString("signCode");
//
// /*
// SDK java http://112.35.4.197:15000
// 单位名称:接口联调账号
// 用户名 :JStlz
// 密 码 :Passwd@#123
// 签名编码:bM16CfN2B
// 服务代码:10657204006
// 黑名单 普通短信 有发送能力
// 时效:1个月 10条/天
// {
// "url":"http://112.35.4.197:15000",
// "userAccount":"JStlz",
// "password":"Passwd@#123",
// "ecname":"接口联调账号",
// "ecname":"接口联调账号",
// "signCode":"bM16CfN2B",
// "serviceCode":"10657204006",
// "desc":"黑名单 普通短信 有发送能力",
// "timeDesc":"1个月 10条/天"
// }
// */
//
// return innerSendNormal(seqNo,
// url,userAccount,password,ecname,signCode,
// phone,content);
// }
//
// public static int innerSendNormal(
// String seqNo,
// String url,String userAccount,String password,
// String ecname,String signCode,String phone,String content
// ) throws EmisBizError {
// try {
//
//// Client client = Client.getInstance( );
//// // 登录地址需另外提供
//// boolean isLoggedin = client.login( url, userAccount, password, ecname );
//// if( !isLoggedin ) {
//// log.error("移动短信渠道登录失败");
//// throw new EmisBizError(EmisBizErrorType.FAIL,"移动短信渠道登录失败");
//// }
////
//// // 普通短信
//// int rst = client.sendDSMS( new String[]{phone}, content, seqNo, 1, signCode, null, true );
// int rst=1;
//// // 获取状态报告——开始
//// List<StatusReportModel> statusReportlist = client.getReport( );
//// log.error( "===>移动短信渠道发送状态==>:" + JSON.toJSONString( statusReportlist ) );
//// // 获取状态报告——结束
//
////
// if(rst==1) {
// return 1;
//// if ("OK".equals(response.getBody().getCode())) {
//// } else {
//// throw new EmisBizError(EmisBizErrorType.FAIL,response.getBody().getMessage());
//// }
// }else{
// throw new EmisBizError(EmisBizErrorType.FAIL,"短信渠道发送错误");
// }
//
// // 普通短信
// int rst = client.sendDSMS( new String[]{phone}, content, seqNo, 1, signCode, null, true );
int rst=1;
// // 获取状态报告——开始
// List<StatusReportModel> statusReportlist = client.getReport( );
// log.error( "===>移动短信渠道发送状态==>:" + JSON.toJSONString( statusReportlist ) );
// // 获取状态报告——结束
// }catch (Exception e) {
// e.printStackTrace();
// throw new EmisBizError(EmisBizErrorType.FAIL,"短信渠道异常");
// }
// }
//
if(rst==1) {
return 1;
// if ("OK".equals(response.getBody().getCode())) {
// } else {
// throw new EmisBizError(EmisBizErrorType.FAIL,response.getBody().getMessage());
// }
}else{
throw new EmisBizError(EmisBizErrorType.FAIL,"短信渠道发送错误");
}
}catch (Exception e) {
e.printStackTrace();
throw new EmisBizError(EmisBizErrorType.FAIL,"短信渠道异常");
}
}
public static void main(String[] args) {
String url="http://112.35.4.197:15000";
String userAccount="JStlz";
String password="Passwd@#123";
String ecname="接口联调账号";
String phoneNumbers="13815412745";
String signCode="bM16CfN2B";
String content="尊敬的客户:您寄往越南的包裹已寄出,运单号T123。如有疑问,详询服务热线4000257080,感谢您使用探路速运!";
try {
int ret = innerSendNormal("1",
url,userAccount,password,ecname,signCode,
phoneNumbers,content);
} catch (Exception e) {
e.printStackTrace();
}
}
//
// public static void main(String[] args) {
//
// String url="http://112.35.4.197:15000";
// String userAccount="JStlz";
// String password="Passwd@#123";
// String ecname="接口联调账号";
// String phoneNumbers="13815412745";
// String signCode="bM16CfN2B";
//
// String content="尊敬的客户:您寄往越南的包裹已寄出,运单号T123。如有疑问,详询服务热线4000257080,感谢您使用探路速运!";
//
// try {
//
// int ret = innerSendNormal("1",
// url,userAccount,password,ecname,signCode,
// phoneNumbers,content);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }

View File

@ -6,13 +6,17 @@ import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.tea.TeaModel;
import com.aliyun.teautil.Common;
import com.aliyun.teautil.models.RuntimeOptions;
import com.xdadan.erp.common.utils.DateUtils;
import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
import com.xdadan.erp.emis.utils.HTTPHelperV3;
import com.xdadan.erp.system.service.ISysConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
@Slf4j
@Service("Sms253Service")
public class Sms253Service {
@ -22,60 +26,73 @@ public class Sms253Service {
/**
* 发送短信
* @param signName 签名
* @param templateCode 模板
* @param phone 手机号
* @param tplParam 参数
* @param content 发送内容
*/
public int sendMessage(String signName,String phone, String templateCode,String tplParam) throws EmisBizError {
public int sendMessage(String phone, String content) throws EmisBizError {
String jsonParamStr=configService.selectConfigByKey("sys.sms253.sms");
JSONObject jObjAliyunParam=JSONObject.parseObject(jsonParamStr);
String accessKeyId=jObjAliyunParam.getString("accessKeyId");
String accessKeySecret=jObjAliyunParam.getString("accessKeySecret");
return innerSendMessage(accessKeyId,accessKeySecret,signName,templateCode,phone,tplParam);
String account=jObjAliyunParam.getString("account");
String passwd=jObjAliyunParam.getString("passwd");
return innerSendMessage(account,passwd,phone,content);
}
/**
* 使用AK&SK初始化账号Client
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
public static Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId(accessKeyId)
.setAccessKeySecret(accessKeySecret);
// 访问的域名
config.endpoint = "dysmsapi.aliyuncs.com";
return new Client(config);
}
public static int innerSendMessage(String accessKeyId,String accessKeySecret,String signName,String templateCode, String phone, String tplParam) throws EmisBizError {
public static int innerSendMessage(String account,String password, String phone, String msg) throws EmisBizError {
try {
Client client = createClient(accessKeyId, accessKeySecret);
com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest();
sendSmsRequest.setPhoneNumbers(phone);
sendSmsRequest.setSignName(signName);
sendSmsRequest.setTemplateCode(templateCode);
// sendSmsRequest.setTemplateParam("{\"code\":\""+param+"\"}");
sendSmsRequest.setTemplateParam(tplParam);
RuntimeOptions runtime = new RuntimeOptions();
com.aliyun.dysmsapi20170525.models.SendSmsResponse response = client.sendSmsWithOptions(sendSmsRequest, runtime);
String jsonStr= Common.toJSONString(TeaModel.buildMap(response));
if(response.getStatusCode()==200) {
if ("OK".equals(response.getBody().getCode())) {
return 1;
} else {
throw new EmisBizError(EmisBizErrorType.FAIL,response.getBody().getMessage());
String url="http://smssh1.253.com/msg/v1/send/json";
JSONObject jObjSms = new JSONObject();
jObjSms.put("account",account);
jObjSms.put("password",password);
jObjSms.put("phone",phone);
// DateUtils.dateTimeNow()
jObjSms.put("sendtime", "");
jObjSms.put("msg",msg);
jObjSms.put("report","true");
jObjSms.put("extend","1");
jObjSms.put("uid","1");
log.debug("===>SMS253==>发送短信数据:{}",jObjSms.toJSONString());
String retStr=HTTPHelperV3.postJson(url,null,jObjSms.toJSONString());
log.debug("===>SMS253==>返回短信发送结果:{}",retStr);
/*
{"account":"N6000001",
"password":"123456",
"msg":"【签名】您的验证码是:123456",
"phone":"15800000000",
"sendtime":"201704101400",
"report":"true",
"extend":"555",
"uid":"321abc",
}
*/
/*
{
"failNum":"0",
"time":"20170410103836",
"successNum":"1",
"msgId":"17041010383624511",
"errorMsg":"",
"code":"0"
}
*/
JSONObject jRst=JSONObject.parseObject(retStr);
String code=jRst.getString("code");
String errorMsg=jRst.getString("errorMsg");
if("0".equals(code)) {
return 1;
}else{
throw new EmisBizError(EmisBizErrorType.FAIL,"短信渠道发送错误");
throw new EmisBizError(EmisBizErrorType.FAIL,errorMsg);
}
}catch (Exception e) {
e.printStackTrace();
@ -86,14 +103,15 @@ public class Sms253Service {
public static void main(String[] args) {
String accessKeyId="LTAI5tA1yz1QK6BVhzg3ne5D";
String accessKeySecret="bFbFle1hFsy1zeyTeN79FXopPx9yRS";
String signName="跨境助手";
String templateCode="SMS_179215861";
// API账号:N588993_N5355809
// API密码:LF2vA700801dca
String accessKeyId="N588993_N5355809";
String accessKeySecret="LF2vA700801dca";
String phoneNumbers="13764645922";
String param="1234";
String msg="【探路速运】尊敬的客户:您寄往${Nationalcity}的包裹已寄出,运单号${name}。如有疑问,详询服务热线4000257080,感谢您使用探路速运!\n";
try {
int ret = innerSendMessage(accessKeyId,accessKeySecret,signName,templateCode,phoneNumbers,param);
int ret = innerSendMessage(accessKeyId,accessKeySecret,phoneNumbers,msg);
} catch (Exception e) {
e.printStackTrace();
}