-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gejian
committed
Aug 21, 2018
1 parent
7efbf0a
commit 6677549
Showing
7 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.github.bthulu</groupId> | ||
<artifactId>msg-service</artifactId> | ||
<version>1.0.0</version> | ||
|
||
<properties> | ||
<slf4j.version>1.8.0-alpha2</slf4j.version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>${slf4j.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package bthulu.msg; | ||
|
||
/** | ||
* @author gejian at 2018/8/21 12:58 | ||
*/ | ||
public class SmsConfig { | ||
private String uri = "http://120.26.66.24/msg/HttpBatchSendSM"; | ||
private String security = "account=szajxx_hy&pswd=szajxx_hy123&product=109402988"; | ||
|
||
public SmsConfig() { | ||
} | ||
|
||
public String getUri() { | ||
return this.uri; | ||
} | ||
|
||
public void setUri(String uri) { | ||
this.uri = uri; | ||
} | ||
|
||
public String getSecurity() { | ||
return this.security; | ||
} | ||
|
||
public void setSecurity(String security) { | ||
this.security = security; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package bthulu.msg; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
import java.net.URLEncoder; | ||
|
||
/** | ||
* @author gejian at 2018/8/21 12:58 | ||
*/ | ||
public class SmsCore { | ||
private static final Logger log = LoggerFactory.getLogger(SmsCore.class); | ||
private SmsConfig smsConfig = new SmsConfig(); | ||
|
||
public SmsCore() { | ||
} | ||
|
||
public void setSmsConfig(SmsConfig smsConfig) { | ||
this.smsConfig = smsConfig; | ||
} | ||
|
||
public SmsResponse getSms(String phoneNo, String sign, String msg) throws IOException { | ||
char[] chars = sign.toCharArray(); | ||
if (chars[0] == 12304 && chars[chars.length - 1] == 12305) { | ||
String send = this.send(phoneNo, sign, msg, false); | ||
String[] split = send.split(","); | ||
return SmsResponse.getResponse(Integer.valueOf(split[1])); | ||
} else { | ||
throw new IllegalArgumentException("签名错误, 如无签名, 可传入默认值: 【安景软件】"); | ||
} | ||
} | ||
|
||
private String send(String phoneNo, String sign, String msg, boolean needstatus) throws IOException { | ||
msg = URLEncoder.encode(sign + msg, "UTF-8"); | ||
String requestURL = | ||
this.smsConfig.getUri() + "?" + this.smsConfig.getSecurity() + "&mobile=" + phoneNo + "&msg=" + msg | ||
+ "&needstatus=" + needstatus; | ||
if (log.isDebugEnabled()) { | ||
log.debug("短信请求报文: " + requestURL); | ||
} | ||
|
||
InputStream content = null; | ||
BufferedReader reader = null; | ||
|
||
String back; | ||
try { | ||
URL url = new URL(requestURL); | ||
URLConnection urlConnection = url.openConnection(); | ||
content = (InputStream) urlConnection.getContent(); | ||
reader = new BufferedReader(new InputStreamReader(content, "UTF-8")); | ||
back = reader.readLine(); | ||
} finally { | ||
if (content != null) { | ||
try { | ||
content.close(); | ||
} catch (IOException var19) { | ||
log.error("短信请求InputStream关闭失败! ", var19); | ||
} | ||
} | ||
|
||
if (reader != null) { | ||
try { | ||
reader.close(); | ||
} catch (IOException var18) { | ||
log.error("短信请求BufferedReader关闭失败! ", var18); | ||
} | ||
} | ||
|
||
} | ||
|
||
if (log.isTraceEnabled()) { | ||
log.trace("返回报文: " + back); | ||
} | ||
|
||
return back; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package bthulu.msg; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author gejian at 2018/8/21 12:58 | ||
*/ | ||
public class SmsResponse { | ||
private static final Logger log = LoggerFactory.getLogger(SmsResponse.class); | ||
private static final Map<Integer, String> RESPONSE_MAP = new HashMap(19); | ||
private static final SmsResponse OK; | ||
|
||
static { | ||
RESPONSE_MAP.put(0, "提交成功"); | ||
RESPONSE_MAP.put(101, "无此用户"); | ||
RESPONSE_MAP.put(102, "密码错误"); | ||
RESPONSE_MAP.put(103, "提交过快(提交速度超过流速限制)"); | ||
RESPONSE_MAP.put(104, "系统忙(因平台的原因,暂时无法处理提交的短信)"); | ||
RESPONSE_MAP.put(105, "敏感短信(短信内容包含敏感词)"); | ||
RESPONSE_MAP.put(106, "消息长度错误(>536或<=0)"); | ||
RESPONSE_MAP.put(108, "手机号码个数错误(群发>50000或<=0;)"); | ||
RESPONSE_MAP.put(109, "无发送额度(该用户可用短信数已使用完)"); | ||
RESPONSE_MAP.put(110, "不在发送时间内"); | ||
RESPONSE_MAP.put(111, "超出该账户当月发送额度限制"); | ||
RESPONSE_MAP.put(112, "无此产品,用户没有订购该产品"); | ||
RESPONSE_MAP.put(113, "extno格式错(非数字或者长度不对)"); | ||
RESPONSE_MAP.put(115, "自动审核驳回"); | ||
RESPONSE_MAP.put(116, "签名不合法,未带签名(用户必须带签名的前提下)"); | ||
RESPONSE_MAP.put(117, "IP地址认证错,请求调用的IP地址不是系统登记的IP地址"); | ||
RESPONSE_MAP.put(118, "用户没有相应的发送权限"); | ||
RESPONSE_MAP.put(119, "用户已过期"); | ||
RESPONSE_MAP.put(120, "内容不在白名单中"); | ||
OK = new SmsResponse(0, "提交成功"); | ||
} | ||
|
||
private int stat; | ||
private String msg; | ||
|
||
private SmsResponse(int stat, String msg) { | ||
this.stat = stat; | ||
this.msg = msg; | ||
} | ||
|
||
static SmsResponse getResponse(int stat) { | ||
if (stat == 0) { | ||
return OK; | ||
} else { | ||
SmsResponse response = new SmsResponse(stat, (String) RESPONSE_MAP.get(stat)); | ||
if (log.isWarnEnabled()) { | ||
log.warn(response.toString()); | ||
} | ||
|
||
return response; | ||
} | ||
} | ||
|
||
public Integer getStat() { | ||
return this.stat; | ||
} | ||
|
||
public String getMsg() { | ||
return this.msg; | ||
} | ||
|
||
public String toString() { | ||
return "SmsResponse{stat=" + this.stat + ", msg='" + this.msg + '\'' + '}'; | ||
} | ||
} |
Empty file.
Empty file.