InBoxSendSmsService.java 1.97 KB
package com.yohoufo.inboxclient.sdk;

import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.service.model.msgcenter.sms.McSmsByMobileBO;
import com.yoho.service.model.sms.response.CommonRspBO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by chenchao on 2018/10/19.
 */
@Service
public class InBoxSendSmsService {


    private static Logger log = LoggerFactory.getLogger(InBoxSendSmsService.class);

    @Autowired
    private ServiceCaller serviceCaller;

    @Value("${yoho.message.controller.url}")
    private String  messageUrl;

    public void smsSendByMobile(String content, List<String> mobileList) {
        log.info("InBoxSendSmsService smsSendByMobile start, content {}, mobileList {}", content, mobileList);
        if(StringUtils.isEmpty(content) || CollectionUtils.isEmpty(mobileList)) {
            log.warn("InBoxSendSmsService smsSendByMobile fail! content is null or mobileList is empty");
            return;
        }
        McSmsByMobileBO[] boArray = new McSmsByMobileBO[mobileList.size()];
        for(int i=0; i<mobileList.size(); i++) {
            McSmsByMobileBO smsBo = new McSmsByMobileBO();
            smsBo.setMobile(mobileList.get(i));
            smsBo.setContent(content);
            //"smsProviderCode" : "3"
            smsBo.setSmsProviderCode("3");
            smsBo.setIsNoDisturb(0);//是否免打扰, 1-是 0-否
            boArray[i] = smsBo;
        }

        String url = messageUrl + "/mcSMS/smsSendByMobile";
        log.info("InBoxSendSmsService sendMessage url is {}", url);
        serviceCaller.post("message.sendMessage", url, boArray, CommonRspBO.class, null);
    }

}