diff --git a/WebContent/Tenwa/Lease/App/Interface/Message/LBSmsNoticeTasksList.jsp b/WebContent/Tenwa/Lease/App/Interface/Message/LBSmsNoticeTasksList.jsp index 652daf38f..82634a139 100644 --- a/WebContent/Tenwa/Lease/App/Interface/Message/LBSmsNoticeTasksList.jsp +++ b/WebContent/Tenwa/Lease/App/Interface/Message/LBSmsNoticeTasksList.jsp @@ -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"%> <%@ include file="/Frame/resources/include/include_end.jspf"%> \ No newline at end of file diff --git a/src_tenwa/com/tenwa/lease/app/message/SmsController.java b/src_tenwa/com/tenwa/lease/app/message/SmsController.java index 1c918f87e..ce34ac64c 100644 --- a/src_tenwa/com/tenwa/lease/app/message/SmsController.java +++ b/src_tenwa/com/tenwa/lease/app/message/SmsController.java @@ -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 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){ diff --git a/src_tenwa/com/tenwa/lease/util/SendMessageUtil.java b/src_tenwa/com/tenwa/lease/util/SendMessageUtil.java index 0b33e898b..125d20f28 100644 --- a/src_tenwa/com/tenwa/lease/util/SendMessageUtil.java +++ b/src_tenwa/com/tenwa/lease/util/SendMessageUtil.java @@ -44,35 +44,33 @@ public class SendMessageUtil{ List 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 model = new HashMap(); - 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();