短信接口配置,之前在其他项目上,现在迁移过来
This commit is contained in:
parent
ea0f5b92ec
commit
a70577bcff
@ -18,78 +18,84 @@
|
||||
{"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","立即发送","立即发送","sendMessage()","","","","btn_icon_message",""},
|
||||
{"true","","Button","余额查询","余额查询","doSelect()","","","","btn_icon_information",""}
|
||||
};
|
||||
%><%@include file="/Frame/resources/include/ui/include_list.jspf"%>
|
||||
<script type="text/javascript">
|
||||
function newRecord(){
|
||||
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();
|
||||
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 ;
|
||||
}
|
||||
}
|
||||
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();
|
||||
reloadSelf();
|
||||
},"修改");
|
||||
}
|
||||
|
||||
function doDelete(){
|
||||
}
|
||||
|
||||
function doDelete(){
|
||||
var rows = getCheckedRows(0);
|
||||
if(rows.length == 0){
|
||||
alert("请选择一行数据!");
|
||||
return;
|
||||
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;
|
||||
}
|
||||
var sendFlag = getItemValue(0,rows[i],"SEND_FLAG");
|
||||
if(sendFlag == 1){
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
if(!flag){
|
||||
alert("已发送的短信不能删除!");
|
||||
return;
|
||||
alert("已发送的短信不能删除!");
|
||||
return;
|
||||
}
|
||||
as_delete(0);
|
||||
}
|
||||
|
||||
function sendMessage(){
|
||||
}
|
||||
|
||||
function sendMessage(){
|
||||
var rows = getCheckedRows(0);
|
||||
if(rows.length == 0){
|
||||
alert("请选择一行数据!");
|
||||
return;
|
||||
alert("请选择一行数据!");
|
||||
return;
|
||||
}
|
||||
var ids = "";
|
||||
for(var i=0;i<rows.length;i++){
|
||||
ids += "@" + getItemValue(0,rows[i],"ID");
|
||||
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();
|
||||
alert("发送成功!");
|
||||
reloadSelf();
|
||||
}else{
|
||||
alert("发送失败!");
|
||||
reloadSelf();
|
||||
alert("发送失败!");
|
||||
reloadSelf();
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<%@ include file="/Frame/resources/include/include_end.jspf"%>
|
||||
@ -1,7 +1,14 @@
|
||||
package com.tenwa.lease.app.message;
|
||||
|
||||
import jbo.com.tenwa.lease.comm.LB_SMS_NOTICE_TASKS;
|
||||
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;
|
||||
@ -13,6 +20,7 @@ import com.tenwa.lease.util.SendMessageUtil;
|
||||
|
||||
public class SmsController {
|
||||
private String ids;
|
||||
|
||||
private Logger logger = Logger.getLogger(this.getClass());
|
||||
|
||||
public String getIds() {
|
||||
@ -49,6 +57,37 @@ public class SmsController {
|
||||
return "SUCCESS";
|
||||
}
|
||||
|
||||
public String selectBalance(JBOTransaction tx){
|
||||
try {
|
||||
//获取数据库中短信配置的相关参数
|
||||
List<BizObject> messageConfigList = JBOFactory.getBizObjectManager(LB_MESSAGE_CONFIG.CLASS_NAME, tx).createQuery("1=1").getResultList(false);
|
||||
BizObject messageConfig = messageConfigList.get(0);
|
||||
//用户名
|
||||
String sendUsername = messageConfig.getAttribute("SENDER_").getString();
|
||||
//密码
|
||||
String sendPassword = messageConfig.getAttribute("SENDER_PASSWORD_").getString();
|
||||
HttpClient httpClient = new HttpClient();
|
||||
//发送url
|
||||
String url = "http://api.app2e.com/getBalance.api.php?pwd="+sendPassword+"&username="+sendUsername;
|
||||
GetMethod getMethod = new GetMethod(url);
|
||||
int statusCode = httpClient.executeMethod(getMethod);
|
||||
System.out.println("状态码:"+statusCode);
|
||||
String result = "";
|
||||
if (statusCode == HttpStatus.SC_OK) {
|
||||
result = getMethod.getResponseBodyAsString();
|
||||
}else{
|
||||
result = statusCode + "";
|
||||
}
|
||||
JSONObject jsonObject=JSONObject.fromObject(result);
|
||||
String balance=jsonObject.get("balance").toString();
|
||||
getMethod.releaseConnection();
|
||||
return balance;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "查询失败";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getResultCodeInfo(String code){
|
||||
String codeMessage = "";
|
||||
switch(code){
|
||||
|
||||
@ -44,35 +44,33 @@ public class SendMessageUtil{
|
||||
List<BizObject> messageConfigList = JBOFactory.getBizObjectManager(LB_MESSAGE_CONFIG.CLASS_NAME).createQuery("1=1").getResultList(false);
|
||||
BizObject messageConfig = messageConfigList.get(0);
|
||||
String allowSendIps = messageConfig.getAttribute("ALLOW_SEND_IPS").getString();
|
||||
//判断本机电脑所有配置好的IP是否与短信配置中的符合
|
||||
if("N".equals(messageConfig.getAttribute("IS_SEND").getString()) || !getServerIsAllowSendMsg(allowSendIps)){
|
||||
System.out.println("短信设置为不发送短信或本机IP未在[允许发送短信的主机IP]之中!");
|
||||
return "当前系统IP不在允许发送的IP地址之中";
|
||||
}
|
||||
|
||||
String sendParamsUrl = messageConfig.getAttribute("SEND_PARAMS_URL_").getString();
|
||||
String[] sendParamsUrlArr = sendParamsUrl.split("&");
|
||||
|
||||
Map<String,String> model = new HashMap<String, String>();
|
||||
for(String str : sendParamsUrlArr){
|
||||
model.put(str.split("=")[0], str.split("=")[1]);
|
||||
}
|
||||
|
||||
HttpClient httpClient = new HttpClient();
|
||||
String sendMsg = "【安鹏租赁】"+msg;
|
||||
//从短信配置中根据对应字段获取要发送的地址和用户名,密码等信息
|
||||
String sendPassword = messageConfig.getAttribute("SENDER_PASSWORD_").getString();
|
||||
String sendMessageUrl = messageConfig.getAttribute("SEND_MESSAGE_URL_").getString();
|
||||
String sendUsername = messageConfig.getAttribute("SENDER_").getString();
|
||||
String content = java.net.URLEncoder.encode(sendMsg, "gbk");
|
||||
//通过HttpClient发送请求信息
|
||||
HttpClient httpClient = new HttpClient();
|
||||
String url = sendMessageUrl;
|
||||
String uid = model.get("uid");
|
||||
String auth = MD5Util.getMD5EncodedPassword(messageConfig.getAttribute("SENDER_").getString() + messageConfig.getAttribute("SENDER_PASSWORD_").getString());
|
||||
String content = java.net.URLEncoder.encode(msg, "gbk");
|
||||
PostMethod postMethod = new PostMethod(url);
|
||||
|
||||
NameValuePair[] data = { new NameValuePair("uid", uid),
|
||||
new NameValuePair("auth", auth),
|
||||
new NameValuePair("mobile", receiverMobilePhone),
|
||||
new NameValuePair("expid", "0"),
|
||||
new NameValuePair("msg", content) };
|
||||
//发送的参数
|
||||
NameValuePair[] data = {
|
||||
new NameValuePair("username", sendUsername),
|
||||
new NameValuePair("p", receiverMobilePhone),
|
||||
new NameValuePair("pwd", sendPassword),
|
||||
new NameValuePair("msg", content)
|
||||
//new NameValuePair("charSetStr","utf") 如果未来编码模式为utf-8可以设置此参数
|
||||
};
|
||||
postMethod.setRequestBody(data);
|
||||
|
||||
//返回的状态码
|
||||
int statusCode = httpClient.executeMethod(postMethod);
|
||||
System.out.println("状态码:"+statusCode);
|
||||
String result = "";
|
||||
if (statusCode == HttpStatus.SC_OK) {
|
||||
result = postMethod.getResponseBodyAsString();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user