@Test public void testSendSms() throws ClientException { SendSmsResponse sendSmsResponse = new SendSmsResponse(); sendSmsResponse.setCode("OK"); sendSmsResponse.setRequestId("mock_id"); when(iAcsClient.getAcsResponse(any(SendSmsRequest.class))).thenReturn(sendSmsResponse); String phoneNumber = "18001112222"; String templateCode = "TESTCODE_XXXXXX"; String templateParam = "TESTPARAM_YYYYYY"; SmsRequest smsRequest = SmsRequest.builder() .to(phoneNumber) .templateCode(templateCode) .templateParam(templateParam) .build(); BaseResponse baseResponse = smsClient.send(AuthConstant.AUTHORIZATION_BOT_SERVICE, smsRequest); assertThat(baseResponse.isSuccess()).isTrue(); ArgumentCaptor<SendSmsRequest> argument = ArgumentCaptor.forClass(SendSmsRequest.class); verify(iAcsClient, times(1)).getAcsResponse(argument.capture()); SendSmsRequest sendSmsRequest = argument.getValue(); assertThat(sendSmsRequest.getPhoneNumbers()).isEqualTo(phoneNumber); assertThat(sendSmsRequest.getTemplateCode()).isEqualTo(templateCode); assertThat(sendSmsRequest.getTemplateParam()).isEqualTo(templateParam); assertThat(sendSmsRequest.getSignName()).isEqualTo(appProps.getAliyunSmsSignName()); sendSmsResponse.setCode("FAIL"); when(iAcsClient.getAcsResponse(any(SendSmsRequest.class))).thenReturn(sendSmsResponse); baseResponse = smsClient.send(AuthConstant.AUTHORIZATION_BOT_SERVICE, smsRequest); assertThat(baseResponse.isSuccess()).isTrue(); }
@PostMapping(path = "/queue_send") @Authorize({ AuthConstant.AUTHORIZATION_COMPANY_SERVICE, AuthConstant.AUTHORIZATION_ACCOUNT_SERVICE, AuthConstant.AUTHORIZATION_BOT_SERVICE }) public BaseResponse send(@RequestBody @Valid SmsRequest smsRequest) { if (appProps.isWhiteListOnly()) { String whiteList = appProps.getWhiteListPhoneNumbers(); boolean allowedToSend = !StringUtils.isEmpty(whiteList) && whiteList.contains(smsRequest.getTo()); if (!allowedToSend) { String msg = String.format("prevented sending to number %s due to whitelist", smsRequest.getTo()); logger.warn(msg); return BaseResponse.builder().code(ResultCode.REQ_REJECT).message(msg).build(); } } smsSendService.sendSmsAsync(smsRequest); String msg = String.format("sent message to %s. async", smsRequest.getTo()); logger.debug(msg); return BaseResponse.builder().message(msg).build(); }
SmsController { @PostMapping(path = "/queue_send") @Authorize({ AuthConstant.AUTHORIZATION_COMPANY_SERVICE, AuthConstant.AUTHORIZATION_ACCOUNT_SERVICE, AuthConstant.AUTHORIZATION_BOT_SERVICE }) public BaseResponse send(@RequestBody @Valid SmsRequest smsRequest) { if (appProps.isWhiteListOnly()) { String whiteList = appProps.getWhiteListPhoneNumbers(); boolean allowedToSend = !StringUtils.isEmpty(whiteList) && whiteList.contains(smsRequest.getTo()); if (!allowedToSend) { String msg = String.format("prevented sending to number %s due to whitelist", smsRequest.getTo()); logger.warn(msg); return BaseResponse.builder().code(ResultCode.REQ_REJECT).message(msg).build(); } } smsSendService.sendSmsAsync(smsRequest); String msg = String.format("sent message to %s. async", smsRequest.getTo()); logger.debug(msg); return BaseResponse.builder().message(msg).build(); } }
SmsController { @PostMapping(path = "/queue_send") @Authorize({ AuthConstant.AUTHORIZATION_COMPANY_SERVICE, AuthConstant.AUTHORIZATION_ACCOUNT_SERVICE, AuthConstant.AUTHORIZATION_BOT_SERVICE }) public BaseResponse send(@RequestBody @Valid SmsRequest smsRequest) { if (appProps.isWhiteListOnly()) { String whiteList = appProps.getWhiteListPhoneNumbers(); boolean allowedToSend = !StringUtils.isEmpty(whiteList) && whiteList.contains(smsRequest.getTo()); if (!allowedToSend) { String msg = String.format("prevented sending to number %s due to whitelist", smsRequest.getTo()); logger.warn(msg); return BaseResponse.builder().code(ResultCode.REQ_REJECT).message(msg).build(); } } smsSendService.sendSmsAsync(smsRequest); String msg = String.format("sent message to %s. async", smsRequest.getTo()); logger.debug(msg); return BaseResponse.builder().message(msg).build(); }  }
SmsController { @PostMapping(path = "/queue_send") @Authorize({ AuthConstant.AUTHORIZATION_COMPANY_SERVICE, AuthConstant.AUTHORIZATION_ACCOUNT_SERVICE, AuthConstant.AUTHORIZATION_BOT_SERVICE }) public BaseResponse send(@RequestBody @Valid SmsRequest smsRequest) { if (appProps.isWhiteListOnly()) { String whiteList = appProps.getWhiteListPhoneNumbers(); boolean allowedToSend = !StringUtils.isEmpty(whiteList) && whiteList.contains(smsRequest.getTo()); if (!allowedToSend) { String msg = String.format("prevented sending to number %s due to whitelist", smsRequest.getTo()); logger.warn(msg); return BaseResponse.builder().code(ResultCode.REQ_REJECT).message(msg).build(); } } smsSendService.sendSmsAsync(smsRequest); String msg = String.format("sent message to %s. async", smsRequest.getTo()); logger.debug(msg); return BaseResponse.builder().message(msg).build(); }  @PostMapping(path = "/queue_send") @Authorize({ AuthConstant.AUTHORIZATION_COMPANY_SERVICE, AuthConstant.AUTHORIZATION_ACCOUNT_SERVICE, AuthConstant.AUTHORIZATION_BOT_SERVICE }) BaseResponse send(@RequestBody @Valid SmsRequest smsRequest); }
SmsController { @PostMapping(path = "/queue_send") @Authorize({ AuthConstant.AUTHORIZATION_COMPANY_SERVICE, AuthConstant.AUTHORIZATION_ACCOUNT_SERVICE, AuthConstant.AUTHORIZATION_BOT_SERVICE }) public BaseResponse send(@RequestBody @Valid SmsRequest smsRequest) { if (appProps.isWhiteListOnly()) { String whiteList = appProps.getWhiteListPhoneNumbers(); boolean allowedToSend = !StringUtils.isEmpty(whiteList) && whiteList.contains(smsRequest.getTo()); if (!allowedToSend) { String msg = String.format("prevented sending to number %s due to whitelist", smsRequest.getTo()); logger.warn(msg); return BaseResponse.builder().code(ResultCode.REQ_REJECT).message(msg).build(); } } smsSendService.sendSmsAsync(smsRequest); String msg = String.format("sent message to %s. async", smsRequest.getTo()); logger.debug(msg); return BaseResponse.builder().message(msg).build(); }  @PostMapping(path = "/queue_send") @Authorize({ AuthConstant.AUTHORIZATION_COMPANY_SERVICE, AuthConstant.AUTHORIZATION_ACCOUNT_SERVICE, AuthConstant.AUTHORIZATION_BOT_SERVICE }) BaseResponse send(@RequestBody @Valid SmsRequest smsRequest);  }