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

Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
titleSMSServiceProcessor
collapsetrue
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 结果
     */
    ThirdResponseResponse sendTest(String mobile);
   
    /**
     * FR包含的短信发送功能
     *
     * @param template 发送短信的模板(里面有参数,需要根据后面的para里的参数值进行替换)
     * @param mobile   接收短信的手机号
     * @param para     生成最终短信需要的参数
     * @param receiver 接收者(用户)
     * @return 结果
     * @throws Exception 异常
     */
    ThirdResponseResponse 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 异常
     */
    ThirdResponseResponse 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;
        }
    }
}
Code Block
titleSMSListener
collapsetrue
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, ThirdResponseSMSServiceProcessor.Response response);
}

关联接口

Immutable接口

...