Browse Source

第三方短信平台示例

master
richie 5 years ago
parent
commit
4547cad5ca
  1. 5
      .gitignore
  2. 10
      plugin.xml
  3. 28
      readme.md
  4. BIN
      screenshots/open.png
  5. BIN
      screenshots/open2.png
  6. BIN
      screenshots/open3.png
  7. BIN
      screenshots/open4.png
  8. 66
      src/main/java/com/fr/plugin/third/sms/SRGT.java
  9. 20
      src/main/java/com/fr/plugin/third/sms/ThirdSmsHandlerBridge.java
  10. 73
      src/main/java/com/fr/plugin/third/sms/ThirdSmsService.java
  11. 20
      src/main/java/com/fr/plugin/third/sms/ThirdSmsURLAliasBridge.java
  12. 40
      src/main/java/com/fr/plugin/third/sms/fun/SmsClient.java
  13. 43
      src/main/java/com/fr/plugin/third/sms/test/SmsTestHandler.java

5
.gitignore vendored

@ -0,0 +1,5 @@
*.iml
.idea/
lib/report/*.jar
target/
.DS_Store

10
plugin.xml

@ -5,11 +5,15 @@
<active>yes</active>
<version>1.0</version>
<env-version>10.0</env-version>
<jartime>2017-11-17</jartime>
<jartime>2019-11-06</jartime>
<vendor>Lanlan</vendor>
<description><![CDATA[第三方短信插件]]></description>
<function-recorder class="com.fr.plugin.third.sms.SRGT"/>
<extra-core>
<SMSServiceProcessor class="com.fr.plugin.third.sms.SRGT"/>
<SMSServiceProvider class="com.fr.plugin.third.sms.ThirdSmsService"/>
</extra-core>
<extra-decision>
<HttpHandlerProvider class="com.fr.plugin.third.sms.ThirdSmsHandlerBridge"/>
<URLAliasProvider class="com.fr.plugin.third.sms.ThirdSmsURLAliasBridge"/>
</extra-decision>
<function-recorder class="com.fr.plugin.third.sms.ThirdSmsService"/>
</plugin>

28
readme.md

@ -0,0 +1,28 @@
# 第三方短信平台插件
## 开启短信
使用该插件可以不使用帆软内置的短信平台,只需要在购买该功能点后,通过插件使用自己的短信平台即可,如下图所示:
![open](screenshots/open.png)
给管理员绑定手机号:
![open2](screenshots/open2.png)
绑定好后如图:
![open3](screenshots/open3.png)
开启短信验证密码:
![open4](screenshots/open4.png)
## 测试方式
可以在登录决策平台后,访问[http://localhost:8075/webroot/decision/url/ts/simple/test](http://localhost:8075/webroot/decision/url/ts/simple/test),尝试发送测试短信。
## 测试时获取验证码
可以直接在日志中看到要短信发送的内容。

BIN
screenshots/open.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

BIN
screenshots/open2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

BIN
screenshots/open3.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

BIN
screenshots/open4.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 KiB

66
src/main/java/com/fr/plugin/third/sms/SRGT.java

@ -1,66 +0,0 @@
package com.fr.plugin.third.sms;
import com.fr.base.sms.SMSContext;
import com.fr.base.top.impl.AbstractSMSServiceProcessor;
import com.fr.base.top.impl.SMSListenerAdapter;
import com.fr.base.top.impl.ThirdResponse;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.transform.ExecuteFunctionRecord;
import com.fr.plugin.transform.FunctionRecorder;
import java.util.List;
/**
* @author Lanlan
* @date 2019/1/29
*/
@FunctionRecorder
public class SRGT extends AbstractSMSServiceProcessor {
public SRGT() {
startListener();
}
@Override
public ThirdResponse sendTest(String mobile) {
System.out.println("发送测试短信成功");
FineLoggerFactory.getLogger().info("发送测试短信成功");
return ThirdResponse.create(ThirdResponse.RES_STATUS_SUCCESS, "发送测试短信成功", JSONObject.create());
}
@Override
@ExecuteFunctionRecord
public ThirdResponse send(String template, String mobile, JSONObject para, String receiver) throws Exception {
System.out.println("发送普通短信成功");
FineLoggerFactory.getLogger().info("发送普通短信成功");
return ThirdResponse.create(ThirdResponse.RES_STATUS_SUCCESS, "发送普通短信成功", JSONObject.create());
}
@Override
public ThirdResponse batchSendSMS(String template, List<String> mobiles, JSONArray params, List<String> receivers) throws Exception {
System.out.println("发送批量短信成功");
FineLoggerFactory.getLogger().info("发送批量短信成功");
return ThirdResponse.create(ThirdResponse.RES_STATUS_SUCCESS, "发送批量短信成功", JSONObject.create());
}
/**
* 启动发送短信的监听器
*/
private void startListener() {
SMSContext.addSmsListener(new SMSListenerAdapter() {
@Override
public void beforeSend(String text, List<String> mobiles, JSONArray params, List<String> receivers) {
System.out.println("发送短信前监听事件");
FineLoggerFactory.getLogger().info("发送短信前监听事件");
}
@Override
public void afterSend(String text, List<String> mobiles, JSONArray params, List<String> receivers, ThirdResponse response) {
System.out.println("发送短信后监听事件");
FineLoggerFactory.getLogger().info("发送短信后监听事件");
}
});
}
}

