切换移动梦网短信平台
This commit is contained in:
parent
804ce361cc
commit
8701e6c89e
@ -1,103 +1,113 @@
|
||||
<%@ page contentType="text/html; charset=GBK"%>
|
||||
<%@ include file="/Frame/resources/include/include_begin_list.jspf"%><%
|
||||
/*
|
||||
<%@ page contentType="text/html; charset=GBK" %>
|
||||
<%@ include file="/Frame/resources/include/include_begin_list.jspf" %>
|
||||
<%
|
||||
/*
|
||||
Author: undefined 2017-08-01
|
||||
Content:
|
||||
History Log:
|
||||
*/
|
||||
ASObjectModel doTemp = new ASObjectModel("LBSmsNoticeTasksList");
|
||||
doTemp.setDataQueryClass("com.amarsoft.awe.dw.ui.list.FlowMonitorListHtmlGenerator");
|
||||
CurPage.setAttribute("flowRowCount","100");
|
||||
ASObjectWindow dwTemp = new ASObjectWindow(CurPage,doTemp,request);
|
||||
dwTemp.Style="1"; //--设置为Grid风格--
|
||||
dwTemp.ReadOnly = "1"; //只读模式
|
||||
dwTemp.MultiSelect = true;
|
||||
dwTemp.setPageSize(pageSize==null?10:Integer.parseInt(pageSize));
|
||||
dwTemp.genHTMLObjectWindow("");
|
||||
ASObjectModel doTemp = new ASObjectModel("LBSmsNoticeTasksList");
|
||||
doTemp.setDataQueryClass("com.amarsoft.awe.dw.ui.list.FlowMonitorListHtmlGenerator");
|
||||
CurPage.setAttribute("flowRowCount", "100");
|
||||
ASObjectWindow dwTemp = new ASObjectWindow(CurPage, doTemp, request);
|
||||
dwTemp.Style = "1"; //--设置为Grid风格--
|
||||
dwTemp.ReadOnly = "1"; //只读模式
|
||||
dwTemp.MultiSelect = true;
|
||||
dwTemp.setPageSize(pageSize == null ? 10 : Integer.parseInt(pageSize));
|
||||
dwTemp.genHTMLObjectWindow("");
|
||||
|
||||
//0、是否展示 1、 权限控制 2、 展示类型 3、按钮显示名称 4、按钮解释文字 5、按钮触发事件代码 6、 7、 8、 9、图标,CSS层叠样式 10、风格
|
||||
String sButtons[][] = {
|
||||
{"true","","Button","新增","新增","newRecord()","","","","btn_icon_add",""},
|
||||
{"true","","Button","修改","修改","viewAndEdit()","","","","btn_icon_set",""},
|
||||
{"true","","Button","删除","删除","doDelete()","","","","btn_icon_delete",""},
|
||||
{"true","","Button","立即发送","立即发送","sendMessage()","","","","btn_icon_message",""},
|
||||
{"true","","Button","余额查询","余额查询","doSelect()","","","","btn_icon_information",""}
|
||||
};
|
||||
%><%@include file="/Frame/resources/include/ui/include_list.jspf"%>
|
||||
//0、是否展示 1、 权限控制 2、 展示类型 3、按钮显示名称 4、按钮解释文字 5、按钮触发事件代码 6、 7、 8、 9、图标,CSS层叠样式 10、风格
|
||||
String sButtons[][] = {
|
||||
{"true", "", "Button", "新增", "新增", "newRecord()", "", "", "", "btn_icon_add", ""},
|
||||
{"true", "", "Button", "修改", "修改", "viewAndEdit()", "", "", "", "btn_icon_set", ""},
|
||||
{"true", "", "Button", "删除", "删除", "doDelete()", "", "", "", "btn_icon_delete", ""},
|
||||
{"true", "", "Button", "立即发送", "立即发送", "sendMessage()", "", "", "", "btn_icon_message", ""},
|
||||
{"true", "", "Button", "余额查询(普通)", "查询普通短信余额", "doSelect('01')", "", "", "", "btn_icon_information", ""},
|
||||
{"true", "", "Button", "余额查询(催收)", "查询催收短信余额", "doSelect('02')", "", "", "", "btn_icon_information", ""}
|
||||
};
|
||||
%>
|
||||
<%@include file="/Frame/resources/include/ui/include_list.jspf" %>
|
||||
<script type="text/javascript">
|
||||
function doSelect(){
|
||||
var result = RunJavaMethodTrans("com.tenwa.lease.app.message.SmsController","selectBalance","");
|
||||
alert("短信余额为:"+result);
|
||||
}
|
||||
function newRecord(){
|
||||
var sUrl = "/Tenwa/Lease/App/Interface/Message/LBSmsNoticeTasksInfo.jsp";
|
||||
AsDialog.PopView(sUrl,"","dialogWidth=800px;dialogHeight=350px;resizable=no;scrollbars=no;status:yes;maximize:no;help:no;",function(){
|
||||
reloadSelf();
|
||||
},"新增");
|
||||
}
|
||||
function viewAndEdit(){
|
||||
var rows = getCheckedRows(0);
|
||||
if(rows.length != 1){
|
||||
alert("请选择一行数据进行修改!");
|
||||
return;
|
||||
}
|
||||
var sUrl = "/Tenwa/Lease/App/Interface/Message/LBSmsNoticeTasksInfo.jsp";
|
||||
var sPara = getItemValue(0,getRow(0),'ID');
|
||||
var sendFlag = getItemValue(0,getRow(0),"SEND_FLAG");
|
||||
if(sendFlag != 0){
|
||||
alert("只能修改待发送的短信!");
|
||||
return;
|
||||
}
|
||||
if(typeof(sPara)=="undefined" || sPara.length==0 ){
|
||||
alert("参数不能为空!");
|
||||
return ;
|
||||
}
|
||||
AsDialog.PopView(sUrl,"ID="+sPara,"dialogWidth=800px;dialogHeight=350px;resizable=no;scrollbars=no;status:yes;maximize:no;help:no;",function(){
|
||||
reloadSelf();
|
||||
},"修改");
|
||||
}
|
||||
|
||||
function doDelete(){
|
||||
var rows = getCheckedRows(0);
|
||||
if(rows.length == 0){
|
||||
alert("请选择一行数据!");
|
||||
return;
|
||||
}
|
||||
var ids = "";
|
||||
var flag = true;
|
||||
for(var i=0;i<rows.length;i++){
|
||||
var sendFlag = getItemValue(0,rows[i],"SEND_FLAG");
|
||||
if(sendFlag == 1){
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
if(!flag){
|
||||
alert("已发送的短信不能删除!");
|
||||
return;
|
||||
}
|
||||
as_delete(0);
|
||||
}
|
||||
|
||||
function sendMessage(){
|
||||
var rows = getCheckedRows(0);
|
||||
if(rows.length == 0){
|
||||
alert("请选择一行数据!");
|
||||
return;
|
||||
}
|
||||
var ids = "";
|
||||
for(var i=0;i<rows.length;i++){
|
||||
ids += "@" + getItemValue(0,rows[i],"ID");
|
||||
}
|
||||
ids = ids.substring(1);
|
||||
console.log(ids);
|
||||
var result = RunJavaMethodTrans("com.tenwa.lease.app.message.SmsController","sendMessage","ids="+ids);
|
||||
if("SUCCESS" == result){
|
||||
alert("发送成功!");
|
||||
reloadSelf();
|
||||
}else{
|
||||
alert("发送失败!");
|
||||
reloadSelf();
|
||||
}
|
||||
}
|
||||
function recvRpt() {
|
||||
var result = RunJavaMethodTrans("com.ample.sms.SmsController", "recvRpt", "");
|
||||
alert(result);
|
||||
}
|
||||
|
||||
function doSelect(smsObjType) {
|
||||
var result = RunJavaMethodTrans("com.ample.sms.SmsController", "getSmsRemains", "smsObjType=" + smsObjType + "");
|
||||
alert(result);
|
||||
}
|
||||
|
||||
function newRecord() {
|
||||
var sUrl = "/Tenwa/Lease/App/Interface/Message/LBSmsNoticeTasksInfo.jsp";
|
||||
AsDialog.PopView(sUrl, "", "dialogWidth=800px;dialogHeight=350px;resizable=no;scrollbars=no;status:yes;maximize:no;help:no;", function () {
|
||||
reloadSelf();
|
||||
}, "新增");
|
||||
}
|
||||
|
||||
function viewAndEdit() {
|
||||
var rows = getCheckedRows(0);
|
||||
if (rows.length != 1) {
|
||||
alert("请选择一行数据进行修改!");
|
||||
return;
|
||||
}
|
||||
var sUrl = "/Tenwa/Lease/App/Interface/Message/LBSmsNoticeTasksInfo.jsp";
|
||||
var sPara = getItemValue(0, getRow(0), 'ID');
|
||||
var sendFlag = getItemValue(0, getRow(0), "SEND_FLAG");
|
||||
if (sendFlag != 0) {
|
||||
alert("只能修改待发送的短信!");
|
||||
return;
|
||||
}
|
||||
if (typeof (sPara) == "undefined" || sPara.length == 0) {
|
||||
alert("参数不能为空!");
|
||||
return;
|
||||
}
|
||||
AsDialog.PopView(sUrl, "ID=" + sPara, "dialogWidth=800px;dialogHeight=350px;resizable=no;scrollbars=no;status:yes;maximize:no;help:no;", function () {
|
||||
reloadSelf();
|
||||
}, "修改");
|
||||
}
|
||||
|
||||
function doDelete() {
|
||||
var rows = getCheckedRows(0);
|
||||
if (rows.length == 0) {
|
||||
alert("请选择一行数据!");
|
||||
return;
|
||||
}
|
||||
var ids = "";
|
||||
var flag = true;
|
||||
for (var i = 0; i < rows.length; i++) {
|
||||
var sendFlag = getItemValue(0, rows[i], "SEND_FLAG");
|
||||
if (sendFlag == 1) {
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
if (!flag) {
|
||||
alert("已发送的短信不能删除!");
|
||||
return;
|
||||
}
|
||||
as_delete(0);
|
||||
}
|
||||
|
||||
function sendMessage() {
|
||||
var rows = getCheckedRows(0);
|
||||
if (rows.length == 0) {
|
||||
alert("请选择一行数据!");
|
||||
return;
|
||||
}
|
||||
var ids = "";
|
||||
for (var i = 0; i < rows.length; i++) {
|
||||
ids += "@" + getItemValue(0, rows[i], "ID");
|
||||
}
|
||||
ids = ids.substring(1);
|
||||
console.log(ids);
|
||||
var result = RunJavaMethodTrans("com.ample.sms.SmsController", "sendMessage", "ids=" + ids);
|
||||
if ("SUCCESS" == result) {
|
||||
alert("发送成功!");
|
||||
reloadSelf();
|
||||
} else {
|
||||
alert("发送失败!");
|
||||
reloadSelf();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<%@ include file="/Frame/resources/include/include_end.jspf"%>
|
||||
<%@ include file="/Frame/resources/include/include_end.jspf" %>
|
||||
@ -651,5 +651,53 @@
|
||||
</managerProperties>
|
||||
</manager>
|
||||
</class>
|
||||
<class name="SMS_RPT" label="短信状态推送记录表" describe="短信状态推送记录表" keyAttributes="msgid">
|
||||
<attributes>
|
||||
<attribute name="MSGID" label="唯一标识" type="LONG" length="64" />
|
||||
<attribute name="CUSTID" label="自定义流水号" type="STRING" length="50"/>
|
||||
<attribute name="PKNUM" label="当前条数" type="int" length="32"/>
|
||||
<attribute name="PKTOTAL" label="总条数" type="int" length="32"/>
|
||||
<attribute name="MOBILE" label="手机号" type="STRING" length="15"/>
|
||||
<attribute name="COUNTRYCODE" label="手机号国际区号" type="int" length="10"/>
|
||||
<attribute name="SPNO" label="完整的通道号" type="STRING" length="32"/>
|
||||
<attribute name="EXNO" label="下行时填写的exno" type="STRING" length="32"/>
|
||||
<attribute name="STIME" label="下行发送时间" type="STRING" length="32"/>
|
||||
<attribute name="RTIME" label="状态报告返回时间" type="STRING" length="32"/>
|
||||
<attribute name="STATUS" label="接收状态:0,成功;非0,失败" type="int" />
|
||||
<attribute name="ERRCODE" label="状态报告错误代码" type="STRING" length="32"/>
|
||||
<attribute name="ERRDESC" label="状态报告错误代码的描述" type="STRING" length="50"/>
|
||||
<attribute name="EXDATA" label="下行时填写的exdata" type="STRING" length="32"/>
|
||||
<attribute name="SMSTYPE" label="短信类型" type="STRING" length="32"/>
|
||||
<attribute name="RPTTYPE" label="状态报告类型" type="STRING" length="32"/>
|
||||
<attribute name="SEQID" label="请求消息流水号" type="int" length="32"/>
|
||||
</attributes>
|
||||
<manager>
|
||||
<managerProperties>
|
||||
<property name="table" value="SMS_RPT"/>
|
||||
</managerProperties>
|
||||
</manager>
|
||||
</class>
|
||||
<class name="SMS_SEND" label="短信发送记录表" describe="短信发送记录表" keyAttributes="ID">
|
||||
<attributes>
|
||||
<attribute name="ID" label="唯一标识" type="LONG" length="64" />
|
||||
<attribute name="MSGID" label="接口方短信唯一标识" type="LONG" length="64" />
|
||||
<attribute name="MOBILE" label="手机号" type="STRING" length="15"/>
|
||||
<attribute name="CONTENT" label="短信内容" type="STRING" length="990"/>
|
||||
<attribute name="EXNO" label="" type="STRING" />
|
||||
<attribute name="CUSTID" label="自定义流水号" type="STRING" length="50"/>
|
||||
<attribute name="SVRTYPE" label="短信类型" type="STRING" length="32"/>
|
||||
<attribute name="RESULT_CODE" label="返回结果编码" type="STRING" length="32"/>
|
||||
<attribute name="RESULT_DESC" label="返回结果描述" type="STRING" length="100"/>
|
||||
<attribute name="EXDATA" label="下行时填写的exdata" type="STRING" length="32"/>
|
||||
<attribute name="SEND_TIME" label="发送时间" type="STRING" length="32"/>
|
||||
<attribute name="SMS_ID" label="系统中短信唯一标识" type="String" length="32"/>
|
||||
<attribute name="SMS_OBJ_TYPE" label="短信类型" type="String" length="32"/>
|
||||
</attributes>
|
||||
<manager>
|
||||
<managerProperties>
|
||||
<property name="table" value="SMS_SEND"/>
|
||||
</managerProperties>
|
||||
</manager>
|
||||
</class>
|
||||
</package>
|
||||
</jbo>
|
||||
BIN
WebContent/WEB-INF/lib/SmsSdk-5.7.jar
Normal file
BIN
WebContent/WEB-INF/lib/SmsSdk-5.7.jar
Normal file
Binary file not shown.
@ -121,6 +121,15 @@
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>SmsRptServlet</servlet-name>
|
||||
<servlet-class>com.ample.sms.SmsRptServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>DataSource</param-name>
|
||||
<param-value>als</param-value>
|
||||
</init-param>
|
||||
</servlet>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>RewriteRunJavaMethodServlet</servlet-name>
|
||||
<servlet-class>com.tenwa.workflow.RewriteRunJavaMethodServlet</servlet-class>
|
||||
@ -298,6 +307,11 @@
|
||||
<url-pattern>/servlet/runflow</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>SmsRptServlet</servlet-name>
|
||||
<url-pattern>/smsRpt</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>DocDownloadZipServlet</servlet-name>
|
||||
<url-pattern>/servlet/view/docDownloadZipServlet</url-pattern>
|
||||
|
||||
11
config/sms.properties
Normal file
11
config/sms.properties
Normal file
@ -0,0 +1,11 @@
|
||||
userid=JU9237
|
||||
pwd=507237
|
||||
ipAddress1=172.28.1.59:8803
|
||||
ipAddress2=
|
||||
ipAddress3=
|
||||
ipAddress4=
|
||||
|
||||
log_path=/data/sms/
|
||||
|
||||
urge_userid=JU9239
|
||||
urge_pwd=507237
|
||||
65
src/com/ample/sms/FileUtil.java
Normal file
65
src/com/ample/sms/FileUtil.java
Normal file
@ -0,0 +1,65 @@
|
||||
package com.ample.sms;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.Calendar;
|
||||
|
||||
public class FileUtil {
|
||||
public static final int BUFFER_SIZE = 1024;
|
||||
|
||||
public FileUtil() {
|
||||
}
|
||||
|
||||
public static void writeFile(String fileName, String content) {
|
||||
FileOutputStream fos = null;
|
||||
ByteArrayInputStream bis = null;
|
||||
|
||||
try {
|
||||
File file = new File(fileName);
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
fos = new FileOutputStream(fileName, true);
|
||||
bis = new ByteArrayInputStream(content.getBytes("GBK"));
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
|
||||
int ch;
|
||||
while((ch = bis.read(buffer)) != -1) {
|
||||
fos.write(buffer, 0, ch);
|
||||
}
|
||||
} catch (Exception var15) {
|
||||
var15.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (bis != null) {
|
||||
bis.close();
|
||||
}
|
||||
|
||||
if (fos != null) {
|
||||
fos.close();
|
||||
}
|
||||
} catch (Exception var14) {
|
||||
var14.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String getCurrTime() {
|
||||
try {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
String yearstr = String.valueOf(calendar.get(1));
|
||||
int month = calendar.get(2) + 1;
|
||||
String monthstr = month > 9 ? String.valueOf(month) : "0" + String.valueOf(month);
|
||||
int day = calendar.get(5);
|
||||
String daystr = day > 9 ? String.valueOf(day) : "0" + String.valueOf(day);
|
||||
return yearstr + "/" + monthstr + "/" + daystr + "/";
|
||||
} catch (Exception var6) {
|
||||
var6.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
100
src/com/ample/sms/RecvMoThread.java
Normal file
100
src/com/ample/sms/RecvMoThread.java
Normal file
@ -0,0 +1,100 @@
|
||||
package com.ample.sms;
|
||||
|
||||
import com.montnets.mwgate.common.MO;
|
||||
import com.montnets.mwgate.smsutil.SmsSendConn;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 获取上行短信的线程
|
||||
*/
|
||||
public class RecvMoThread extends Thread {
|
||||
|
||||
// 短信处理对象,在这个方法中调用获取上行功能
|
||||
private SmsSendConn smsSendConn = null;
|
||||
// 用户账号
|
||||
private String userid = null;
|
||||
// 每次请求想要获取上行的最大条数
|
||||
private int retsize = 0;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @param smsSendConn
|
||||
* 短信处理对象
|
||||
* @param userid
|
||||
* 用户账号
|
||||
*/
|
||||
public RecvMoThread(SmsSendConn smsSendConn, String userid, int retsize) {
|
||||
// 短信处理对象
|
||||
this.smsSendConn = smsSendConn;
|
||||
// 用户账号
|
||||
this.userid = userid;
|
||||
// 每次请求想要获取上行的最大条数
|
||||
this.retsize = retsize;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上行短信线程的方法
|
||||
*/
|
||||
public void run() {
|
||||
// 上行集合 本集合临时存储上行,需要将收到的上行保存在一个队列中,由另外一个线程去处理。
|
||||
List<MO> mos = new ArrayList<MO>();
|
||||
// 返回值
|
||||
int result = -310099;
|
||||
//上行对象声明
|
||||
MO mo = null;
|
||||
// 循环调用获取上行的方法
|
||||
while (true) {
|
||||
try {
|
||||
// 初始化返回值
|
||||
result = -310099;
|
||||
// 清空上行集合中的对象
|
||||
mos.clear();
|
||||
// 调用获取上行接口
|
||||
result = smsSendConn.getMo(userid, retsize, mos);
|
||||
// 如果获取上行成功,并且有上行
|
||||
if (result == 0 && mos != null && mos.size() > 0) {
|
||||
// 有上行
|
||||
// 添加到上行队列
|
||||
// add mo queue
|
||||
// 这里不要做复杂的耗时的处理,将收到的上行保存在一个队列中,由另外一个线程去处理。
|
||||
|
||||
// 代码示例是将上行信息打印出来
|
||||
System.out.println("获取上行成功!获取到的上行有" + mos.size() + "条记录。");
|
||||
for (int i = 0; i < mos.size(); i++) {
|
||||
mo = mos.get(i);
|
||||
System.out.println("上行记录:" +"msgid:"+mo.getMsgid() + ",mobile:" + mo.getMobile()+",countrycode:"+mo.getCountrycode()
|
||||
+ ",pknum:"+mo.getPknum()+",pktotal:"+mo.getPktotal()+",spno:" + mo.getSpno()
|
||||
+ ",exno:" + mo.getExno() + ",content:" + mo.getContent()+ ",rtime:" + mo.getRtime() );
|
||||
}
|
||||
|
||||
// 继续循环
|
||||
continue;
|
||||
} else {
|
||||
// 如果获取上行失败,则将错误码打印
|
||||
if (result != 0) {
|
||||
System.out.println("获取上行失败,错误码为:" + result);
|
||||
}
|
||||
|
||||
// 没有上行,延时5秒以上
|
||||
try {
|
||||
Thread.sleep(5000L);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// 循环出现异常,暂停5秒
|
||||
try {
|
||||
Thread.sleep(5000L);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
103
src/com/ample/sms/RecvRptThread.java
Normal file
103
src/com/ample/sms/RecvRptThread.java
Normal file
@ -0,0 +1,103 @@
|
||||
package com.ample.sms;
|
||||
|
||||
import com.montnets.mwgate.common.RPT;
|
||||
import com.montnets.mwgate.smsutil.SmsSendConn;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 获取短信状态报告的线程
|
||||
*/
|
||||
public class RecvRptThread extends Thread {
|
||||
|
||||
// 短信处理对象,在这个方法中调用获取状态报告功能
|
||||
private SmsSendConn smsSendConn = null;
|
||||
// 用户账号
|
||||
private String userid = null;
|
||||
// 每次请求想要获取状态报告的最大条数
|
||||
private int retsize = 0;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @param smsSendConn
|
||||
* 短信处理对象
|
||||
* @param userid
|
||||
* 用户账号
|
||||
*/
|
||||
public RecvRptThread(SmsSendConn smsSendConn, String userid, int retsize) {
|
||||
// 短信处理对象
|
||||
this.smsSendConn = smsSendConn;
|
||||
// 用户账号
|
||||
this.userid = userid;
|
||||
// 每次请求想要获取状态报告的最大条数
|
||||
this.retsize = retsize;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取短信状态报告线程的方法
|
||||
*/
|
||||
public void run() {
|
||||
// 状态报告集合 本集合临时存储状态报告,需要将收到的状态报告保存在一个队列中,由另外一个线程去处理
|
||||
List<RPT> rpts = new ArrayList<RPT>();
|
||||
// 返回值
|
||||
int result = -310099;
|
||||
//状态报告对象声明
|
||||
RPT rpt = null;
|
||||
// 循环调用获取状态报告的方法
|
||||
while (true) {
|
||||
try {
|
||||
// 初始化返回值
|
||||
result = -310099;
|
||||
// 清空状态报告集合中的对象
|
||||
rpts.clear();
|
||||
// 调用获取状态报告接口
|
||||
result = smsSendConn.getRpt(userid, retsize, rpts);
|
||||
// 如果获取状态报告成功,并且有状态报告
|
||||
if (result == 0 && rpts != null && rpts.size() > 0) {
|
||||
// 有状态报告
|
||||
// 添加到状态报告队列
|
||||
// add rpt queue
|
||||
// 这里不要做复杂的耗时的处理,将收到的状态报告保存在一个队列中,由另外一个线程去处理。
|
||||
|
||||
// 代码示例是将状态报告信息打印出来
|
||||
System.out.println("获取状态报告成功!获取到的状态报告有" + rpts.size()
|
||||
+ "条记录。");
|
||||
for (int i = 0; i < rpts.size(); i++) {
|
||||
rpt = rpts.get(i);
|
||||
System.out.println("状态报告记录:" +"msgid:"+rpt.getMsgid() + ",custid:" + rpt.getCustid() + ",pknum:" + rpt.getPknum()
|
||||
+ ",pktotal:" + rpt.getPktotal() + ",mobile:" + rpt.getMobile()+",countrycode:"+rpt.getCountrycode()
|
||||
+ ",spno:" + rpt.getSpno() + ",exno:" + rpt.getExno() + ",stime:" + rpt.getStime()
|
||||
+ ",rtime:" + rpt.getRtime() + ",status:" + rpt.getStatus() + ",errcode:" + rpt.getErrcode()
|
||||
+ ",errdesc:"+rpt.getErrdesc()+ ",exdata:" + rpt.getExdata());
|
||||
}
|
||||
|
||||
// 继续循环
|
||||
continue;
|
||||
} else {
|
||||
// 如果获取状态报告失败,则将错误码打印
|
||||
if (result != 0) {
|
||||
System.out.println("获取状态报告失败,错误码为:" + result);
|
||||
}
|
||||
|
||||
// 没有状态报告,延时5秒以上
|
||||
try {
|
||||
Thread.sleep(5000L);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// 循环出现异常,暂停5秒
|
||||
try {
|
||||
Thread.sleep(5000L);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
184
src/com/ample/sms/SmsController.java
Normal file
184
src/com/ample/sms/SmsController.java
Normal file
@ -0,0 +1,184 @@
|
||||
package com.ample.sms;
|
||||
|
||||
import com.amarsoft.are.jbo.*;
|
||||
import com.amarsoft.are.util.StringFunction;
|
||||
import com.montnets.mwgate.common.Message;
|
||||
import com.montnets.mwgate.common.Remains;
|
||||
import com.montnets.mwgate.smsutil.SmsSendConn;
|
||||
import jbo.com.tenwa.lease.comm.LB_SMS_NOTICE_TASKS;
|
||||
import jbo.oti.SMS_SEND;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class SmsController {
|
||||
private String ids;
|
||||
private String smsObjType;
|
||||
|
||||
private Logger logger = Logger.getLogger(this.getClass());
|
||||
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
|
||||
public String sendMessage(JBOTransaction tx){
|
||||
try{
|
||||
// 实例化短信处理对象
|
||||
SmsSendConn smsSendConn = new SmsSendConn(true);
|
||||
//将发送过来的参数按照@切分出来
|
||||
String[] smsID = ids.split("@");
|
||||
BizObjectManager bomLSNT = JBOFactory.getBizObjectManager(LB_SMS_NOTICE_TASKS.CLASS_NAME,tx);
|
||||
BizObjectManager bomSS = JBOFactory.getBizObjectManager(SMS_SEND.CLASS_NAME,tx);
|
||||
for(String id:smsID){
|
||||
sendMessage(smsSendConn,id,bomLSNT,bomSS);
|
||||
}
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
return "ERROR";
|
||||
}
|
||||
return "SUCCESS";
|
||||
}
|
||||
|
||||
public void sendMessage(SmsSendConn smsSendConn,String smsId,BizObjectManager bomLSNT,BizObjectManager bomSS) throws JBOException {
|
||||
BizObject boLSNT = bomLSNT.createQuery("ID=:ID").setParameter("ID", smsId).getSingleResult(true);
|
||||
int resultCode = -310099;
|
||||
try {
|
||||
Message message = createMessageByBizObject(boLSNT);
|
||||
String smsObType = boLSNT.getAttribute("SEND_OBJ_TYPE").toString();
|
||||
if(SmsObjType.URGE_COLLECTION.getType().equals(smsObType)){
|
||||
SmsSendManager.setAccountInfo(SmsObjType.URGE_COLLECTION);
|
||||
}else {
|
||||
SmsSendManager.setAccountInfo(SmsObjType.NORMAL);
|
||||
}
|
||||
StringBuffer returnValue = new StringBuffer();
|
||||
/*
|
||||
发送短信
|
||||
*/
|
||||
resultCode = smsSendConn.singleSend(message, returnValue);
|
||||
boLSNT = this.saveObject(boLSNT,bomSS,returnValue.toString(),resultCode);
|
||||
bomLSNT.saveObject(boLSNT);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("短信发送执行失败。", e);
|
||||
}
|
||||
|
||||
}
|
||||
public BizObject saveObject(BizObject boLSNT,BizObjectManager bomSS,String returnValue,int resultCode) throws JBOException {
|
||||
String smsStatus = "未发送";
|
||||
|
||||
// result为0:成功;非0:失败
|
||||
if (resultCode == 0) {
|
||||
smsStatus = "已发送";
|
||||
System.out.println("单条发送提交成功:"+returnValue);
|
||||
}else {
|
||||
System.out.println("单条发送提交失败,错误码:" + resultCode);
|
||||
smsStatus = "未发送";
|
||||
}
|
||||
|
||||
BizObject boSS = bomSS.newObject();
|
||||
boSS.setAttributeValue("MOBILE",boLSNT.getAttribute("PHONE_NUMBER").toString());
|
||||
boSS.setAttributeValue("CONTENT",boLSNT.getAttribute("SMS_CONTENT").getString());
|
||||
boSS.setAttributeValue("SMS_ID",boLSNT.getAttribute("ID").toString());
|
||||
boSS.setAttributeValue("SEND_TIME", StringFunction.getTodayNow());
|
||||
boSS.setAttributeValue("RESULT_CODE",resultCode);
|
||||
boSS.setAttributeValue("MSGID",StringUtils.substringAfterLast(returnValue.toString(),","));
|
||||
boSS.setAttributeValue("SMS_OBJ_TYPE",boLSNT.getAttribute("SEND_OBJ_TYPE").getString());
|
||||
bomSS.saveObject(boSS);
|
||||
|
||||
boLSNT.setAttributeValue("SMS_TYPE","IMMEDIATELY");
|
||||
boLSNT.setAttributeValue("SEND_RESULT",smsStatus);
|
||||
boLSNT.setAttributeValue("SEND_TIME",sdf.format(new Date()));
|
||||
boLSNT.setAttributeValue("SEND_FLAG",resultCode == 0 ? 1 : 0);
|
||||
return boLSNT;
|
||||
}
|
||||
|
||||
public String getSmsRemains(JBOTransaction tx){
|
||||
String result = "查询失败";
|
||||
// 实例化短信处理对象
|
||||
SmsSendConn smsSendConn = new SmsSendConn(true);
|
||||
SmsSendManager.setAccountInfo("02".equals(smsObjType)?SmsObjType.URGE_COLLECTION:SmsObjType.NORMAL);
|
||||
// 查询余额接口。
|
||||
Remains remains = smsSendConn.getRemains(SmsPropertiesUtil.get("userid"));
|
||||
|
||||
//remains不为空
|
||||
if(remains==null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
//查询成功
|
||||
if(remains.getResult()!=0)
|
||||
{
|
||||
//查询失败
|
||||
System.out.println("查询失败,错误码为:" + remains.getResult());
|
||||
return "查询失败,错误码为:" + remains.getResult();
|
||||
}
|
||||
//计费类型为0,条数计费
|
||||
if(remains.getChargetype()==0)
|
||||
{
|
||||
System.out.println("查询成功,剩余条数为:" + remains.getBalance()+"条");
|
||||
return "查询成功,剩余条数为:" + remains.getBalance()+"条";
|
||||
}else if(remains.getChargetype()==1)
|
||||
{
|
||||
//计费类型为1,金额计费
|
||||
System.out.println("查询成功,剩余金额为:" + remains.getMoney()+"元");
|
||||
return "查询成功,剩余金额为:" + remains.getMoney()+"元";
|
||||
}else
|
||||
{
|
||||
System.out.println("未知的计费类型,计费类型:"+remains.getChargetype());
|
||||
return "未知的计费类型,计费类型:"+remains.getChargetype();
|
||||
}
|
||||
}
|
||||
|
||||
public String recvRpt(JBOTransaction tx){
|
||||
// 实例化短信处理对象
|
||||
SmsSendConn smsSendConnRpt = new SmsSendConn(true);
|
||||
// 每次请求想要获取的状态报告的最大条数。
|
||||
int retsizeRpt = 100;
|
||||
// 实例化状态报告线程
|
||||
String userId = "CS1156";
|
||||
SmsRecvRptThread recvRptThread = new SmsRecvRptThread(smsSendConnRpt, userId,retsizeRpt);
|
||||
// 线程获取 启动获取状态报告的线程
|
||||
recvRptThread.start();
|
||||
System.out.println("获取状态报告的线程启动成功!");
|
||||
return "获取状态报告的线程启动成功!";
|
||||
}
|
||||
public Message createMessageByBizObject(BizObject bo) throws JBOException {
|
||||
//调用短信接口
|
||||
String phoneNo = bo.getAttribute("PHONE_NUMBER").getString();
|
||||
String smsContent = bo.getAttribute("SMS_CONTENT").getString();
|
||||
String smsId = bo.getAttribute("ID").getString();
|
||||
// 参数类
|
||||
Message message = new Message();
|
||||
// 设置用户账号 指定用户账号发送,需要填写用户账号,不指定用户账号发送,无需填写用户账号
|
||||
// message.setUserid(userid);
|
||||
// 设置手机号码 此处只能设置一个手机号码
|
||||
message.setMobile(phoneNo);
|
||||
// 设置内容
|
||||
message.setContent(smsContent);
|
||||
// 设置扩展号为数字字符串且长度不能超过6位,注意通道号+扩展号的总长度不能超过20位,若超出exno无效,如不需要扩展号则不用提交此字段或填空
|
||||
message.setExno("");
|
||||
// 用户自定义流水编号:最大可支持64位的ASCII字符串:字母、数字、下划线、减号,如不需要则不用提交此字段或填空
|
||||
message.setCustid("");
|
||||
// 自定义扩展数据:额外提供的最大64位长度的ASCII字符串:字母、数字、下划线、减号,作为自定义扩展数据,填写后,状态报告返回时将会包含这部分数据,如不需要则不用提交此字段或填空
|
||||
message.setExdata(smsId);
|
||||
// 业务类型:最大可支持32个长度的英文字母、数字组合的字符串
|
||||
message.setSvrtype("");
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
public String getSmsObjType() {
|
||||
return smsObjType;
|
||||
}
|
||||
public void setSmsObjType(String smsObjType) {
|
||||
this.smsObjType = smsObjType;
|
||||
}
|
||||
public String getIds() {
|
||||
return ids;
|
||||
}
|
||||
|
||||
public void setIds(String ids) {
|
||||
this.ids = ids;
|
||||
}
|
||||
|
||||
}
|
||||
24
src/com/ample/sms/SmsObjType.java
Normal file
24
src/com/ample/sms/SmsObjType.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.ample.sms;
|
||||
|
||||
public enum SmsObjType {
|
||||
|
||||
NORMAL("01","ÆÕͨ"),
|
||||
URGE_COLLECTION("02","´ßÊÕ"),
|
||||
MARKETING("03","ÓªÏú");
|
||||
|
||||
private String type;
|
||||
private String desc;
|
||||
|
||||
SmsObjType(String type, String desc) {
|
||||
this.type=type;
|
||||
this.desc=desc;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return this.desc;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
36
src/com/ample/sms/SmsPropertiesUtil.java
Normal file
36
src/com/ample/sms/SmsPropertiesUtil.java
Normal file
@ -0,0 +1,36 @@
|
||||
package com.ample.sms;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class SmsPropertiesUtil {
|
||||
private static Map<String, String> attributes;
|
||||
|
||||
public static void load() {
|
||||
attributes = new ConcurrentHashMap<String, String>();
|
||||
Properties prop = new Properties();
|
||||
try {
|
||||
prop.load(SmsPropertiesUtil.class.getResourceAsStream("/sms.properties"));
|
||||
for(Map.Entry<Object, Object> entry : prop.entrySet()) {
|
||||
if(entry.getKey() == null || entry.getValue() == null) {
|
||||
continue;
|
||||
}
|
||||
attributes.put(entry.getKey().toString(), entry.getValue().toString());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void destroy() {
|
||||
if(attributes != null) attributes.clear();
|
||||
}
|
||||
|
||||
public static String get(String propName) {
|
||||
if(attributes == null) load();
|
||||
return attributes.get(propName);
|
||||
}
|
||||
}
|
||||
98
src/com/ample/sms/SmsRecvRptThread.java
Normal file
98
src/com/ample/sms/SmsRecvRptThread.java
Normal file
@ -0,0 +1,98 @@
|
||||
package com.ample.sms;
|
||||
|
||||
import com.montnets.mwgate.common.RPT;
|
||||
import com.montnets.mwgate.smsutil.SmsSendConn;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SmsRecvRptThread extends Thread{
|
||||
// 短信处理对象,在这个方法中调用获取状态报告功能
|
||||
private SmsSendConn smsSendConn = null;
|
||||
// 用户账号
|
||||
private String userid = null;
|
||||
// 每次请求想要获取状态报告的最大条数
|
||||
private int retsize = 0;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @param smsSendConn
|
||||
* 短信处理对象
|
||||
* @param userid
|
||||
* 用户账号
|
||||
*/
|
||||
public SmsRecvRptThread(SmsSendConn smsSendConn, String userid, int retsize) {
|
||||
// 短信处理对象
|
||||
this.smsSendConn = smsSendConn;
|
||||
// 用户账号
|
||||
this.userid = userid;
|
||||
// 每次请求想要获取状态报告的最大条数
|
||||
this.retsize = retsize;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取短信状态报告线程的方法
|
||||
*/
|
||||
public void run() {
|
||||
// 状态报告集合 本集合临时存储状态报告,需要将收到的状态报告保存在一个队列中,由另外一个线程去处理
|
||||
List<RPT> rpts = new ArrayList<RPT>();
|
||||
// 返回值
|
||||
int result = -310099;
|
||||
//状态报告对象声明
|
||||
RPT rpt = null;
|
||||
// 循环调用获取状态报告的方法
|
||||
while (true) {
|
||||
try {
|
||||
// 初始化返回值
|
||||
result = -310099;
|
||||
// 清空状态报告集合中的对象
|
||||
rpts.clear();
|
||||
// 调用获取状态报告接口
|
||||
result = smsSendConn.getRpt(userid, retsize, rpts);
|
||||
// 如果获取状态报告成功,并且有状态报告
|
||||
if (result == 0 && rpts != null && rpts.size() > 0) {
|
||||
// 有状态报告
|
||||
// 添加到状态报告队列
|
||||
// add rpt queue
|
||||
// 这里不要做复杂的耗时的处理,将收到的状态报告保存在一个队列中,由另外一个线程去处理。
|
||||
|
||||
// 代码示例是将状态报告信息打印出来
|
||||
System.out.println("获取状态报告成功!获取到的状态报告有" + rpts.size()
|
||||
+ "条记录。");
|
||||
for (int i = 0; i < rpts.size(); i++) {
|
||||
rpt = rpts.get(i);
|
||||
System.out.println("状态报告记录:" +"msgid:"+rpt.getMsgid() + ",custid:" + rpt.getCustid() + ",pknum:" + rpt.getPknum()
|
||||
+ ",pktotal:" + rpt.getPktotal() + ",mobile:" + rpt.getMobile()+",countrycode:"+rpt.getCountrycode()
|
||||
+ ",spno:" + rpt.getSpno() + ",exno:" + rpt.getExno() + ",stime:" + rpt.getStime()
|
||||
+ ",rtime:" + rpt.getRtime() + ",status:" + rpt.getStatus() + ",errcode:" + rpt.getErrcode()
|
||||
+ ",errdesc:"+rpt.getErrdesc()+ ",exdata:" + rpt.getExdata());
|
||||
}
|
||||
|
||||
// 继续循环
|
||||
continue;
|
||||
} else {
|
||||
// 如果获取状态报告失败,则将错误码打印
|
||||
if (result != 0) {
|
||||
System.out.println("获取状态报告失败,错误码为:" + result);
|
||||
}
|
||||
|
||||
// 没有状态报告,延时5秒以上
|
||||
try {
|
||||
Thread.sleep(5000L);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// 循环出现异常,暂停5秒
|
||||
try {
|
||||
Thread.sleep(5000L);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
128
src/com/ample/sms/SmsRptServlet.java
Normal file
128
src/com/ample/sms/SmsRptServlet.java
Normal file
@ -0,0 +1,128 @@
|
||||
package com.ample.sms;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.montnets.mwgate.common.EncryptUtil;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class SmsRptServlet extends HttpServlet{
|
||||
public SmsRptServlet() {
|
||||
}
|
||||
private static final long serialVersionUID = 1L;
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
System.out.println("请求回调开始");
|
||||
response.setContentType("application/json;charset:utf-8");
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
response.setHeader("Pragma", "no-cache");
|
||||
response.setDateHeader("Expires", 0L);
|
||||
response.setCharacterEncoding("utf-8");
|
||||
int result = -100999;
|
||||
JSONObject resultJson = new JSONObject();
|
||||
resultJson.put("cmd","RPT_RESP");
|
||||
PrintWriter out = response.getWriter();
|
||||
try{
|
||||
if (!WriteRptThread.rptIsAlive()) {
|
||||
WriteRptThread.getRptthread().start();
|
||||
}
|
||||
//进行初步验证
|
||||
String userid = request.getParameter("userid");
|
||||
String pwd = request.getParameter("pwd");
|
||||
String timestamp = request.getParameter("timestamp");
|
||||
String cmd = request.getParameter("cmd");
|
||||
String seqid =request.getParameter("seqid");
|
||||
if(!(SmsPropertiesUtil.get("userid").equals(userid)||SmsPropertiesUtil.get("urge_userid").equals(userid))){
|
||||
return;
|
||||
}
|
||||
String normalVld = EncryptUtil.encryptPwd(userid,SmsPropertiesUtil.get("pwd"),timestamp);
|
||||
String urgeVld = EncryptUtil.encryptPwd(userid,SmsPropertiesUtil.get("urge_pwd"),timestamp);
|
||||
if(!(normalVld.equals(pwd)||urgeVld.equals(pwd))){
|
||||
return;
|
||||
}
|
||||
|
||||
String currDate = FileUtil.getCurrTime();
|
||||
String fileUrl = SmsPropertiesUtil.get("log_path") + "file/rpt/"+ currDate +"/RPT.txt";
|
||||
String rpts = request.getParameter("rpts");
|
||||
int count = 0;
|
||||
if (rpts != null && rpts.length() > 0) {
|
||||
Object object = JSON.parse(rpts);
|
||||
if(object instanceof JSONArray){
|
||||
JSONArray jsonArray = (JSONArray)object;
|
||||
for(Iterator it = jsonArray.iterator(); it.hasNext(); ++count) {
|
||||
JSONObject rptJsn = (JSONObject)it.next();
|
||||
String errDesc = rptJsn.getString("errdesc");
|
||||
byte[] byte_test = errDesc.getBytes(StandardCharsets.ISO_8859_1);
|
||||
errDesc = new String(byte_test,"utf-8");
|
||||
rptJsn.put("errdesc",decode(errDesc));
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("rpt",rptJsn);
|
||||
jo.put("userid",userid);
|
||||
jo.put("pwd",pwd);
|
||||
jo.put("timestamp",timestamp);
|
||||
jo.put("cmd",cmd);
|
||||
jo.put("seqid",seqid);
|
||||
jo.put("fileUrl",fileUrl);
|
||||
WriteRptThread.rptQueue.put(jo);
|
||||
}
|
||||
}else if(object instanceof JSONObject){
|
||||
JSONObject rptJsn = (JSONObject)object;
|
||||
String errDesc = rptJsn.getString("errdesc");
|
||||
byte[] byte_test = errDesc.getBytes(StandardCharsets.ISO_8859_1);
|
||||
errDesc = new String(byte_test,"utf-8");
|
||||
rptJsn.put("errdesc",decode(errDesc));
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("rpt",object);
|
||||
jo.put("userid",userid);
|
||||
jo.put("pwd",pwd);
|
||||
jo.put("timestamp",timestamp);
|
||||
jo.put("cmd",cmd);
|
||||
jo.put("seqid",seqid);
|
||||
jo.put("fileUrl",fileUrl);
|
||||
WriteRptThread.rptQueue.put(jo);
|
||||
count = 1;
|
||||
}
|
||||
result=0;
|
||||
}
|
||||
|
||||
System.out.println("接收到Rpt记录:" + count + "条");
|
||||
|
||||
resultJson.put("seqid",seqid);
|
||||
resultJson.put("result",result);
|
||||
out.print(resultJson.toJSONString());
|
||||
out.close();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
//pwd = "{\"cmd\":\"RPT_RESP\",\"seqid\":" + seqid + ",\"result\":-100999}";
|
||||
resultJson.put("seqid","");
|
||||
resultJson.put("result",result);
|
||||
out.print(resultJson.toJSONString());
|
||||
out.close();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
doPost(request, response);
|
||||
}
|
||||
|
||||
private String decode(String content) {
|
||||
try {
|
||||
return URLDecoder.decode(content, "UTF-8");
|
||||
} catch (Exception var3) {
|
||||
var3.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
245
src/com/ample/sms/SmsSendManager.java
Normal file
245
src/com/ample/sms/SmsSendManager.java
Normal file
@ -0,0 +1,245 @@
|
||||
package com.ample.sms;
|
||||
|
||||
import com.montnets.mwgate.common.*;
|
||||
import com.montnets.mwgate.smsutil.ConfigManager;
|
||||
import com.montnets.mwgate.smsutil.SmsSendConn;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SmsSendManager {
|
||||
|
||||
static {
|
||||
|
||||
|
||||
// 获取全局参数单例对象
|
||||
GlobalParams globalParams = GlobalParams.getInstance();
|
||||
// 设置请求路径
|
||||
globalParams.setRequestPath("/sms/v2/std/");
|
||||
// 设置是否需要日志 1:需要日志;0:不需要日志
|
||||
globalParams.setNeedLog(0);
|
||||
// 设置http连接池的连接数量
|
||||
globalParams.setPoolNumber(16);
|
||||
|
||||
//设置密码加密类型
|
||||
globalParams.setPwdEncryptType(PwdEncryptEnum.MD5);
|
||||
|
||||
//设置下行内容的加密类型 明文
|
||||
globalParams.setMsgMtEncrypt(ContentEncryptEnum.PLAIN);
|
||||
//下行内容加密类型还有 ContentEncryptEnum.SM4_ECB_ZEROPADDING和ContentEncryptEnum.SM4_ECB_PKCS7PADDING
|
||||
//如果设置为以上两种SM4加密类型,则还需要设置参数
|
||||
//globalParams.setMtKey(SecretKeyEnum.SM3HASH_KEY);或者globalParams.setMtKey(SecretKeyEnum.FIXED_KEY);
|
||||
//如果设置为SecretKeyEnum.FIXED_KEY
|
||||
//则还需要设置固定秘钥,秘钥是双方共同约定好的
|
||||
//globalParams.setMtFixedKey("0123456789abcdeffedcba9876543210");
|
||||
|
||||
//设置下行内容的编码类型 UTF-8
|
||||
globalParams.setMsgMtEncode(ContentEncodeEnum.UTF_8);
|
||||
|
||||
//设置上行内容的加密类型 明文
|
||||
globalParams.setMsgMoEncrypt(ContentEncryptEnum.PLAIN);
|
||||
//上行内容加密类型还有 ContentEncryptEnum.SM4_ECB_ZEROPADDING和ContentEncryptEnum.SM4_ECB_PKCS7PADDING
|
||||
//如果设置为以上两种SM4加密类型,则还需要设置参数
|
||||
//globalParams.setMoKey(SecretKeyEnum.SM3HASH_KEY);或者globalParams.setMoKey(SecretKeyEnum.FIXED_KEY);
|
||||
//如果设置为SecretKeyEnum.FIXED_KEY
|
||||
//则还需要设置固定秘钥,秘钥是双方共同约定好的
|
||||
//globalParams.setMoFixedKey("0123456789abcdeffedcba9876543210");
|
||||
|
||||
// 设置用户账号信息
|
||||
setAccountInfo(SmsObjType.NORMAL);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 设置用户账号信息
|
||||
*/
|
||||
public static void setAccountInfo(SmsObjType smsObjType) {
|
||||
// 设置用户账号信息
|
||||
|
||||
// 用户账号
|
||||
String userid = SmsPropertiesUtil.get("userid");
|
||||
// 密码
|
||||
String password = SmsPropertiesUtil.get("pwd");
|
||||
|
||||
if((SmsObjType.URGE_COLLECTION).equals(smsObjType)){
|
||||
userid = SmsPropertiesUtil.get("urge_userid");
|
||||
password = SmsPropertiesUtil.get("urge_pwd");
|
||||
}
|
||||
|
||||
// 发送优先级
|
||||
int priority = 1;
|
||||
// 主IP信息,请前往您的控制台获取请求域名(IP)或联系梦网客服进行获取
|
||||
String ipAddress1 = SmsPropertiesUtil.get("ipAddress1");
|
||||
|
||||
// 备用IP1信息
|
||||
String ipAddress2 = SmsPropertiesUtil.get("ipAddress2");
|
||||
// 备用IP2信息
|
||||
String ipAddress3 = SmsPropertiesUtil.get("ipAddress3");
|
||||
// 备用IP3信息
|
||||
String ipAddress4 = SmsPropertiesUtil.get("ipAddress4");
|
||||
// 返回值
|
||||
int result = -310007;
|
||||
try {
|
||||
// 设置用户账号信息
|
||||
result = ConfigManager.setAccountInfo(userid, password, priority,
|
||||
ipAddress1, ipAddress2, ipAddress3, ipAddress4);
|
||||
// 判断返回结果,0设置成功,否则失败
|
||||
if (result == 0) {
|
||||
System.out.println("设置"+smsObjType.getDesc()+"用户账号信息成功!");
|
||||
} else {
|
||||
System.out.println("设置"+smsObjType.getDesc()+"用户账号信息失败,错误码:" + result);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 异常处理
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @description 单条发送
|
||||
* @param smsSendConn
|
||||
* 短信处理对象,在这个方法中调用发送短信功能
|
||||
* @param message
|
||||
* 短信
|
||||
*/
|
||||
public static void singleSend(SmsSendConn smsSendConn,Message message) {
|
||||
try {
|
||||
|
||||
// 返回的流水号
|
||||
StringBuffer returnValue = new StringBuffer();
|
||||
// 返回值
|
||||
int result = -310099;
|
||||
// 发送短信
|
||||
result = smsSendConn.singleSend(message, returnValue);
|
||||
// result为0:成功
|
||||
if (result == 0) {
|
||||
System.out.println("单条发送提交成功!");
|
||||
System.out.println(returnValue.toString());
|
||||
}
|
||||
// result为非0:失败
|
||||
else {
|
||||
System.out.println("单条发送提交失败,错误码:" + result);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 异常处理
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @description 个性化群发
|
||||
* @param smsSendConn
|
||||
* 短信处理对象,在这个方法中调用发送短信功能
|
||||
* @param userid
|
||||
* 用户账号
|
||||
* 暂时还未使用。因为原有短信和定时任务逻辑单位为每条,在不进行大改动的情况下,暂时不用群发功能。
|
||||
* 原有短信发送逻辑:1.在LB_SMS_NOTICE_TASKS表中新建待发送短信,
|
||||
* 2.然后在qrtz_jbo_detail和msg_send_relative中创建每条短信的定时任务,定时任务触发时间为当前时间+2秒。
|
||||
*/
|
||||
public static void multiSend(SmsSendConn smsSendConn, String userid) {
|
||||
try {
|
||||
// List集合
|
||||
List<MultiMt> multixMts = new ArrayList<MultiMt>();
|
||||
// 第一条 短信对象
|
||||
MultiMt multixMt1 = new MultiMt();
|
||||
// 手机号
|
||||
multixMt1.setMobile("18101193112");
|
||||
// 短信内容
|
||||
multixMt1.setContent("测试第一条!");
|
||||
// 设置扩展号
|
||||
multixMt1.setExno("");
|
||||
// 用户自定义流水编号
|
||||
multixMt1.setCustid("111");
|
||||
// 自定义扩展数据
|
||||
multixMt1.setExdata("222");
|
||||
// 业务类型
|
||||
multixMt1.setSvrtype("");
|
||||
// 添加到集合中去
|
||||
multixMts.add(multixMt1);
|
||||
|
||||
// 第二条 短信对象
|
||||
MultiMt multixMt2 = new MultiMt();
|
||||
// 手机号
|
||||
multixMt2.setMobile("18101193113");
|
||||
// 短信内容
|
||||
multixMt2.setContent("测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!测试第二条!");
|
||||
// 设置扩展号
|
||||
multixMt2.setExno("");
|
||||
// 用户自定义流水编号
|
||||
multixMt2.setCustid("111");
|
||||
// 自定义扩展数据
|
||||
multixMt2.setExdata("222");
|
||||
// 业务类型
|
||||
multixMt2.setSvrtype("");
|
||||
// 添加到集合中去
|
||||
multixMts.add(multixMt2);
|
||||
|
||||
// 返回的流水号
|
||||
StringBuffer returnValue = new StringBuffer();
|
||||
// 返回值
|
||||
int result = -310099;
|
||||
|
||||
//设置用户账号 指定用户账号发送,需要填写用户账号,不指定用户账号发送,无需填写用户账号
|
||||
// 发送短信
|
||||
result = smsSendConn.multiSend(userid, 0L, multixMts, returnValue);
|
||||
// result为0:成功
|
||||
if (result == 0) {
|
||||
System.out.println("个性化群发提交成功!");
|
||||
System.out.println(returnValue.toString());
|
||||
}
|
||||
// result为非0:失败
|
||||
else {
|
||||
System.out.println("个性化群发提交失败,错误码:" + result);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 异常处理
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询剩余金额或条数接口
|
||||
*/
|
||||
public static void getRemains(SmsSendConn smsSendConn,String userid)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 查询余额接口。
|
||||
Remains remains = smsSendConn.getRemains(userid);
|
||||
|
||||
//remains不为空
|
||||
if(remains==null)
|
||||
{
|
||||
System.out.println("查询失败。");
|
||||
return;
|
||||
}
|
||||
//查询成功
|
||||
if(remains.getResult()!=0)
|
||||
{
|
||||
//查询失败
|
||||
System.out.println("查询失败,错误码为:" + remains.getResult());
|
||||
return;
|
||||
}
|
||||
//计费类型为0,条数计费
|
||||
if(remains.getChargetype()==0)
|
||||
{
|
||||
System.out.println("查询成功,剩余条数为:" + remains.getBalance()+"条");
|
||||
}else if(remains.getChargetype()==1)
|
||||
{
|
||||
//计费类型为1,金额计费
|
||||
System.out.println("查询成功,剩余金额为:" + remains.getMoney()+"元");
|
||||
}else
|
||||
{
|
||||
System.out.println("未知的计费类型,计费类型:"+remains.getChargetype());
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
110
src/com/ample/sms/WriteRptThread.java
Normal file
110
src/com/ample/sms/WriteRptThread.java
Normal file
@ -0,0 +1,110 @@
|
||||
package com.ample.sms;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.amarsoft.are.jbo.BizObject;
|
||||
import com.amarsoft.are.jbo.BizObjectManager;
|
||||
import com.amarsoft.are.jbo.JBOException;
|
||||
import com.amarsoft.are.jbo.JBOFactory;
|
||||
import jbo.com.tenwa.lease.comm.LB_SMS_NOTICE_TASKS;
|
||||
import jbo.oti.SMS_RPT;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class WriteRptThread extends Thread{
|
||||
public static LinkedBlockingQueue<JSONObject> rptQueue = new LinkedBlockingQueue<JSONObject>();
|
||||
private static boolean STOP = false;
|
||||
private static Thread rptThread = new WriteRptThread();
|
||||
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
private WriteRptThread() {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
String content = "";
|
||||
String filePath = "";
|
||||
STOP = false;
|
||||
try {
|
||||
while(!STOP) {
|
||||
JSONObject rptJson = (JSONObject)rptQueue.take();
|
||||
filePath = rptJson.get("fileUrl").toString();
|
||||
rptJson.remove("fileUrl");
|
||||
content = this.sdf.format(System.currentTimeMillis()) + " " + rptJson.toJSONString()+ "\r\n";
|
||||
FileUtil.writeFile(filePath, content);
|
||||
//保存返回结果
|
||||
saveSmsRpt(rptJson);
|
||||
}
|
||||
} catch (Exception var5) {
|
||||
var5.printStackTrace();
|
||||
STOP = true;
|
||||
rptThread = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static boolean rptIsAlive() {
|
||||
return rptThread.isAlive();
|
||||
}
|
||||
|
||||
public static Thread getRptthread() {
|
||||
if (rptThread == null) {
|
||||
rptThread = new WriteRptThread();
|
||||
}
|
||||
|
||||
return rptThread;
|
||||
}
|
||||
public void saveSmsRpt(JSONObject jo) throws JBOException {
|
||||
JSONObject rptJsn = jo.getJSONObject("rpt");
|
||||
BizObjectManager boManager = JBOFactory.getBizObjectManager(SMS_RPT.CLASS_NAME);
|
||||
BizObjectManager bomLsnt = JBOFactory.getBizObjectManager(LB_SMS_NOTICE_TASKS.CLASS_NAME);
|
||||
|
||||
try {
|
||||
BizObject bo = boManager.newObject();
|
||||
Set<String> rptSet = rptJsn.keySet();
|
||||
Iterator<String> rptIt = rptSet.iterator();
|
||||
String smsId = null;
|
||||
while(rptIt.hasNext()){
|
||||
String key = rptIt.next();
|
||||
bo.getAttribute(key);
|
||||
//表中没有此值则跳过
|
||||
if (bo.indexOfAttribute(key) < 0) {
|
||||
continue;
|
||||
}
|
||||
if("exdata".equals(key)){
|
||||
smsId = rptJsn.getString(key);
|
||||
}
|
||||
if("msgid".equals(key)){
|
||||
String msgId = rptJsn.getString(key);
|
||||
int count = boManager.createQuery("MSGID=:msgid").setParameter("msgid",msgId).getTotalCount();
|
||||
if(count>0){
|
||||
return;
|
||||
}
|
||||
}
|
||||
bo.setAttributeValue(key,rptJsn.getString(key));
|
||||
}
|
||||
bo.setAttributeValue("SEQID",jo.get("seqid"));
|
||||
boManager.saveObject(bo);
|
||||
|
||||
if(smsId!=null&&smsId.length()>0){
|
||||
String sendResult = null;
|
||||
BizObject boLsnt = bomLsnt.createQuery("ID=:smsId").setParameter("smsId",smsId).getSingleResult(true);
|
||||
if(boLsnt!=null){
|
||||
if("0".equals(bo.getAttribute("STATUS").toString())){
|
||||
sendResult = "发送成功";
|
||||
}else{
|
||||
sendResult = bo.getAttribute("errdesc").toString();
|
||||
}
|
||||
boLsnt.setAttributeValue("SEND_RESULT",sendResult);
|
||||
bomLsnt.saveObject(boLsnt);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (JBOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
84
src_jbo/jbo/oti/SMS_RPT.java
Normal file
84
src_jbo/jbo/oti/SMS_RPT.java
Normal file
@ -0,0 +1,84 @@
|
||||
package jbo.oti;
|
||||
|
||||
import java.lang.String;
|
||||
|
||||
/**
|
||||
* 短信状态推送记录表 - JBO命名常量类<br><br>
|
||||
* Note: This file is generated by ADE tools, <em>dont</em> modify it.<br>
|
||||
|
||||
*/
|
||||
public interface SMS_RPT{
|
||||
/**
|
||||
* 短信状态推送记录表<br><br>
|
||||
* 代表本类映射的BizObjectClass
|
||||
*/
|
||||
public static final String CLASS_NAME = "jbo.oti.SMS_RPT";
|
||||
/**
|
||||
* 唯一标识 LONG(64)<br>
|
||||
*/
|
||||
public static final String MSGID = "MSGID";
|
||||
/**
|
||||
* 自定义流水号 STRING(50)<br>
|
||||
*/
|
||||
public static final String CUSTID = "CUSTID";
|
||||
/**
|
||||
* 当前条数 INT(32)<br>
|
||||
*/
|
||||
public static final String PKNUM = "PKNUM";
|
||||
/**
|
||||
* 总条数 INT(32)<br>
|
||||
*/
|
||||
public static final String PKTOTAL = "PKTOTAL";
|
||||
/**
|
||||
* 手机号 STRING(15)<br>
|
||||
*/
|
||||
public static final String MOBILE = "MOBILE";
|
||||
/**
|
||||
* 手机号国际区号 INT(10)<br>
|
||||
*/
|
||||
public static final String COUNTRYCODE = "COUNTRYCODE";
|
||||
/**
|
||||
* 完整的通道号 STRING(32)<br>
|
||||
*/
|
||||
public static final String SPNO = "SPNO";
|
||||
/**
|
||||
* 下行时填写的exno STRING(32)<br>
|
||||
*/
|
||||
public static final String EXNO = "EXNO";
|
||||
/**
|
||||
* 下行发送时间 STRING(32)<br>
|
||||
*/
|
||||
public static final String STIME = "STIME";
|
||||
/**
|
||||
* 状态报告返回时间 STRING(32)<br>
|
||||
*/
|
||||
public static final String RTIME = "RTIME";
|
||||
/**
|
||||
* 接收状态:0,成功;非0,失败 INT(20)<br>
|
||||
*/
|
||||
public static final String STATUS = "STATUS";
|
||||
/**
|
||||
* 状态报告错误代码 STRING(32)<br>
|
||||
*/
|
||||
public static final String ERRCODE = "ERRCODE";
|
||||
/**
|
||||
* 状态报告错误代码的描述 STRING(50)<br>
|
||||
*/
|
||||
public static final String ERRDESC = "ERRDESC";
|
||||
/**
|
||||
* 下行时填写的exdata STRING(32)<br>
|
||||
*/
|
||||
public static final String EXDATA = "EXDATA";
|
||||
/**
|
||||
* 短信类型 STRING(32)<br>
|
||||
*/
|
||||
public static final String SMSTYPE = "SMSTYPE";
|
||||
/**
|
||||
* 状态报告类型 STRING(32)<br>
|
||||
*/
|
||||
public static final String RPTTYPE = "RPTTYPE";
|
||||
/**
|
||||
* 请求消息流水号 INT(32)<br>
|
||||
*/
|
||||
public static final String SEQID = "SEQID";
|
||||
}
|
||||
68
src_jbo/jbo/oti/SMS_SEND.java
Normal file
68
src_jbo/jbo/oti/SMS_SEND.java
Normal file
@ -0,0 +1,68 @@
|
||||
package jbo.oti;
|
||||
|
||||
import java.lang.String;
|
||||
|
||||
/**
|
||||
* 短信发送记录表 - JBO命名常量类<br><br>
|
||||
* Note: This file is generated by ADE tools, <em>dont</em> modify it.<br>
|
||||
|
||||
*/
|
||||
public interface SMS_SEND{
|
||||
/**
|
||||
* 短信发送记录表<br><br>
|
||||
* 代表本类映射的BizObjectClass
|
||||
*/
|
||||
public static final String CLASS_NAME = "jbo.oti.SMS_SEND";
|
||||
/**
|
||||
* 唯一标识 LONG(64)<br>
|
||||
*/
|
||||
public static final String ID = "ID";
|
||||
/**
|
||||
* 接口方短信唯一标识 LONG(64)<br>
|
||||
*/
|
||||
public static final String MSGID = "MSGID";
|
||||
/**
|
||||
* 手机号 STRING(15)<br>
|
||||
*/
|
||||
public static final String MOBILE = "MOBILE";
|
||||
/**
|
||||
* 短信内容 STRING(990)<br>
|
||||
*/
|
||||
public static final String CONTENT = "CONTENT";
|
||||
/**
|
||||
* STRING(20)<br>
|
||||
*/
|
||||
public static final String EXNO = "EXNO";
|
||||
/**
|
||||
* 自定义流水号 STRING(50)<br>
|
||||
*/
|
||||
public static final String CUSTID = "CUSTID";
|
||||
/**
|
||||
* 短信类型 STRING(32)<br>
|
||||
*/
|
||||
public static final String SVRTYPE = "SVRTYPE";
|
||||
/**
|
||||
* 返回结果编码 STRING(32)<br>
|
||||
*/
|
||||
public static final String RESULT_CODE = "RESULT_CODE";
|
||||
/**
|
||||
* 返回结果描述 STRING(100)<br>
|
||||
*/
|
||||
public static final String RESULT_DESC = "RESULT_DESC";
|
||||
/**
|
||||
* 下行时填写的exdata STRING(32)<br>
|
||||
*/
|
||||
public static final String EXDATA = "EXDATA";
|
||||
/**
|
||||
* 发送时间 STRING(32)<br>
|
||||
*/
|
||||
public static final String SEND_TIME = "SEND_TIME";
|
||||
/**
|
||||
* 系统中短信唯一标识 STRING(32)<br>
|
||||
*/
|
||||
public static final String SMS_ID = "SMS_ID";
|
||||
/**
|
||||
* 系统中短信唯一标识 STRING(32)<br>
|
||||
*/
|
||||
public static final String SMS_OBJ_TYPE = "SMS_OBJ_TYPE";
|
||||
}
|
||||
@ -1,9 +1,9 @@
|
||||
package com.tenwa.message;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.amarsoft.are.jbo.*;
|
||||
import com.tenwa.lease.util.SendMessageUtil;
|
||||
import jbo.com.tenwa.lease.comm.LB_SMS_NOTICE_TASKS;
|
||||
import com.amarsoft.are.jbo.JBOException;
|
||||
import com.amarsoft.are.jbo.JBOFactory;
|
||||
import com.amarsoft.are.jbo.JBOTransaction;
|
||||
import com.ample.sms.SmsController;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.quartz.Job;
|
||||
@ -11,7 +11,6 @@ import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class JobSendMessage implements Job{
|
||||
|
||||
@ -26,34 +25,9 @@ public class JobSendMessage implements Job{
|
||||
tx= JBOFactory.createJBOTransaction();
|
||||
smsnoticeid = context.getJobDetail().getJobDataMap().getString("smsnoticeid");
|
||||
logger.info("short message running..... LB_SMS_NOTICE_TASKS[ID]: "+smsnoticeid);
|
||||
BizObjectManager bomNotice = JBOFactory.getBizObjectManager(LB_SMS_NOTICE_TASKS.CLASS_NAME,tx);
|
||||
BizObject notice = bomNotice.createQuery("id=:id").setParameter("id", smsnoticeid).getSingleResult(true);
|
||||
if(notice != null){
|
||||
if(notice.getAttribute("send_flag").getInt() == 0){
|
||||
String result = null;
|
||||
boolean flagErrStatus = true;
|
||||
try {
|
||||
result = SendMessageUtil.sendMessageByHttpClient(notice.getAttribute("phone_number").getString(), notice.getAttribute("sms_content").getString());
|
||||
if(!result.matches("^[0-9].*")){
|
||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||
if(jsonObject.getIntValue("status")==100){
|
||||
flagErrStatus = false;
|
||||
result = "全部成功";
|
||||
}else{
|
||||
result = getResultCodeInfoNew(jsonObject.getString("status"));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("短信发送任务执行失败,LB_SMS_NOTICE_TASKS[ID] : "+smsnoticeid, e);
|
||||
result = "发送失败,发送遇到异常:" + e.getMessage();
|
||||
}
|
||||
notice.setAttributeValue("sms_type", "IMMEDIATELY");
|
||||
notice.setAttributeValue("send_result", result);
|
||||
notice.setAttributeValue("send_time", sdf.format(new Date()));
|
||||
notice.setAttributeValue("send_flag", flagErrStatus ? 0 : 1);
|
||||
bomNotice.saveObject(notice);
|
||||
}
|
||||
}
|
||||
SmsController sc = new SmsController();
|
||||
sc.setIds(smsnoticeid);
|
||||
sc.sendMessage(tx);
|
||||
tx.commit();
|
||||
} catch (Exception e) {
|
||||
logger.error("short message error LB_SMS_NOTICE_TASKS[ID] : "+smsnoticeid ,e);
|
||||
@ -65,53 +39,4 @@ public class JobSendMessage implements Job{
|
||||
}
|
||||
}
|
||||
|
||||
public static String getResultCodeInfoNew(String code){
|
||||
String codeMessage = "";
|
||||
switch(code){
|
||||
case "101": codeMessage = "参数错误"; break;
|
||||
case "102": codeMessage = "号码错误"; break;
|
||||
case "103": codeMessage = "当日余量不足"; break;
|
||||
case "104": codeMessage = "请求超时"; break;
|
||||
case "105": codeMessage = "用户余量不足"; break;
|
||||
case "106": codeMessage = "非法用户"; break;
|
||||
case "107": codeMessage = "提交号码超限"; break;
|
||||
case "111": codeMessage = "签名不合法"; break;
|
||||
case "120": codeMessage = "内容长度超长,请不要超过500个字"; break;
|
||||
case "121": codeMessage = "内容中有屏蔽词"; break;
|
||||
case "131": codeMessage = "IP非法"; break;
|
||||
default : codeMessage = code ; break;
|
||||
}
|
||||
return codeMessage;
|
||||
}
|
||||
|
||||
public static String getResultCodeInfo(String code){
|
||||
String codeMessage = "";
|
||||
switch(code){
|
||||
case "-1": codeMessage = "签权失败"; break;
|
||||
case "-2": codeMessage = "未检索到被叫号码"; break;
|
||||
case "-3": codeMessage = "被叫号码过多"; break;
|
||||
case "-4": codeMessage = "内容未签名"; break;
|
||||
case "-5": codeMessage = "内容过长"; break;
|
||||
case "-6": codeMessage = "余额不足"; break;
|
||||
case "-7": codeMessage = "暂停发送"; break;
|
||||
case "-8": codeMessage = "保留"; break;
|
||||
case "-9": codeMessage = "定时发送时间格式错误"; break;
|
||||
case "-10": codeMessage = "下发内容为空"; break;
|
||||
case "-11": codeMessage = "账户无效"; break;
|
||||
case "-12": codeMessage = "Ip地址非法"; break;
|
||||
case "-13": codeMessage = "操作频率快"; break;
|
||||
case "-14": codeMessage = "操作失败"; break;
|
||||
case "-15": codeMessage = "拓展码无效"; break;
|
||||
case "-16": codeMessage = "取消定时,seqid错误"; break;
|
||||
case "-18": codeMessage = "暂留"; break;
|
||||
case "-19": codeMessage = "未开通上行"; break;
|
||||
case "-20": codeMessage = "暂留"; break;
|
||||
case "-21": codeMessage = "包含屏蔽词"; break;
|
||||
default : codeMessage = code; break;
|
||||
}
|
||||
if("0".equals(codeMessage.substring(0,1))){
|
||||
codeMessage = "操作成功";
|
||||
}
|
||||
return codeMessage;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user