java发送短信

Controller:

try {smsService.send(132****8954, SmsTemplateConstants.getSmsTemplate(1635955200000L,param));} catch (Exception e) {
                    logger.error("发送短信失败: ", e);
                }

smsService:

  String send(String phone, String content);

smsServiceImpl:

@Override
    public String send(String phone, String content) {
        logger.info("手机号:[{}],内容:[{}]", phone, content);
        if (!SpringContextHolder.getEnvironment().equals(SpringContextHolder.EnvironmentEnum.PROD)) {
            logger.info("当前处于[{}]环境,屏蔽短信发送", SpringContextHolder.getEnvironment());
            return "deny";
        }
        if (phone.length() != 11) {
            logger.info("手机号不正常,屏蔽短信发送");
            return "deny";
        }
        String result = HttpClient.doGet(url + "?phone=" + phone + "&content=" + content);
        logger.info("发送结果:", result);
        return result;
    }

SmsTemplateConstants类:

public static String SMS_TEMPLATE_SUCCESS = "短信模板";
public static String getSmsTemplate(1635955200000L,param) {
        return String.format(SMS_TEMPLATE_SUCCESS, param);
    }

你可能感兴趣的:(java,开发语言)