Java Code Examples for com.aliyuncs.CommonRequest#setVersion()
The following examples show how to use
com.aliyuncs.CommonRequest#setVersion() .
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 pybbs with GNU Affero General Public License v3.0 | 7 votes |
public boolean sendSms(String mobile, String code) { try { if (StringUtils.isEmpty(mobile)) return false; // 获取连接 if (this.instance() == null) return false; // 构建请求体 CommonRequest request = new CommonRequest(); //request.setProtocol(ProtocolType.HTTPS); request.setMethod(MethodType.POST); request.setDomain("dysmsapi.aliyuncs.com"); request.setVersion("2017-05-25"); request.setAction("SendSms"); request.putQueryParameter("RegionId", regionId); request.putQueryParameter("PhoneNumbers", mobile); request.putQueryParameter("SignName", signName); request.putQueryParameter("TemplateCode", templateCode); request.putQueryParameter("TemplateParam", String.format("{\"code\": \"%s\"}", code)); CommonResponse response = client.getCommonResponse(request); //{"Message":"OK","RequestId":"93E35E66-B2B2-4D7A-8AC9-2BDD97F5FB18","BizId":"689615750980282428^0","Code":"OK"} Map responseMap = JsonUtil.jsonToObject(response.getData(), Map.class); if (responseMap.get("Code").equals("OK")) return true; } catch (ClientException e) { log.error(e.getMessage()); } return false; }
Example 2
Source File: SmsHelper.java From tools with MIT License | 6 votes |
/** * Send SMS * * @param phones Mobile phone number, multiple with English commas separated, the maximum of 1000 * @param templateCode SMS template code * @param signName SMS sign name * @param param The actual value of the SMS template variable * @return Send the receipt */ public String send(String phones, String templateCode, String signName, Map<String, ?> param) { CommonRequest request = new CommonRequest(); request.setMethod(MethodType.POST); request.setDomain(DO_MAIN); request.setVersion(VERSION); request.setAction("sendSms"); request.putQueryParameter("PhoneNumbers", phones); if (param != null) { request.putQueryParameter("TemplateParam", new Gson().toJson(param)); } request.putQueryParameter("TemplateCode", templateCode); request.putQueryParameter("SignName", signName); try { CommonResponse response = this.client.getCommonResponse(request); return response.getData(); } catch (ClientException e) { throw new ToolsAliyunException(e.getMessage()); } }
Example 3
Source File: SmsHelper.java From tools with MIT License | 6 votes |
/** * Query the record of sending the specified mobile phone number * * @param phone Mobile phone number * @param sendDate Send date,Format for yyyy-MM-dd * @param page Query page * @param row No more than 50 pages per page * @return Query results */ public String findSendDetail(String phone, String sendDate, long page, long row) { if (row > 50) { throw new IllegalArgumentException("每页条数不能大于50"); } CommonRequest request = new CommonRequest(); request.setMethod(MethodType.POST); request.setDomain(DO_MAIN); request.setVersion(VERSION); request.setAction("QuerySendDetails"); request.putQueryParameter("PhoneNumber", phone); request.putQueryParameter("SendDate", sendDate.replaceAll("-", "")); request.putQueryParameter("PageSize", String.valueOf(row)); request.putQueryParameter("CurrentPage", String.valueOf(page)); try { CommonResponse commonResponse = this.client.getCommonResponse(request); return commonResponse.getData(); } catch (ClientException e) { throw new ToolsAliyunException(e.getMessage()); } }
Example 4
Source File: AbstractAliSmsTemplate.java From fast-family-master with Apache License 2.0 | 6 votes |
@Override public CommonRequest getAliSmsRequest(T t) { CommonRequest request = new CommonRequest(); request.setAction("SendSms"); request.setVersion("2017-05-25"); request.setMethod(MethodType.POST); request.setDomain(aliSmsProperties.getDomain()); request.setProduct(aliSmsProperties.getProduce()); request.setEndpointType(aliSmsProperties.getEndPointName()); request.putQueryParameter("PhoneNumbers", t.getMobile()); request.putQueryParameter("TemplateCode", t.getTemplateCode()); request.putQueryParameter("TemplateParam", JSONObject.toJSONString(t.getParams())); request.putQueryParameter("SignName", t.getSignName()); request.putQueryParameter("OutId", t.getOutId()); return request; }
Example 5
Source File: NoticeService.java From ticket with GNU General Public License v3.0 | 5 votes |
public void send(NoticeModel noticeModel) { try { Gson gson = new Gson(); Map<String, String> map = new HashMap<>(); map.put("name", noticeModel.getName()); map.put("username", noticeModel.getUserName()); map.put("password", noticeModel.getPassword()); map.put("orderId", noticeModel.getOrderId()); DefaultProfile profile = DefaultProfile.getProfile("default", noticeConfig.getAccessKeyId(), noticeConfig.getAccessSecret()); IAcsClient client = new DefaultAcsClient(profile); CommonRequest request = new CommonRequest(); request.setProtocol(ProtocolType.HTTPS); request.setMethod(MethodType.GET); request.setDomain(apiConfig.getNotice()); request.setVersion("2017-05-25"); request.setAction("SendSms"); request.putQueryParameter("PhoneNumbers", noticeModel.getPhoneNumber()); request.putQueryParameter("SignName", noticeConfig.getSignName()); request.putQueryParameter("TemplateCode", noticeConfig.getTemplateCode()); request.putQueryParameter("TemplateParam", gson.toJson(map)); CommonResponse response = client.getCommonResponse(request); map = gson.fromJson(response.getData(), Map.class); if (map.get("Code").equals("OK")) { log.debug("短信通知通知完成{}!", noticeModel.getPhoneNumber()); } else { log.error("短信通知失败:" + map); } } catch (Exception e) { log.error("短信通知失败:" + noticeModel, e); } }
Example 6
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 7
Source File: AliYunSmsUtils.java From pre with GNU General Public License v3.0 | 4 votes |
public static SmsResponse sendSms(String phone, String signName, String templateCode) { SmsResponse smsResponse = new SmsResponse(); //初始化ascClient DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", ACCESS_KEY_ID, ACCESS_KEY_SECRET); IAcsClient client = new DefaultAcsClient(profile); //组装请求对象 CommonRequest request = new CommonRequest(); /** * 使用post提交 */ request.setMethod(MethodType.POST); //可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者 //request.setOutId("1454"); request.setDomain("dysmsapi.aliyuncs.com"); request.setVersion("2017-05-25"); request.setAction("SendSms"); request.putQueryParameter("RegionId", "cn-hangzhou"); //待发送的手机号 request.putQueryParameter("PhoneNumbers", phone); //短信签名 request.putQueryParameter("SignName", signName); if ("登录".equals(templateCode)){ templateCode = "SMS_172887387"; } else if ("注册".equals(templateCode)){ templateCode = "SMS_172887416"; } //短信模板ID request.putQueryParameter("TemplateCode", templateCode); //验证码 /** * 可选:模板中的变量替换JSON串, */ String random = RandomStringUtils.random(6, false, true); request.putQueryParameter("TemplateParam", "{\"code\":\"" + random + "\"}"); request.putQueryParameter("OutId", random); try { CommonResponse response = client.getCommonResponse(request); String responseData = response.getData(); JSONObject jsonObject = JSONObject.parseObject(responseData); String code = (String) jsonObject.get("Code"); if (StrUtil.isNotEmpty(code) && "OK".equals(code)) { //请求成功 log.info(phone + ",发送短信成功"); smsResponse.setSmsCode(random); smsResponse.setSmsPhone(phone); smsResponse.setSmsTime(System.nanoTime() + ""); return smsResponse; } else { log.error(phone + ",发送短信失败:{}", jsonObject.get("Message")); } } catch (ClientException e) { log.error(phone + ",发送短信失败:{}", e.getMessage()); } return null; }