Java Code Examples for com.aliyuncs.CommonRequest#setSysAction()
The following examples show how to use
com.aliyuncs.CommonRequest#setSysAction() .
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: SmsClient.java From aliyun-sms with Apache License 2.0 | 8 votes |
/** * 发送短信. * * @param smsTemplate 短信模板 */ public void send(final SmsTemplate smsTemplate) { Objects.requireNonNull(smsTemplate); checkSmsTemplate(smsTemplate); final CommonRequest request = new CommonRequest(); request.setSysMethod(MethodType.POST); request.setSysDomain("dysmsapi.aliyuncs.com"); request.setSysVersion("2017-05-25"); request.setSysAction("SendSms"); request.putQueryParameter("PhoneNumbers", String.join(",", smsTemplate.getPhoneNumbers())); request.putQueryParameter("SignName", smsTemplate.getSignName()); request.putQueryParameter("TemplateCode", smsTemplate.getTemplateCode()); request.putQueryParameter("TemplateParam", Utils.toJsonStr(smsTemplate.getTemplateParam())); try { final CommonResponse response = this.acsClient.getCommonResponse(request); checkSmsResponse(response); } catch (final ClientException e) { throw new SmsException(e); } }
Example 2
Source File: SmsClient.java From aliyun-sms with Apache License 2.0 | 6 votes |
/** * 批量发送短信. * * <p> * 批量发送短信接口,支持在一次请求中分别向多个不同的手机号码发送不同签名的短信。 * 手机号码,签名,模板参数字段个数相同,一一对应,短信服务根据字段的顺序判断发往指定手机号码的签名。 * * <p> * 如果您需要往多个手机号码中发送同样签名的短信,请使用 {@link #send(SmsTemplate)}。 * * @param batchSmsTemplate 批量发送短信模板 */ public void send(final BatchSmsTemplate batchSmsTemplate) { Objects.requireNonNull(batchSmsTemplate); checkBatchSmsTemplate(batchSmsTemplate); final CommonRequest request = new CommonRequest(); request.setSysMethod(MethodType.POST); request.setSysDomain("dysmsapi.aliyuncs.com"); request.setSysVersion("2017-05-25"); request.setSysAction("SendBatchSms"); request.putQueryParameter("PhoneNumberJson", this.gson.toJson(batchSmsTemplate.getPhoneNumbers())); request.putQueryParameter("SignNameJson", this.gson.toJson(batchSmsTemplate.getSignNames())); request.putQueryParameter("TemplateCode", batchSmsTemplate.getTemplateCode()); request.putQueryParameter("TemplateParamJson", this.gson.toJson(batchSmsTemplate.getTemplateParams())); try { final CommonResponse response = this.acsClient.getCommonResponse(request); checkSmsResponse(response); } catch (final ClientException e) { throw new SmsException(e); } }
Example 3
Source File: AliyunSmsSenderImpl.java From open-cloud with MIT License | 5 votes |
@Override public Boolean send(SmsMessage parameter) { boolean result = false; try { // 地域ID DefaultProfile profile = DefaultProfile.getProfile( "cn-hangzhou", accessKeyId, accessKeySecret); IAcsClient client = new DefaultAcsClient(profile); CommonRequest request = new CommonRequest(); request.setSysMethod(MethodType.POST); request.setSysDomain("dysmsapi.aliyuncs.com"); request.setSysVersion("2017-05-25"); request.setSysAction("SendSms"); request.putQueryParameter("RegionId", "cn-hangzhou"); request.putQueryParameter("PhoneNumbers", parameter.getPhoneNum()); request.putQueryParameter("SignName", parameter.getSignName()); request.putQueryParameter("TemplateCode", parameter.getTplCode()); request.putQueryParameter("TemplateParam", parameter.getTplParams()); CommonResponse response = client.getCommonResponse(request); System.out.println(response.toString()); JSONObject json = JSONObject.parseObject(response.getData()); result = OK.equalsIgnoreCase(json.getString(CODE)); log.info("result:{}", response.getData()); } catch (Exception e) { log.error("发送短信失败:{}", e.getMessage(), e); } return result; }
Example 4
Source File: SmsOtpAuthnAliyun.java From MaxKey with Apache License 2.0 | 5 votes |
@Override public boolean produce(UserInfo userInfo) { // 手机号 String mobile = userInfo.getMobile(); if (mobile != null && !mobile.equals("")) { try { DefaultProfile profile = DefaultProfile.getProfile( "cn-hangzhou", accessKeyId, accessSecret); IAcsClient client = new DefaultAcsClient(profile); String token = this.genToken(userInfo); CommonRequest request = new CommonRequest(); request.setSysMethod(MethodType.POST); request.setSysDomain("dysmsapi.aliyuncs.com"); request.setSysVersion("2017-05-25"); request.setSysAction("SendSms"); request.putQueryParameter("RegionId", "cn-hangzhou"); request.putQueryParameter("PhoneNumbers", mobile); request.putQueryParameter("SignName", signName); request.putQueryParameter("TemplateCode", templateCode); request.putQueryParameter("TemplateParam", "{\"code\":\"" + token + "\"}"); CommonResponse response = client.getCommonResponse(request); logger.debug("responseString " + response.getData()); //成功返回 if (response.getData().indexOf("OK") > -1) { this.optTokenStore.store( userInfo, token, userInfo.getMobile(), OptTypes.SMS); return true; } } catch (Exception e) { logger.error(" produce code error ", e); } } return false; }
Example 5
Source File: AliyunVmsMessageNotifier.java From super-cloudops with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public void send(GenericNotifyMessage msg) { CommonRequest req = new CommonRequest(); // 请求方法分为POST和GET,建议您选择POST方式 req.setSysMethod(MethodType.POST); // Domain参数的默认值为dyvmsapi.aliyuncs.com req.setSysDomain("dyvmsapi.aliyuncs.com"); req.setSysVersion("2017-05-25"); // SingleCallByTts|SingleCallByVoice req.setSysAction(msg.getParameterAsString(KEY_VMS_ACTION, "SingleCallByTts")); // VoiceCode和TtsCode二选一即可,前者用于自定义语音文件通知,后者用于标准语音通知, // action都为SingleCallByTts,参考文档: // https://help.aliyun.com/document_detail/114036.html?spm=a2c4g.11186623.6.579.7bc95f33wpPjWM // https://help.aliyun.com/document_detail/114035.html?spm=a2c4g.11186623.6.581.56295ad5EBbcwv# String ttsCodeOrVoiceCode = config.getAliyun().getTemplates().getProperty(msg.getTemplateKey()); // 自定义语音文件ID req.putQueryParameter("VoiceCode", ttsCodeOrVoiceCode); // 标准文本转语音模板ID req.putQueryParameter("TtsCode", ttsCodeOrVoiceCode); req.putQueryParameter("TtsParam", toJSONString(msg.getParameters())); req.putQueryParameter("CalledShowNumber", config.getAliyun().getCalledShowNumber()); String calledNumber = msg.getToObjects().get(0); req.putQueryParameter("CalledNumber", calledNumber); req.putQueryParameter("PlayTimes", msg.getParameterAsString(KEY_VMS_PLAYTIMES, "2")); req.putQueryParameter("Volume", msg.getParameterAsString(KEY_VMS_VOLUME, "100")); req.putQueryParameter("Speed", msg.getParameterAsString(KEY_VMS_SPEED, "100")); req.putQueryParameter("OutId", msg.getCallbackId()); try { log.debug("Aliyun vms request: {}", () -> toJSONString(req)); CommonResponse resp = acsClient.getCommonResponse(req); if (!isNull(resp) && !isBlank(resp.getData())) { Properties body = parseJSON(resp.getData(), Properties.class); if (!isNull(body) && "OK".equalsIgnoreCase((String) body.get("Code"))) { if (log.isDebugEnabled()) log.debug("Successed response: {}, request: {}", resp.getData(), toJSONString(req)); else log.info("Successed calledNumer: {}, message: {}", calledNumber, msg.getParameters()); } else log.warn("Failed response: {}, request: {}", resp.getData(), toJSONString(req)); } else throw new NotificationException(kind(), format("Failed to vms request", toJSONString(req))); } catch (Exception e) { throw new NotificationException(kind(), e.getMessage(), e); } }