【仅供内部供应商使用,不提供对外解答和培训】

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

接口作用

通过第三方短信平台发送短信,可以根据自己需求实现短信服务和监听服务。

正式服务器上使用该接口,需要购买了“短信平台”功能点,并在系统管理=>短信配置界面,开启短信平台,才可以使用。

 

接口内容

主要接口

SMSServiceProcessor
package com.fr.stable.fun;

import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.fr.stable.StringUtils;
import com.fr.stable.fun.mark.Immutable;

import java.util.List;
import java.util.Map;

/**
 * 第三方sms服务接入接口
 *
 * @author Lanlan
 */
public interface SMSServiceProcessor extends Immutable {

    int CURRENT_LEVEL = 1;

    String XML_TAG = "SMSServiceProcessor";

    /**
     * 根据内置的短信模板编号,转换成实际的第三方短信平台的短信模板
     *
     * @return 编号和实际模板的键值对集合
     */
    Map<String, String> mapping();

    /**
     * 发送测试短信
     *
     * @param mobile 接收短信的手机号
     * @return 结果
     */
    Response sendTest(String mobile);

    /**
     * FR包含的短信发送功能
     *
     * @param template 发送短信的模板(里面有参数,需要根据后面的para里的参数值进行替换)
     * @param mobile   接收短信的手机号
     * @param para     生成最终短信需要的参数
     * @param receiver 接收者(用户)
     * @return 结果
     * @throws Exception 异常
     */
    Response send(String template, String mobile, JSONObject para, String receiver) throws Exception;

    /**
     * FR包含的批量发送短信的功能
     *
     * @param template  发送短信的模板(里面有参数,需要根据后面的para里的参数值进行替换)
     * @param mobiles   接收短信的手机号列表
     * @param params    对应的生成最终短信需要的参数JSON数组
     * @param receivers 接收者(用户)列表,三个列表/数组,根据序号一一对应
     * @return 结果
     * @throws Exception 异常
     */
    Response batchSendSMS(String template, List<String> mobiles, JSONArray params, List<String> receivers) throws Exception;

    /**
     * 第三方sms服务响应
     */
    class Response {

        public final static String RES_STATUS_SUCCESS = "success";
        public final static String RES_STATUS_FAILED = "failed";

        private String status;
        private String msg;
        private JSONObject content;

        public static Response create(String status, String msg, JSONObject content) {
            if (StringUtils.isEmpty(status) || StringUtils.isEmpty(msg)) {
                return null;
            }
            if (content == null) {
                content = JSONObject.create();
            }
            return new Response(status, msg, content);
        }

        private Response(String status, String msg, JSONObject content) {
            this.status = status;
            this.msg = msg;
            this.content = content;
        }

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        public JSONObject getContent() {
            if (!content.has("status")) {
                content.put("status", status);
            }
            if (!content.has("msg")) {
                content.put("msg", msg);
            }
            return content;
        }

        public void setContent(JSONObject content) {
            this.content = content;
        }
    }
}
SMSListener
public interface SMSListener {

    /**
     * 短信发送前事件处理接口
     *
     * @param text      发送短信的模板(里面有参数,需要根据后面的para里的参数值进行替换)
     * @param mobiles   接收短信的手机号列表
     * @param params    生成最终短信需要的参数JSON数组
     * @param receivers 接收者(用户)列表
     */
    void beforeSend(String text, List<String> mobiles, JSONArray params, List<String> receivers);

    /**
     * 短信发送后事件处理接口
     *
     * @param text      发送短信的模板(里面有参数,需要根据后面的para里的参数值进行替换)
     * @param mobiles   接收短信的手机号列表
     * @param params    生成最终短信需要的参数JSON数组
     * @param receivers 接收者(用户)列表
     * @param response  响应(仅在使用了第三方服务接口后且仅在发送结束后事件有效!)
     */
    void afterSend(String text, List<String> mobiles, JSONArray params, List<String> receivers, SMSServiceProcessor.Response response);
}

关联接口

Immutable接口

接口接入

<extra-core>
    <SMSServiceProcessor class="com.fr.plugin.third.sms.SRGT"/>
</extra-core>

示例效果

接口示例

示例源码:https://git.fanruan.com/fanruan/demo-third-sms

注意事项

项目短信编号默认模板内容
日志清理预警49 
定时任务发送失败提醒10 
上报流程提醒54 
上报流程预警53 
短信平台告警136 
 短信平台开通通知19 
短息登录验证码20 
  • No labels