删除失信企业湖南乐活科技lehuo520.cn乐云短信代码
This commit is contained in:
@@ -21,8 +21,7 @@ JeeSite 自开源以来已被广大爱好者用到了企业、政府、医疗、
|
||||
* 视图层:Spring MVC 4.3、Beetl 2.7 替换JSP、Bootstrap 3.3、AdminLTE 2.4
|
||||
* 前端组件:jQuery 1.12、jqGrid 4.7、layer 3.0、zTree 3.5、jquery-validation
|
||||
* 工具组件:Apache Commons、Logback 1.1、Jackson 2.8、POI 3.14、Quartz 2.2
|
||||
* JFlow工作流引擎:<https://gitee.com/thinkgem/jeesite4-jflow> :<http://ccflow.org>
|
||||
* 乐云短信网关:SmsUtils.java :<http://www.lehuo520.cn>
|
||||
* JFlow工作流引擎:<https://gitee.com/thinkgem/jeesite4-jflow> :http://ccflow.org
|
||||
* 技术选型详情:<http://jeesite4.mydoc.io/?t=273599>
|
||||
|
||||
## 内置功能菜单
|
||||
@@ -98,6 +97,7 @@ JeeSite的小版本(4.0.x)升级是非常便捷的,你只需要将 pom.xml
|
||||
* GitHub:<https://github.com/thinkgem/jeesite4>
|
||||
* 作者博客:<https://my.oschina.net/thinkgem>
|
||||
* 官方网站:<http://jeesite.com>
|
||||
* 官方论坛:<http://jeesite.net>
|
||||
* 微信公众号:
|
||||
|
||||

