SmsChinesePipeline.java 1003 Bytes
package com.diligrp.assistant.sms.pipeline;

import com.diligrp.assistant.sms.client.SmsChineseHttpClient;
import com.diligrp.assistant.sms.domain.SmsMessage;
import com.diligrp.assistant.sms.type.PipelineType;

import java.util.stream.Collectors;

/**
 * 网建短信服务通道
 */
// TODO: 数据库中进行通道配置
public class SmsChinesePipeline extends SmsPipeline {

    private final SmsChineseHttpClient client;

    public SmsChinesePipeline(int code, String name, String uri, String uid, String secretKey) {
        super(code, name, PipelineType.SMS_CHINESE);
        this.client = new SmsChineseHttpClient(uri, uid, secretKey);
    }

    @Override
    public boolean templateSupported() {
        return false;
    }

    @Override
    public String sendSmsMessage(SmsMessage message) {
        String telephones = message.getTelephones().stream().collect(Collectors.joining());
        return client.sendSmsMessage(telephones, message.getContent(), message.getSignature());
    }
}