短信发送细节修正
This commit is contained in:
parent
118943ad93
commit
61778b2d96
@ -1,16 +1,13 @@
|
||||
package com.tenwa.lease.app.message;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import jbo.com.tenwa.lease.comm.LB_MESSAGE_CONFIG;
|
||||
import jbo.com.tenwa.lease.comm.LB_SMS_NOTICE_TASKS;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.amarsoft.are.jbo.BizObject;
|
||||
import com.amarsoft.are.jbo.BizObjectManager;
|
||||
import com.amarsoft.are.jbo.JBOFactory;
|
||||
@ -33,19 +30,29 @@ public class SmsController {
|
||||
|
||||
public String sendMessage(JBOTransaction tx){
|
||||
try{
|
||||
//将发送过来的参数按照@切分出来
|
||||
String[] smsID = ids.split("@");
|
||||
BizObjectManager bomLSNT = JBOFactory.getBizObjectManager(LB_SMS_NOTICE_TASKS.CLASS_NAME,tx);
|
||||
for(String id:smsID){
|
||||
//通过ID获取表中的BizObject对象
|
||||
BizObject boLSNT = bomLSNT.createQuery("ID=:ID").setParameter("ID", id).getSingleResult(true);
|
||||
String result = null;
|
||||
try {
|
||||
//通过HttpClient发送短信
|
||||
result = SendMessageUtil.sendMessageByHttpClient(boLSNT.getAttribute("PHONE_NUMBER").getString(), boLSNT.getAttribute("SMS_CONTENT").getString());
|
||||
} catch (Exception e) {
|
||||
logger.error("短信发送任务执行失败。", e);
|
||||
result = "发送失败,发送遇到异常:" + e.getMessage();
|
||||
}
|
||||
//使用Jsonlib解析返回结果
|
||||
JSONObject object = JSONObject.fromObject(result);
|
||||
String statuscode = "";
|
||||
if(object != null){
|
||||
statuscode = object.get("status").toString();
|
||||
}
|
||||
boLSNT.setAttributeValue("SMS_TYPE","IMMEDIATELY");
|
||||
boLSNT.setAttributeValue("SEND_RESULT",SmsController.getResultCodeInfo(result));
|
||||
//判断返回的状态码
|
||||
boLSNT.setAttributeValue("SEND_RESULT",SmsController.getResultCodeInfo(statuscode));
|
||||
boLSNT.setAttributeValue("SEND_TIME",StringFunction.getTodayNow());
|
||||
boLSNT.setAttributeValue("SEND_FLAG",1);
|
||||
bomLSNT.saveObject(boLSNT);
|
||||
@ -67,7 +74,7 @@ public class SmsController {
|
||||
//密码
|
||||
String sendPassword = messageConfig.getAttribute("SENDER_PASSWORD_").getString();
|
||||
HttpClient httpClient = new HttpClient();
|
||||
//发送url
|
||||
//余额查询的接口url
|
||||
String url = "http://api.app2e.com/getBalance.api.php?pwd="+sendPassword+"&username="+sendUsername;
|
||||
GetMethod getMethod = new GetMethod(url);
|
||||
int statusCode = httpClient.executeMethod(getMethod);
|
||||
@ -78,7 +85,9 @@ public class SmsController {
|
||||
}else{
|
||||
result = statusCode + "";
|
||||
}
|
||||
//使用Jsonlib解析返回结果
|
||||
JSONObject jsonObject=JSONObject.fromObject(result);
|
||||
//取出剩余的余额
|
||||
String balance=jsonObject.get("balance").toString();
|
||||
getMethod.releaseConnection();
|
||||
return balance;
|
||||
@ -87,35 +96,24 @@ public class SmsController {
|
||||
return "查询失败";
|
||||
}
|
||||
}
|
||||
|
||||
//用于判断返回结果中的状态码
|
||||
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;
|
||||
case "100": codeMessage = "全部成功"; break;
|
||||
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;
|
||||
}
|
||||
if("0".equals(codeMessage.substring(0,1))){
|
||||
codeMessage = "操作成功";
|
||||
}
|
||||
return codeMessage;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user