SendMsg

SendMsg.java





/**
 * Created on 2018/3/28.
 * Description:
 *    统一命令入口
 */
public class SendMsg {
    /**
     * @param args
     *
     * type=sendSMS:    [sendSMS]    [content] [phone number]
     * type=sendEspace: [sendEspace] [content] [job number]
     * type=sendEmail:  [sendEmail]  [subject] [content] [email] [Cc(Optional)] [Bcc(Optional)]
     */
    public static void main(String[] args) {
        checkParameter(args);

        String result = dispatchCmd(args);
        if (!CommonUtil.checkCloudPagerResult(result)) {
            CommonUtil.exitWithErrorMsg("send message error, details:" + result);
        }

        System.exit(CommonConstants.RET_SUCCESS);
    }

    private static String dispatchCmd(String[] args) {
        String result = null;
        MsgType msgType = MsgType.valueOf(args[0]);
        try {
            if (MsgType.sendSMS == msgType) {
                result = SendMsgUtil.sendSMS(args[2], args[1]);
            } else if(MsgType.sendEspace == msgType) {
                result = SendMsgUtil.SendMulEspace(args[2], args[1]);
            } else if(MsgType.sendEmail == msgType){
                String ccAddr = null;
                String bccAddr = null;
                if (args.length == 5) {
                    ccAddr = args[4];
                }
                if (args.length == 6) {
                    ccAddr = args[4];
                    bccAddr = args[5];
                }
                result = SendMsgUtil.sendEmail(args[3], ccAddr, bccAddr, args[1], args[2]);
            }
        } catch (Exception e) {
            CommonUtil.exitWithErrorMsg("send sms exception, details:" + e.getLocalizedMessage());
        }

        return result;
    }

    private static void checkParameter(String[] args) {
        if (null == args || args.length < 3) {
            showHelp();
            System.exit(CommonConstants.RET_FAIL);
        }

        String type = args[0];
        if (null == MsgType.valueOf(type)) {
            CommonUtil.exitWithErrorMsg("unsupported message type[sendSMS/sendEspace/sendEmail]");
        }

        if (MsgType.sendEmail == MsgType.valueOf(type)) {
            if (args.length < 4) {
                showHelp();
                System.exit(CommonConstants.RET_FAIL);
            }
        }
    }

    private static void showHelp() {
        String lineSeparator = System.lineSeparator();
        StringBuffer sb = new StringBuffer("Usage:");
        sb.append(lineSeparator).append("script need at least three parameters, format: [type] [] [].. ").append(lineSeparator);
        sb.append("1 type=sendSMS:    [sendSMS]    [content] [phone number(separate by \",\")] ").append(lineSeparator);
        sb.append("2 type=sendEspace: [sendEspace] [content] [job number(separate by \",\")] ").append(lineSeparator);
        sb.append("3 type=sendEmail:  [sendEmail]  [subject] [content] [email(separate by \",\")] [Cc(Optional)] [Bcc(Optional)] ").append(lineSeparator);
        System.out.println(sb.toString());
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值