com.aliyuncs.exceptions.ClientException Java Examples
The following examples show how to use
com.aliyuncs.exceptions.ClientException.
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: 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 #3
Source File: SmsService.java From microservice-recruit with Apache License 2.0 | 6 votes |
private boolean sendSms(String phoneNumber, String randomCode) { SendSmsRequest request = new SendSmsRequest(); request.setMethod(MethodType.POST); request.setPhoneNumbers(phoneNumber); request.setSignName("leader直聘"); request.setTemplateCode("SMS_130924380"); request.setTemplateParam("{\"code\":\"" + randomCode + "\"}"); try { SendSmsResponse sendSmsResponse = getAcsClient().getAcsResponse(request); if (sendSmsResponse.getCode() != null && sendSmsResponse.getCode().equals(Constant.OK)) { log.info("发送短信成功"); return true; } log.error(sendSmsResponse.getCode()); } catch (ClientException e) { log.error("ClientException异常:" + e.getMessage()); throw new MyException(ResultEnum.SEND_NOTE_ERROR); } log.error("发送短信失败"); return false; }
Example #4
Source File: AliSmsService.java From faster-framework-project with Apache License 2.0 | 6 votes |
@Override public boolean send(SendSmsRequest request) { try { IAcsClient acsClient = new DefaultAcsClient(profile); request.setMethod(MethodType.POST); SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request); if (sendSmsResponse.getCode() != null && sendSmsResponse.getCode(). equals("OK")) { return true; } } catch (ClientException e) { log.error(e.getMessage()); return false; } return false; }
Example #5
Source File: SMSUtil.java From anyline with Apache License 2.0 | 6 votes |
public SMSResult send(String sign, String template, String mobile, Map<String, String> params) { SMSResult result = new SMSResult(); try { if(BasicUtil.isEmpty(sign)){ sign = config.SMS_SIGN; } request.setPhoneNumbers(mobile); //必填:短信签名-可在短信控制台中找到 request.setSignName(sign); //必填:短信模板-可在短信控制台中找到 request.setTemplateCode(template); //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为 request.setTemplateParam(BeanUtil.map2json(params)); //hint 此处可能会抛出异常,注意catch SendSmsResponse response = client.getAcsResponse(request); result.setResult(true); } catch (ClientException e) { e.printStackTrace(); result.setCode(e.getErrCode()); result.setMsg(e.getErrMsg()); } return result; }
Example #6
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 #7
Source File: SmsListener.java From mogu_blog_v2 with Apache License 2.0 | 6 votes |
@RabbitListener(queues = "mogu.sms") public void sendSms(Map<String, String> map) { try { SendSmsResponse response = smsUtil.sendSms( map.get("mobile"), map.get("template_code"), map.get("sign_name"), map.get("param")); System.out.println("code:" + response.getCode()); System.out.println("message:" + response.getMessage()); } catch (ClientException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Example #8
Source File: AliyunSmsConfig.java From cloud-service with MIT License | 6 votes |
@Bean public IAcsClient iAcsClient() throws ClientException { // 设置超时时间-可自行调整 System.setProperty("sun.net.client.defaultConnectTimeout", "10000"); System.setProperty("sun.net.client.defaultReadTimeout", "10000"); // 初始化ascClient需要的几个参数 final String product = "Dysmsapi";// 短信API产品名称(短信产品名固定,无需修改) final String domain = "dysmsapi.aliyuncs.com";// 短信API产品域名(接口地址固定,无需修改) // 初始化ascClient,暂时不支持多region(请勿修改) IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret); DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain); IAcsClient acsClient = new DefaultAcsClient(profile); return acsClient; }
Example #9
Source File: OptSmsServiceImpl.java From paascloud-master with Apache License 2.0 | 6 votes |
@Override public SendSmsResponse sendSms(SendSmsRequest sendSmsRequest) { checkParam(sendSmsRequest); SendSmsResponse acsResponse; try { if (GlobalConstant.DEV_PROFILE.equals(profile)) { log.error("dev环境不发送短信"); return new SendSmsResponse(); } if (GlobalConstant.TEST_PROFILE.equals(profile)) { log.error("test环境不发送短信"); return new SendSmsResponse(); } acsResponse = iAcsClient.getAcsResponse(sendSmsRequest); } catch (ClientException e) { log.error("send sms message error={}", e.getMessage(), e); throw new OpcBizException(ErrorCodeEnum.OPC10040004, e); } log.info("send sms message OK acsResponse={}", acsResponse); return acsResponse; }
Example #10
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 #11
Source File: AliyunSmsConfig.java From open-capacity-platform with Apache License 2.0 | 6 votes |
@Bean public IAcsClient iAcsClient() throws ClientException { // 设置超时时间-可自行调整 System.setProperty("sun.net.client.defaultConnectTimeout", "10000"); System.setProperty("sun.net.client.defaultReadTimeout", "10000"); // 初始化ascClient需要的几个参数 logger.info("初始化阿里云接口:" + this); final String product = "Dysmsapi";// 短信API产品名称(短信产品名固定,无需修改) final String domain = "dysmsapi.aliyuncs.com";// 短信API产品域名(接口地址固定,无需修改) // 替换成你的AK // 初始化ascClient,暂时不支持多region(请勿修改) IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret); try { DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain); } catch (ClientException e) { logger.error("初始化阿里云客户端失败:" + e); } IAcsClient acsClient = new DefaultAcsClient(profile); return acsClient; }
Example #12
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 #13
Source File: OSSUtil.java From xnx3 with Apache License 2.0 | 6 votes |
static AssumeRoleResponse assumeRole(String accessKeyId, String accessKeySecret,String roleArn, String roleSessionName, String policy,ProtocolType protocolType) throws ClientException { try { // 创建一个 Aliyun Acs Client, 用于发起 OpenAPI 请求 IClientProfile profile = DefaultProfile.getProfile(region_cn_hangzhou, accessKeyId, accessKeySecret); DefaultAcsClient client = new DefaultAcsClient(profile); // 创建一个 AssumeRoleRequest 并设置请求参数 final AssumeRoleRequest request = new AssumeRoleRequest(); request.setVersion(sta_api_version); request.setMethod(MethodType.POST); request.setProtocol(protocolType); request.setRoleArn(roleArn); request.setRoleSessionName(roleSessionName); request.setPolicy(policy); // 发起请求,并得到response final AssumeRoleResponse response = client.getAcsResponse(request); return response; } catch (ClientException e) { throw e; } }
Example #14
Source File: SmsService.java From microservice-recruit with Apache License 2.0 | 6 votes |
private boolean sendSms(String phoneNumber, String randomCode) { SendSmsRequest request = new SendSmsRequest(); request.setMethod(MethodType.POST); request.setPhoneNumbers(phoneNumber); request.setSignName("leader直聘"); request.setTemplateCode("SMS_130924380"); request.setTemplateParam("{\"code\":\"" + randomCode + "\"}"); try { SendSmsResponse sendSmsResponse = getAcsClient().getAcsResponse(request); if (sendSmsResponse.getCode() != null && sendSmsResponse.getCode().equals(Constant.OK)) { log.info("发送短信成功"); return true; } log.error(sendSmsResponse.getCode()); } catch (ClientException e) { log.error("ClientException异常:" + e.getMessage()); throw new MyException(ResultEnum.SEND_NOTE_ERROR); } log.error("发送短信失败"); return false; }
Example #15
Source File: StsServiceSample.java From jframe with Apache License 2.0 | 6 votes |
static AssumeRoleResponse assumeRole(String accessKeyId, String accessKeySecret, String roleArn, String roleSessionName, String policy, ProtocolType protocolType) throws ClientException { try { // 创建一个 Aliyun Acs Client, 用于发起 OpenAPI 请求 IClientProfile profile = DefaultProfile.getProfile(REGION_CN_HANGZHOU, accessKeyId, accessKeySecret); DefaultAcsClient client = new DefaultAcsClient(profile); // 创建一个 AssumeRoleRequest 并设置请求参数 final AssumeRoleRequest request = new AssumeRoleRequest(); request.setVersion(STS_API_VERSION); request.setMethod(MethodType.POST); request.setProtocol(protocolType); request.setRoleArn(roleArn); request.setRoleSessionName(roleSessionName); request.setPolicy(policy); // 发起请求,并得到response final AssumeRoleResponse response = client.getAcsResponse(request); return response; } catch (ClientException e) { throw e; } }
Example #16
Source File: InstanceService.java From cs-actions with Apache License 2.0 | 6 votes |
private static AcsResponse getResponse(final String proxyHost, final String proxyPort, final String proxyUsername, final String proxyPassword, final IAcsClient client, final AcsRequest request) { try { if (!isEmpty(proxyHost)) { // Set JVM proxies during runtime ProxyUtil.setProxies(proxyHost, proxyPort, proxyUsername, proxyPassword); //Thread.sleep(30000); } return client.getAcsResponse(request); } catch (ClientException e) { throw new RuntimeException(e.getMessage()); } finally { if (!isEmpty(proxyHost)) { //Clear proxies ProxyUtil.clearProxy(); } } }
Example #17
Source File: DMServiceImpl.java From jframe with Apache License 2.0 | 5 votes |
@Override public SingleSendMailResponse singleSend(String id, SingleSendMailRequest request) throws ClientException { DefaultAcsClient client = clients.get(id); if (client == null) { throw new NullPointerException("not found dm id:" + id); } return client.getAcsResponse(request); }
Example #18
Source File: SimaplePhoneRegist.java From danyuan-application with Apache License 2.0 | 5 votes |
public void SendPhoneToCustom(String phone, String templateParam) throws ClientException { // 设置超时时间-可自行调整 System.setProperty("sun.net.client.defaultConnectTimeout", "10000"); System.setProperty("sun.net.client.defaultReadTimeout", "10000"); // 初始化ascClient需要的几个参数 final String product = "Dysmsapi";// 短信API产品名称(短信产品名固定,无需修改) final String domain = "dysmsapi.aliyuncs.com";// 短信API产品域名(接口地址固定,无需修改) // 替换成你的AK // 初始化ascClient,暂时不支持多region(请勿修改) IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", PHONE_ACCESSKEYID, PHONE_ACCESSKEYSECRET); DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain); IAcsClient acsClient = new DefaultAcsClient(profile); // 组装请求对象 SendSmsRequest request = new SendSmsRequest(); // 使用post提交 request.setMethod(MethodType.POST); // 必填:待发送手机号。支持以逗号分隔的形式进行批量调用,批量上限为1000个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式;发送国际/港澳台消息时,接收号码格式为国际区号+号码,如“85200000000” request.setPhoneNumbers(phone); // 必填:短信签名-可在短信控制台中找到 request.setSignName(PHONE_SIGNNAME); // 必填:短信模板-可在短信控制台中找到,发送国际/港澳台消息时,请使用国际/港澳台短信模版 request.setTemplateCode(PHONE_TEMPLATECODE); // 可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为 // 友情提示:如果JSON中需要带换行符,请参照标准的JSON协议对换行符的要求,比如短信内容中包含\r\n的情况在JSON中需要表示成\\r\\n,否则会导致JSON在服务端解析失败 request.setTemplateParam(templateParam); // 可选-上行短信扩展码(扩展码字段控制在7位或以下,无特殊需求用户请忽略此字段) // request.setSmsUpExtendCode("90997"); // 可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者 // request.setOutId("yourOutId"); // 请求失败这里会抛ClientException异常 SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request); if (sendSmsResponse.getCode() != null && sendSmsResponse.getCode().equals("OK")) { // 请求成功 } }
Example #19
Source File: SmsapiService.java From FlyCms with MIT License | 5 votes |
public static QuerySendDetailsResponse querySendDetails(String PhoneNumber,String bizId,String accessKeyId,String accessKeySecret) throws ClientException { //可自助调整超时时间 System.setProperty("sun.net.client.defaultConnectTimeout", "10000"); System.setProperty("sun.net.client.defaultReadTimeout", "10000"); //初始化acsClient,暂不支持region化 IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret); DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain); IAcsClient acsClient = new DefaultAcsClient(profile); //组装请求对象 QuerySendDetailsRequest request = new QuerySendDetailsRequest(); //必填-号码 request.setPhoneNumber(PhoneNumber); //可选-流水号 request.setBizId(bizId); //必填-发送日期 支持30天内记录查询,格式yyyyMMdd SimpleDateFormat ft = new SimpleDateFormat("yyyyMMdd"); request.setSendDate(ft.format(new Date())); //必填-页大小 request.setPageSize(10L); //必填-当前页码从1开始计数 request.setCurrentPage(1L); //hint 此处可能会抛出异常,注意catch QuerySendDetailsResponse querySendDetailsResponse = acsClient.getAcsResponse(request); return querySendDetailsResponse; }
Example #20
Source File: SMSServiceImpl.java From jframe with Apache License 2.0 | 5 votes |
@Override public SendSmsResponse send(String id, SendSmsRequest request) throws ClientException { DefaultAcsClient client = clients.get(id); if (client == null) { throw new NullPointerException("not found sms id:" + id); } return client.getAcsResponse(request);// TODO async }
Example #21
Source File: AliGreenService.java From lolibox with Apache License 2.0 | 5 votes |
@Override public float getCheckResult(String taskId) { ImageResultRequest imageResultRequest = new ImageResultRequest(); imageResultRequest.setTaskId(taskId); try { ImageResultResponse imageResultResponse = client.getAcsResponse(imageResultRequest); logger.info("Getting image detection result... {}^^^^{}", imageResultResponse.getCode(), imageResultResponse.getMsg()); if ("Success".equals(imageResultResponse.getCode()) && "TaskProcessSuccess".equals(imageResultResponse.getStatus())) { ImageResultResponse.ImageResult imageResult = imageResultResponse.getImageResult(); ImageResultResponse.ImageResult.PornResult pornResult = imageResult.getPornResult(); if (pornResult != null) { Integer label = pornResult.getLabel(); Float rate = pornResult.getRate(); return rate; } imageResult.getOcrResult(); imageResult.getIllegalResult(); } else { logger.error("Failed to get image check result"); } } catch (ClientException e) { logger.error("Failed to get image check result"); throw new RuntimeException(e); } logger.error("Failed to get image check result"); throw new RuntimeException("Failed to get image check result"); }
Example #22
Source File: AliSmsSend.java From charging_pile_cloud with MIT License | 5 votes |
/** * 发送短信 * * @param ali * @return * @throws IOException * @throws ClientException */ public static AliSendBack getYZM(AliParam ali) throws IOException, ClientException { //发短信 SendSmsResponse response = AliSmsUtil.sendSms(ali); AliSendBack sms = new AliSendBack(); sms.setCode(response.getCode()); sms.setMessage(response.getMessage()); sms.setBizId(response.getBizId()); sms.setRequestId(response.getRequestId()); return sms; }
Example #23
Source File: AliSmsService.java From faster-framework-project with Apache License 2.0 | 5 votes |
public AliSmsService(String accessKeyId, String accessKeySecret) { try { //初始化ascClient,暂时不支持多region(请勿修改) profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret); DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Dysmsapi", "dysmsapi.aliyuncs.com"); } catch (ClientException e) { e.printStackTrace(); } }
Example #24
Source File: AliyunSmsConfiguration.java From paascloud-master with Apache License 2.0 | 5 votes |
/** * Acs client acs client. * * @return the acs client * * @throws ClientException the client exception */ @Bean public IAcsClient acsClient() throws ClientException { log.info("SMS Bean IAcsClient Start"); IClientProfile profile = DefaultProfile.getProfile(paascloudProperties.getAliyun().getSms().getRegionId(), paascloudProperties.getAliyun().getKey().getAccessKeyId(), paascloudProperties.getAliyun().getKey().getAccessKeySecret()); DefaultProfile.addEndpoint(paascloudProperties.getAliyun().getSms().getEndpointName(), paascloudProperties.getAliyun().getSms().getRegionId(), paascloudProperties.getAliyun().getSms().getProduct(), paascloudProperties.getAliyun().getSms().getDomain()); DefaultAcsClient defaultAcsClient = new DefaultAcsClient(profile); log.info("加载SMS Bean IAcsClient OK"); return defaultAcsClient; }
Example #25
Source File: SmsUtil.java From codeway_service with GNU General Public License v3.0 | 5 votes |
/** * 查询发送详情 * @param mobile * @param bizId * @return QuerySendDetailsResponse */ public QuerySendDetailsResponse querySendDetails(String mobile, String bizId) throws ClientException { //可自助调整超时时间 System.setProperty("sun.net.client.defaultConnectTimeout","10000"); System.setProperty("sun.net.client.defaultReadTimeout", "10000"); //初始化acsClient,暂不支持region化 IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou",accessKeyId, accessKeySecret); DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product,domain); IAcsClient acsClient = new DefaultAcsClient(profile); //组装请求对象 QuerySendDetailsRequest request = new QuerySendDetailsRequest(); //必填‐号码 request.setPhoneNumber(mobile); //可选‐流水号 request.setBizId(bizId); //必填‐发送日期 支持30天内记录查询,格式yyyyMMdd SimpleDateFormat ft = new SimpleDateFormat("yyyyMMdd"); request.setSendDate(ft.format(new Date())); //必填‐页大小 request.setPageSize(10L); //必填‐当前页码从1开始计数 request.setCurrentPage(1L); //hint 此处可能会抛出异常,注意catch QuerySendDetailsResponse querySendDetailsResponse = acsClient.getAcsResponse(request); return querySendDetailsResponse; }
Example #26
Source File: SmsUtil.java From codeway_service with GNU General Public License v3.0 | 5 votes |
/** * 发送短信 * * @param mobile 手机号 * @param template_code 模板号 * @param sign_name 签名 * @param param 参数 * @return SendSmsResponse */ public SendSmsResponse sendSms(String mobile, String template_code, String sign_name, String param) throws ClientException { //可自助调整超时时间 System.setProperty("sun.net.client.defaultConnectTimeout","10000"); System.setProperty("sun.net.client.defaultReadTimeout", "10000"); //初始化acsClient,暂不支持region化 IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou",accessKeyId, accessKeySecret); DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product,domain); IAcsClient acsClient = new DefaultAcsClient(profile); //组装请求对象‐具体描述见控制台‐文档部分内容 SendSmsRequest request = new SendSmsRequest(); //必填:待发送手机号 request.setPhoneNumbers(mobile); //必填:短信签名‐可在短信控制台中找到 request.setSignName(sign_name); //必填:短信模板‐可在短信控制台中找到 request.setTemplateCode(template_code); //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为$ {code}"时,此处的值为("{\"name\":\"Tom\", \"code\":\"123\"}" request.setTemplateParam(param); //选填‐上行短信扩展码(无特殊需求用户请忽略此字段) //request.setSmsUpExtendCode("90997"); //可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者 request.setOutId("yourOutId"); //hint 此处可能会抛出异常,注意catch SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request); return sendSmsResponse; }
Example #27
Source File: SmsListener.java From codeway_service with GNU General Public License v3.0 | 5 votes |
/** * 发送短信 * @param message 监听到的数据 */ @RabbitHandler public SendSmsResponse sendSms(Map<String,String> message){ LogBack.info("手机号:{},验证码:{};", message.get("mobile"), message.get("code")); try { return smsUtil.sendSms(message.get("mobile"), template_code, sign_name, "{\"code\":\"" + message.get("code") + "\"}"); } catch (ClientException | NullPointerException e) { LogBack.error("发送手机验证码失败:{}", e.getMessage()); e.printStackTrace(); } return null; }
Example #28
Source File: AbstractAliSmsTemplate.java From fast-family-master with Apache License 2.0 | 5 votes |
@Override public IAcsClient getAcsClient() { IClientProfile profile = DefaultProfile.getProfile(aliSmsProperties.getRegionId(), aliSmsProperties.getAliyunAccessKeyId(), aliSmsProperties.getAliyunAccessKeySecret()); try { DefaultProfile.addEndpoint(aliSmsProperties.getEndPointName(), aliSmsProperties.getRegionId(), aliSmsProperties.getProduce(), aliSmsProperties.getDomain()); } catch (ClientException e) { throw new AliSmsException(e); } return new DefaultAcsClient(profile); }
Example #29
Source File: DefaultAliSmsTemplate.java From fast-family-master with Apache License 2.0 | 5 votes |
@Override public void sendSms(AliSmsEntity aliSmsEntity) { final IAcsClient acsClient = this.getAcsClient(); final CommonRequest request = this.getAliSmsRequest(aliSmsEntity); final CommonResponse response; try { response = acsClient.getCommonResponse(request); this.parseResponse(response); } catch (ClientException | IOException e) { throw new AliSmsException(e); } finally { acsClient.shutdown(); } }
Example #30
Source File: DySmsHelper.java From jeewx-boot with Apache License 2.0 | 5 votes |
/** * 发短信接口(短信模板编码自己传入) * @param templateCode * @param phone * @param json * @return * @throws ClientException */ public static boolean sendSms(String templateCode,String phone,JSONObject json) throws ClientException { //可自助调整超时时间 System.setProperty("sun.net.client.defaultConnectTimeout", "10000"); System.setProperty("sun.net.client.defaultReadTimeout", "10000"); //初始化acsClient,暂不支持region化 IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret); DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain); IAcsClient acsClient = new DefaultAcsClient(profile); //组装请求对象-具体描述见控制台-文档部分内容 SendSmsRequest request = new SendSmsRequest(); //必填:待发送手机号 request.setPhoneNumbers(phone); //必填:短信签名-可在短信控制台中找到 request.setSignName(msgSignName); //必填:短信模板-可在短信控制台中找到 request.setTemplateCode(templateCode); //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为 request.setTemplateParam(json.toString()); //选填-上行短信扩展码(无特殊需求用户请忽略此字段) //request.setSmsUpExtendCode("90997"); //可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者 //request.setOutId("yourOutId"); boolean result = false; //hint 此处可能会抛出异常,注意catch SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request); logger.info("短信接口返回的数据----------------"); logger.info("{Code:" + sendSmsResponse.getCode()+",Message:" + sendSmsResponse.getMessage()+",RequestId:"+ sendSmsResponse.getRequestId()+",BizId:"+sendSmsResponse.getBizId()+"}"); if ("OK".equals(sendSmsResponse.getCode())) { result = true; } return result; }