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 mobiles, JSONArray params, List 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 mobiles, JSONArray params, List receivers) { System.out.println("发送短信前监听事件"); FineLoggerFactory.getLogger().info("发送短信前监听事件"); } @Override public void afterSend(String text, List mobiles, JSONArray params, List receivers, ThirdResponse response) { System.out.println("发送短信后监听事件"); FineLoggerFactory.getLogger().info("发送短信后监听事件"); } }); } }