|
||||
|
||||
@@ -24,12 +24,12 @@ public class EmailUtils {
|
||||
* @return
|
||||
*/
|
||||
public static boolean send(String toAddress, String subject, String content) {
|
||||
PropertiesUtils loader = PropertiesUtils.getInstance();
|
||||
String fromAddress = loader.getProperty("msg.email.fromAddress");
|
||||
String fromPassword = loader.getProperty("msg.email.fromPassword");
|
||||
String fromHostName = loader.getProperty("msg.email.fromHostName");
|
||||
String sslOnConnect = loader.getProperty("msg.email.sslOnConnect", "false");
|
||||
String sslSmtpPort = loader.getProperty("msg.email.sslSmtpPort");
|
||||
PropertiesUtils props = PropertiesUtils.getInstance();
|
||||
String fromAddress = props.getProperty("msg.email.fromAddress");
|
||||
String fromPassword = props.getProperty("msg.email.fromPassword");
|
||||
String fromHostName = props.getProperty("msg.email.fromHostName");
|
||||
String sslOnConnect = props.getProperty("msg.email.sslOnConnect", "false");
|
||||
String sslSmtpPort = props.getProperty("msg.email.sslSmtpPort");
|
||||
return send(fromAddress, fromPassword, fromHostName, sslOnConnect, sslSmtpPort, toAddress, subject, content);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,141 +1,43 @@
|
||||
package com.jeesite.common.msg;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Date;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.jeesite.common.io.PropertiesUtils;
|
||||
import com.jeesite.common.lang.DateUtils;
|
||||
|
||||
/**
|
||||
* 发送短信(乐云短信)
|
||||
* 发送短信(请实现send方法)
|
||||
*/
|
||||
public class SmsUtils {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(SmsUtils.class);
|
||||
private final static PropertiesUtils props = PropertiesUtils.getInstance();
|
||||
private final static String url = props.getProperty("msg.sms.url", "http://lehuo520.cn/a/sms/api");
|
||||
private final static String data = props.getProperty("msg.sms.data", "username=jeesite&password=jeesite.com");
|
||||
private final static String prefix = props.getProperty("msg.sms.prefix", "【JeeSite】");
|
||||
private final static String suffix = props.getProperty("msg.sms.suffix", "");
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// String phone = "18500000000"; // 收短信人手机号码;例如:18500000000 支持多号码,号码之间用英文逗号隔开,最多100个
|
||||
// String content = "您好,您的验证码是:123456(请勿透露给其他人)感谢您的使用。"; // 输入需要发送内容;例如:你好这是一条测试短信
|
||||
// String smsid = ""; // 短信id,查询短信状态报告时需要,可为空
|
||||
// System.out.println(send(content, phone)); // 发短信
|
||||
// System.out.println(status(smsid, phone)); // 取状态
|
||||
// System.out.println(reply()); //取上行 回复短信
|
||||
// }
|
||||
|
||||
/**
|
||||
* 发送短信
|
||||
* @param content 接受内容
|
||||
* @param phone 接受手机号码
|
||||
* @return {"result":"0","describing":"提交成功","sms":[{"phone":"18073110001,18073110002","smsid":"83bd18f1d48b4cc9b9fe7810c768ac43","status":"3"}]}
|
||||
* 模拟发送短信
|
||||
* @param content 短信内容
|
||||
* @param mobile 接受手机号码
|
||||
*/
|
||||
public static String send(String content, String phone) {
|
||||
return send(content, phone, null);
|
||||
public static String send(String content, String mobile) {
|
||||
// PropertiesUtils props = PropertiesUtils.getInstance();
|
||||
// String url = props.getProperty("msg.sms.url");
|
||||
// String data = props.getProperty("msg.sms.data");
|
||||
// String prefix = props.getProperty("msg.sms.prefix", "");
|
||||
// String suffix = props.getProperty("msg.sms.suffix", "");
|
||||
// Connection conn = Jsoup.connect(url);
|
||||
// conn.postDataCharset("UTF-8");
|
||||
// conn.method(Method.POST);
|
||||
// for (String param : StringUtils.split(data, "&")){
|
||||
// String[] ss = StringUtils.split(param, "=");
|
||||
// if (ss.length == 1){
|
||||
// conn.data(ss[0], "");
|
||||
// }else if (ss.length == 2){
|
||||
// conn.data(ss[0], ss[1]);
|
||||
// }
|
||||
// }
|
||||
// // 手机号码
|
||||
// conn.data("mobile", mobile);
|
||||
// // 短信内容
|
||||
// conn.data("content", prefix + content + suffix);
|
||||
logger.warn("模拟发送短信成功!请实现 "+SmsUtils.class+" 的 send 方法。");
|
||||
return "{result:0,message:\"模拟发送短信成功!\"}";
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送短信
|
||||
* @param content 接受内容
|
||||
* @param phone 接受手机号码
|
||||
* @param sendtime 发送时间为空立即发送
|
||||
* @return {"result":"0","describing":"提交成功","sms":[{"phone":"18073110001,18073110002","smsid":"83bd18f1d48b4cc9b9fe7810c768ac43","status":"3"}]}
|
||||
*/
|
||||
public static String send(String content, String phone, Date sendTime) {
|
||||
String res = "";
|
||||
try {
|
||||
String param = data + "&phone=" + phone + "&content=" + URLEncoder
|
||||
.encode(prefix + content + suffix, "UTF-8")
|
||||
+ "&sendTime=" + (sendTime != null ? DateUtils
|
||||
.formatDate(sendTime, "yyyyMMddHHmm") : "");
|
||||
res = connectURL(url + "/send", param);
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态
|
||||
* @param smsid,phone可为空,为空取最近两天未获取状态报告,沦询间隔时间不能低于5分钟
|
||||
* @return 请求错误返回页面示例: {"result":"-1","describing":"帐号不存在,请检查用户名或者密码是否正确","sms":[]} 请求成功返回页面示例:
|
||||
* {"result":"0","describing":"提交成功","sms":[{"phone":"18073110001","smsid":"83bd18f1d48b4cc9b9fe7810c768ac43","status":"7"},{"phone":"18073110001","smsid":"83bd18f1d48b4cc9b9fe7810c768ac43","status":"8"}]}
|
||||
*/
|
||||
public static String status(String smsid, String phone) {
|
||||
String res = "";
|
||||
try {
|
||||
String param = data + "&smsid=" + smsid;
|
||||
res = connectURL(url + "/status", param);
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取回复
|
||||
* @param smsid:下发短信对应短信ID,taskId同一批任务ID
|
||||
* @return {"result":"0","sms":[{"phone":"18073110001","neirong":"已收到","taskId":"83bd18f1d48b4cc9b9fe7810c768ac43"},"smsId":"83bd18f1d48b48j9b9fe7810c768ac43"}]}
|
||||
*/
|
||||
public static String reply() {
|
||||
String res = "";
|
||||
try {
|
||||
String param = data;
|
||||
res = connectURL(url + "/query", param);
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 进行http提交
|
||||
* @param
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @throws Exception
|
||||
*/
|
||||
private static String connectURL(String url, String param) throws IOException {
|
||||
String res = "";
|
||||
HttpURLConnection urlConn = null;
|
||||
URL url1 = new URL(url);
|
||||
urlConn = (HttpURLConnection) url1.openConnection();
|
||||
urlConn.setRequestMethod("POST");
|
||||
urlConn.setDoOutput(true);
|
||||
OutputStream out = null;
|
||||
BufferedReader rd = null;
|
||||
try{
|
||||
out = urlConn.getOutputStream();
|
||||
out.write(param.getBytes("UTF-8"));
|
||||
out.flush();
|
||||
rd = new BufferedReader(new InputStreamReader(urlConn.getInputStream(), "UTF-8"));
|
||||
StringBuffer sb = new StringBuffer();
|
||||
int ch;
|
||||
while ((ch = rd.read()) > -1) {
|
||||
sb.append((char) ch);
|
||||
}
|
||||
res = sb.toString().trim();
|
||||
}finally {
|
||||
if (out!=null){
|
||||
out.close();
|
||||
}
|
||||
if (rd!=null){
|
||||
rd.close();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user