richie
5 years ago
13 changed files with 236 additions and 69 deletions
@ -0,0 +1,5 @@
|
||||
*.iml |
||||
.idea/ |
||||
lib/report/*.jar |
||||
target/ |
||||
.DS_Store |
@ -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),尝试发送测试短信。 |
||||
|
||||
## 测试时获取验证码 |
||||
|
||||
可以直接在日志中看到要短信发送的内容。 |
||||
|
||||
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 73 KiB |
After Width: | Height: | Size: 138 KiB |
After Width: | Height: | Size: 39 KiB |
After Width: | Height: | Size: 242 KiB |
@ -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("发送短信后监听事件"); |
||||
} |
||||
}); |
||||
} |
||||
} |
@ -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() |
||||
}; |
||||
} |
||||
} |
@ -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("发送短信后监听事件"); |
||||
} |
||||
}); |
||||
} |
||||
} |
@ -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) |
||||
}; |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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…
Reference in new issue