20
src/main/java/com/fr/plugin/third/sms/ThirdSmsHandlerBridge.java

@ -0,0 +1,20 @@
package com.fr.plugin.third.sms;
import com.fr.decision.fun.HttpHandler;
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider;
import com.fr.plugin.third.sms.test.SmsTestHandler;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/8
*/
public class ThirdSmsHandlerBridge extends AbstractHttpHandlerProvider {
@Override
public HttpHandler[] registerHandlers() {
return new HttpHandler[] {
new SmsTestHandler()
};
}
}

73
src/main/java/com/fr/plugin/third/sms/ThirdSmsService.java

@ -0,0 +1,73 @@
package com.fr.plugin.third.sms;
import com.fr.base.sms.SMSContext;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.third.sms.fun.SmsClient;
import com.fr.plugin.transform.ExecuteFunctionRecord;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.stable.fun.impl.AbstractSMSServiceProvider;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Lanlan
* @date 2019/1/29
*/
@FunctionRecorder
public class ThirdSmsService extends AbstractSMSServiceProvider {
public ThirdSmsService() {
startListener();
}
@Override
public Map<String, String> mapping() {
Map<String, String> map = new HashMap<>();
map.put("16", "【短信模板】您的手机验证码为#Verifiecode#,请于10分钟内正确输入。");
return map;
}
@Override
public Response sendTest(String mobile) {
SmsClient.getInstance().send(mobile);
return Response.create(Response.RES_STATUS_SUCCESS, "发送测试短信成功", JSONObject.create());
}
@Override
@ExecuteFunctionRecord
public Response send(String template, String mobile, JSONObject para, String receiver) throws Exception {
SmsClient.getInstance().send(template, mobile, para, receiver);
FineLoggerFactory.getLogger().info("短信模板:{}, 手机号:{},参数:{}", template, mobile, para);
return Response.create(Response.RES_STATUS_SUCCESS, "发送普通短信成功", JSONObject.create());
}
@Override
public Response batchSendSMS(String template, List<String> mobiles, JSONArray params, List<String> receivers) throws Exception {
SmsClient.getInstance().batchSend(template, mobiles, params, receivers);
return Response.create(Response.RES_STATUS_SUCCESS, "发送批量短信成功", JSONObject.create());
}
/**
* 启动发送短信的监听器
*/
private void startListener() {
SMSContext.addSmsListener(new Listener() {
@Override
public void beforeSend(String text, List<String> mobiles, JSONArray params, List<String> receivers) {
System.out.println("发送短信前监听事件");
FineLoggerFactory.getLogger().info("发送短信前监听事件");
}
@Override
public void afterSend(String text, List<String> mobiles, JSONArray params, List<String> receivers, Response response) {
System.out.println("发送短信后监听事件");
FineLoggerFactory.getLogger().info("发送短信后监听事件");
}
});
}
}

20
src/main/java/com/fr/plugin/third/sms/ThirdSmsURLAliasBridge.java

@ -0,0 +1,20 @@
package com.fr.plugin.third.sms;
import com.fr.decision.fun.impl.AbstractURLAliasProvider;
import com.fr.decision.webservice.url.alias.URLAlias;
import com.fr.decision.webservice.url.alias.URLAliasFactory;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/8
*/
public class ThirdSmsURLAliasBridge extends AbstractURLAliasProvider {
@Override
public URLAlias[] registerAlias() {
return new URLAlias[]{
URLAliasFactory.createPluginAlias("/ts/simple/test", "/ts/test", false)
};
}
}

40
src/main/java/com/fr/plugin/third/sms/fun/SmsClient.java

@ -0,0 +1,40 @@
package com.fr.plugin.third.sms.fun;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import java.util.List;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/8
* 这个是短信发送的客户端调用各家实际短信发送平台这里只通过输出日志的方式提供一个示例
*/
public class SmsClient {
private static SmsClient instance = new SmsClient();
public static SmsClient getInstance() {
return instance;
}
public boolean send(String mobile) {
System.out.println("发送测试短信成功");
FineLoggerFactory.getLogger().info("发送测试短信成功");
return true;
}
public boolean send(String template, String mobile, JSONObject para, String receiver) {
System.out.println("发送普通短信成功");
FineLoggerFactory.getLogger().info("发送普通短信成功");
return true;
}
public boolean batchSend(String template, List<String> mobiles, JSONArray params, List<String> receivers) {
System.out.println("发送批量短信成功");
FineLoggerFactory.getLogger().info("发送批量短信成功");
return true;
}
}

43
src/main/java/com/fr/plugin/third/sms/test/SmsTestHandler.java

@ -0,0 +1,43 @@
package com.fr.plugin.third.sms.test;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.plugin.third.sms.fun.SmsClient;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/8
*/
public class SmsTestHandler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
return RequestMethod.GET;
}
@Override
public String getPath() {
return "/ts/test";
}
@Override
public boolean isPublic() {
return false;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
String mobile = "13898675683";
boolean status = SmsClient.getInstance().send(mobile);
if (status) {
WebUtils.printAsString(res, "已向" + mobile + "发送测试短信");
} else {
WebUtils.printAsString(res, "向" + mobile + "发送测试短信失败");
}
}
}
Loading…
Cancel
Save