package com.uas.platform.b2b.support;

import com.uas.platform.b2b.core.util.ThreadUtils;
import com.uas.platform.b2b.temporary.model.SmsMessage;
import com.uas.platform.core.util.HttpUtil;
import com.uas.platform.core.util.serializer.FlexJsonUtils;

/**
 * 短信发送配置
 *
 * Created by hejq on 2018-05-14.
 */
public class SendMsgUtils {

    /**
     * 短信接口
     */
    final static String messageUrl = "http://message.ubtob.com/sms/send";

    /**
     * 发送短信
     *
     * @param receiver 短信接收人，电话号码
     * @param tempId 短信模板地址
     * @param args 消息内容
     */
    public static void sendMsg(final String receiver, final String tempId, final String... args) {
        ThreadUtils.task(new Runnable() {
            @Override
            public void run() {
                try {
                    SmsMessage sms = new SmsMessage();
                    sms.setParams(args);
                    sms.setReceiver(receiver);
                    sms.setTemplateId(tempId);
                    HttpUtil.sendPost(messageUrl, FlexJsonUtils.toJsonDeep(sms));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).run();
    }
}
