Java Code Examples for com.aliyuncs.CommonResponse#getHttpStatus()
The following examples show how to use
com.aliyuncs.CommonResponse#getHttpStatus() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SmsService.java From spring-microservice-exam with MIT License | 5 votes |
/** * 发送短信 * * @param smsDto smsDto * @return SmsResponse * @author tangyi * @date 2019/06/22 13:28 */ public SmsResponse sendSms(SmsDto smsDto) { DefaultProfile profile = DefaultProfile.getProfile(smsProperties.getRegionId(), smsProperties.getAppKey(), smsProperties.getAppSecret()); IAcsClient client = new DefaultAcsClient(profile); CommonRequest request = new CommonRequest(); request.setMethod(MethodType.POST); request.setDomain(smsProperties.getDomain()); request.putQueryParameter("RegionId", smsProperties.getRegionId()); request.putQueryParameter("PhoneNumbers", smsDto.getReceiver()); request.putQueryParameter("SignName", smsProperties.getSignName()); request.putQueryParameter("TemplateCode", smsProperties.getTemplateCode()); request.putQueryParameter("TemplateParam", smsDto.getContent()); request.setVersion(smsProperties.getVersion()); request.setAction(smsProperties.getAction()); try { CommonResponse response = client.getCommonResponse(request); log.info("response: {}", response.getData()); if (response.getHttpStatus() != 200) throw new CommonException(response.getData()); SmsResponse smsResponse = JsonMapper.getInstance().fromJson(response.getData(), SmsResponse.class); if (smsResponse == null) throw new CommonException("Parse response error"); if (!"OK".equals(smsResponse.getCode())) throw new CommonException(smsResponse.getMessage()); return smsResponse; } catch (Exception e) { log.error(e.getMessage(), e); throw new CommonException("Send message failed: " + e.getMessage()); } }
Example 2
Source File: DefaultAliSmsTemplate.java From fast-family-master with Apache License 2.0 | 5 votes |
private void parseResponse(final CommonResponse response) throws IOException { log.debug("response : {}", response.getData()); final AliSmsReponse smsReponse = new ObjectMapper().readValue(response.getData(), AliSmsReponse.class); if (response.getHttpStatus() != 200 || !"OK".equals(smsReponse.getCode())) { log.error("发送短信失败,状态码:{},返回数据:{}", response.getHttpStatus(), smsReponse); throw new AliSmsException(smsReponse.getMessage()); } }
Example 3
Source File: Utils.java From aliyun-sms with Apache License 2.0 | 5 votes |
/** * 校验 SendSmsResponse 状态. * * @param response the SendSmsResponse */ static void checkSmsResponse(final CommonResponse response) { if (null == response) { throw new SmsException("Response is null"); } final Gson gson = new Gson(); final Map<String, String> json = gson.fromJson(response.getData(), Map.class); if (!SUCCESS_CODE.equalsIgnoreCase(json.get("Code"))) { throw new SmsException("Http status: " + response.getHttpStatus() + ", response: " + response.getData()); } }