Java Code Examples for com.aliyuncs.profile.IClientProfile

The following examples show how to use com.aliyuncs.profile.IClientProfile. These examples are extracted from open source projects. 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 Project: open-capacity-platform   Source File: AliyunSmsConfig.java    License: Apache License 2.0 6 votes vote down vote up
@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 2
Source Project: cloud-service   Source File: AliyunSmsConfig.java    License: MIT License 6 votes vote down vote up
@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 3
Source Project: anyline   Source File: SMSUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static SMSUtil getInstance(String key){ 
	if(BasicUtil.isEmpty(key)){ 
		key = "default"; 
	} 
	SMSUtil util = instances.get(key); 
	if(null == util){ 
		util = new SMSUtil(); 
		SMSConfig config = SMSConfig.getInstance(key); 
		util.config = config; 
		try { 
			System.setProperty("sun.net.client.defaultConnectTimeout", "10000"); 
	        System.setProperty("sun.net.client.defaultReadTimeout", "10000"); 

	        //初始化acsClient,暂不支持region化 
	        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", config.ACCESS_KEY, config.ACCESS_SECRET); 
	        DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain); 
	        util.client = new DefaultAcsClient(profile); 
		} 
        catch (Exception e) { 
			e.printStackTrace(); 
        	e.printStackTrace(); 
        } 
		instances.put(key, util); 
	} 
	return util; 
}
 
Example 4
Source Project: api-boot   Source File: ApiBootAliYunSmsService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * invoke send SMS
 *
 * @param request {@link ApiBootSmsRequest}
 * @return {@link ApiBootSmsResponse}
 * @throws ApiBootException ApiBoot Exception
 */
@Override
public ApiBootSmsResponse send(ApiBootSmsRequest request) throws ApiBootException {
    try {
        IClientProfile profile = DefaultProfile.getProfile(this.profile, this.accessKeyId, this.accessKeySecret);
        DefaultProfile.addEndpoint(this.profile, ALIYUN_PRODUCT, ALIYUN_PRODUCT_DOMAIN);
        IAcsClient acsClient = new DefaultAcsClient(profile);

        SendSmsRequest sendSmsRequest = new SendSmsRequest();
        sendSmsRequest.setPhoneNumbers(request.getPhone());
        sendSmsRequest.setSignName(this.signName);
        sendSmsRequest.setTemplateCode(request.getTemplateCode());
        sendSmsRequest.setTemplateParam(request.getParam().getParamJson());

        SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(sendSmsRequest);

        return ApiBootSmsResponse.builder().success(SUCCESS_RESULT.equals(sendSmsResponse.getCode())).build();

    } catch (Exception e) {
        throw new ApiBootException("invoke send SMS have Exception:" + e.getMessage());
    }
}
 
Example 5
Source Project: xnx3   Source File: OSSUtil.java    License: Apache License 2.0 6 votes vote down vote up
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 6
Source Project: jframe   Source File: STSServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Start
void start() {
    LOG.info("Start STSService");

    try {
        String file = plugin.getConfig(FILE_ALISTS, plugin.getConfig(Config.APP_CONF) + "/alists.properties");
        if (!new File(file).exists()) { throw new FileNotFoundException("not found " + file); }
        _config.init(file);
        for (String id : _config.getGroupIds()) {
            // 创建一个 Aliyun Acs Client, 用于发起 OpenAPI 请求
            IClientProfile profile = DefaultProfile.getProfile(_config.getConf(id, K_regionId), _config.getConf(id, K_accessKeyId),
                    _config.getConf(id, K_accessKeySecret));
            DefaultAcsClient client = new DefaultAcsClient(profile);
            clients.put(id, client);
        }
    } catch (Exception e) {
        LOG.error("Start STSService Failure!" + e.getMessage(), e);
        return;
    }
    LOG.info("Start STSService Successfully!");
}
 
Example 7
Source Project: jframe   Source File: SMSServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Start
void start() {
    LOG.info("Start SMSService");

    try {
        String file = plugin.getConfig(FILE_ALISMS, plugin.getConfig(Config.APP_CONF) + "/alisms.properties");
        if (!new File(file).exists()) { throw new FileNotFoundException("not found " + file); }
        _config.init(file);
        for (String id : _config.getGroupIds()) {
            // 创建一个 Aliyun Acs Client, 用于发起 OpenAPI 请求
            IClientProfile profile = DefaultProfile.getProfile(_config.getConf(id, K_regionId), _config.getConf(id, K_accessKeyId),
                    _config.getConf(id, K_accessKeySecret));
            String regionId = _config.getConf(id, K_regionId, "cn-hangzhou");
            String product = _config.getConf(id, K_product, "Dysmsapi");
            String domain = _config.getConf(id, K_domain, "dysmsapi.aliyuncs.com");
            DefaultProfile.addEndpoint(regionId, product, domain);

            DefaultAcsClient client = new DefaultAcsClient(profile);
            clients.put(id, client);
        }
    } catch (Exception e) {
        LOG.error("Start SMSService Failure!" + e.getMessage(), e);
        return;
    }
    LOG.info("Start SMSService Successfully!");
}
 
Example 8
Source Project: jframe   Source File: StsServiceSample.java    License: Apache License 2.0 6 votes vote down vote up
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 9
Source Project: jeewx-boot   Source File: DySmsHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 发短信接口(固定:登录验证码模板)
 * @param phone
 * @param json
 * @return
 * @throws ClientException
 */
public static boolean sendSms(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.setMethod(MethodType.POST);
    //选填-上行短信扩展码(无特殊需求用户请忽略此字段)
    //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;
}
 
Example 10
Source Project: jeewx-boot   Source File: DySmsHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 发短信接口(短信模板编码自己传入)
 * @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;
}
 
Example 11
Source Project: codeway_service   Source File: SmsUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 发送短信
 *
 * @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 12
Source Project: codeway_service   Source File: SmsUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 查询发送详情
 * @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 13
Source Project: staffjoy   Source File: AppConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public IAcsClient acsClient() {
    IClientProfile profile = DefaultProfile.getProfile(MailConstant.ALIYUN_REGION_ID,
            appProps.getAliyunAccessKey(), appProps.getAliyunAccessSecret());
    IAcsClient client = new DefaultAcsClient(profile);
    return client;
}
 
Example 14
Source Project: staffjoy   Source File: AppConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public IAcsClient acsClient(@Autowired SentryClient sentryClient) {
    IClientProfile profile = DefaultProfile.getProfile(SmsConstant.ALIYUN_REGION_ID, appProps.getAliyunAccessKey(), appProps.getAliyunAccessSecret());
    try {
        DefaultProfile.addEndpoint(SmsConstant.ALIYUN_SMS_ENDPOINT_NAME, SmsConstant.ALIYUN_REGION_ID, SmsConstant.ALIYUN_SMS_PRODUCT, SmsConstant.ALIYUN_SMS_DOMAIN);
    } catch (ClientException ex) {
        sentryClient.sendException(ex);
        logger.error("Fail to create acsClient ", ex);
    }
    IAcsClient client = new DefaultAcsClient(profile);
    return client;
}
 
Example 15
Source Project: leyou   Source File: SmsUtils.java    License: Apache License 2.0 5 votes vote down vote up
public SendSmsResponse sendSms(String phone, String code, String signName, String template) throws ClientException {

        // 可自助调整超时时间
        System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
        System.setProperty("sun.net.client.defaultReadTimeout", "10000");

        // 初始化acsClient,暂不支持region化
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou",
                prop.getAccessKeyId(), prop.getAccessKeySecret());
        DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
        IAcsClient acsClient = new DefaultAcsClient(profile);

        // 组装请求对象-具体描述见控制台-文档部分内容
        SendSmsRequest request = new SendSmsRequest();
        request.setMethod(MethodType.POST);
        // 必填:待发送手机号
        request.setPhoneNumbers(phone);
        // 必填:短信签名-可在短信控制台中找到
        request.setSignName(signName);
        // 必填:短信模板-可在短信控制台中找到
        request.setTemplateCode(template);
        // 可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
        request.setTemplateParam("{\"code\":\"" + code + "\"}");

        // 选填-上行短信扩展码(无特殊需求用户请忽略此字段)
        //request.setSmsUpExtendCode("90997");

        // 可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
        request.setOutId("123456");

        // hint 此处可能会抛出异常,注意catch
        SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);

        logger.info("发送短信状态:{}", sendSmsResponse.getCode());
        logger.info("发送短信消息:{}", sendSmsResponse.getMessage());

        return sendSmsResponse;
    }
 
Example 16
Source Project: mogu_blog_v2   Source File: SmsUtil.java    License: Apache License 2.0 5 votes vote down vote up
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}"时,此处的值为
        request.setTemplateParam(param);

        //选填-上行短信扩展码(无特殊需求用户请忽略此字段)
        //request.setSmsUpExtendCode("90997");

        //可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
        request.setOutId("yourOutId");

        //hint 此处可能会抛出异常,注意catch
        SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);

        return sendSmsResponse;
    }
 
Example 17
Source Project: mogu_blog_v2   Source File: SmsUtil.java    License: Apache License 2.0 5 votes vote down vote up
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 18
private void sendSms(String mobile, String templateCode, Map<String, String> params) throws ClientException {

        //可自助调整超时时间
        System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
        System.setProperty("sun.net.client.defaultReadTimeout", "10000");

        //初始化acsClient,暂不支持region化
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", aLiDaYu.getAccessKeyId(), aLiDaYu.getAccessKeySecret());
        DefaultProfile.addEndpoint("cn-hangzhou", PRODUCT, DOMAIN);
        IAcsClient acsClient = new DefaultAcsClient(profile);

        //组装请求对象-具体描述见控制台-文档部分内容
        SendSmsRequest request = new SendSmsRequest();
        //必填:待发送手机号
        request.setPhoneNumbers(mobile);
        //必填:短信签名-可在短信控制台中找到
        request.setSignName(aLiDaYu.getSignName());
        //必填:短信模板-可在短信控制台中找到
        request.setTemplateCode(templateCode);
        request.setTemplateParam(Json.toJsonString(params));


        //hint 此处可能会抛出异常,注意catch
        SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
        log.debug(Json.toJsonString(sendSmsResponse));
        if (sendSmsResponse.getCode() == null || !SEND_SMS_SUCCESS_FLAG.equals(sendSmsResponse.getCode())) {
            throw new YamiShopBindException("发送短信失败,请稍后再试:" + sendSmsResponse.getMessage());
        }
    }
 
Example 19
Source Project: NutzSite   Source File: SmsUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static SendSmsResponse sendSms(String phoneNumber,String code) 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(phoneNumber);
        //必填:短信签名-可在短信控制台中找到
        request.setSignName("");
        //必填:短信模板-可在短信控制台中找到
        request.setTemplateCode("SMS_151600445");
        //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
        request.setTemplateParam("{\"code\":\"" + code + "\"}");

        //选填-上行短信扩展码(无特殊需求用户请忽略此字段)
        //request.setSmsUpExtendCode("90997");

        //可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
        request.setOutId("yourOutId");

        //hint 此处可能会抛出异常,注意catch
        SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);

        return sendSmsResponse;
    }
 
Example 20
Source Project: zuihou-admin-boot   Source File: SmsAliStrategy.java    License: Apache License 2.0 5 votes vote down vote up
@Override
    protected SmsResult send(SmsDO smsDO) {
        //可自助调整超时时间
        System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
        System.setProperty("sun.net.client.defaultReadTimeout", "10000");

        try {
            //初始化acsClient,暂不支持region化
            IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", smsDO.getAppId(), smsDO.getAppSecret());
//            DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", PRODUCT, DOMAIN);
            DefaultProfile.addEndpoint("cn-hangzhou", PRODUCT, DOMAIN);
            IAcsClient acsClient = new DefaultAcsClient(profile);

            //组装请求对象-具体描述见控制台-文档部分内容
            SendSmsRequest request = new SendSmsRequest();
            //必填:待发送手机号
            request.setPhoneNumbers(smsDO.getPhone());
            //必填:短信签名-可在短信控制台中找到
            request.setSignName(smsDO.getSignName());
            //必填:短信模板-可在短信控制台中找到
            request.setTemplateCode(smsDO.getTemplateCode());
            //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
            request.setTemplateParam(smsDO.getTemplateParams());

            //可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
            request.setOutId(String.valueOf(smsDO.getTaskId()));

            log.info("阿里短信发送参数={}", JSONObject.toJSONString(request));
            //hint 此处可能会抛出异常,注意catch
            SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);

            log.info("阿里短信发送结果={}", JSONObject.toJSONString(sendSmsResponse));
            return SmsResult.build(ProviderType.ALI, sendSmsResponse.getCode(), sendSmsResponse.getBizId(),
                    sendSmsResponse.getRequestId(), sendSmsResponse.getMessage(), 0);
        } catch (ClientException e) {
            log.warn("阿里短信发送失败:" + smsDO.getPhone(), e);
            return SmsResult.fail(e.getMessage());
        }

    }
 
Example 21
Source Project: charging_pile_cloud   Source File: AliSmsUtil.java    License: MIT License 5 votes vote down vote up
/**
 * 发送短信类
 *
 * @return
 * @throws ClientException
 */
public static SendSmsResponse sendSms(AliParam ali) throws ClientException {

    //可自助调整超时时间
    System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
    System.setProperty("sun.net.client.defaultReadTimeout", "10000");

    //初始化acsClient,暂不支持region化
    IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", ali.getAccessKeyId(), ali.getAccessKeySecret());
    DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
    IAcsClient acsClient = new DefaultAcsClient(profile);

    //组装请求对象-具体描述见控制台-文档部分内容
    SendSmsRequest request = new SendSmsRequest();
    //必填:待发送手机号
    request.setPhoneNumbers(ali.getTel());
    //必填:短信签名-可在短信控制台中找到
    request.setSignName(ali.getSignName());
    //必填:短信模板-可在短信控制台中找到
    request.setTemplateCode(ali.getTemplateCode());
    //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
    request.setTemplateParam("{\"" + ali.getTemplateParam() + "\":\"" + ali.getCode() + "\"}");
    //可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
    request.setOutId("yourOutId");

    //hint 此处可能会抛出异常,注意catch
    SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);

    return sendSmsResponse;
}
 
Example 22
Source Project: charging_pile_cloud   Source File: AliSmsUtil.java    License: MIT License 5 votes vote down vote up
/**
 * 查询短信详情类
 *
 * @param bizId
 * @return
 * @throws ClientException
 */
public static QuerySendDetailsResponse querySendDetails(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("13015582371");
    //可选-流水号
    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 23
Source Project: fast-family-master   Source File: AbstractAliSmsTemplate.java    License: Apache License 2.0 5 votes vote down vote up
@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 24
Source Project: codeway_service   Source File: SmsUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 发送短信
 *
 * @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 25
Source Project: codeway_service   Source File: SmsUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 查询发送详情
 * @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 Project: roncoo-education   Source File: AliyunUtil.java    License: MIT License 5 votes vote down vote up
public static boolean sendMsg(String phone, String code, Aliyun aliyun) throws ClientException {
	System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
	System.setProperty("sun.net.client.defaultReadTimeout", "10000");
	// 初始化ascClient需要的几个参数
	// 初始化ascClient,暂时不支持多region(请勿修改)
	IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", aliyun.getAliyunAccessKeyId(), aliyun.getAliyunAccessKeySecret());
	DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Dysmsapi", "dysmsapi.aliyuncs.com");
	IAcsClient acsClient = new DefaultAcsClient(profile);
	// 组装请求对象
	SendSmsRequest request = new SendSmsRequest();
	// 使用post提交
	request.setMethod(MethodType.POST);
	// 必填:待发送手机号。支持以逗号分隔的形式进行批量调用,批量上限为1000个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式
	request.setPhoneNumbers(phone);
	// 必填:短信签名-可在短信控制台中找到
	request.setSignName(aliyun.getSignName());
	// 必填:短信模板-可在短信控制台中找到
	request.setTemplateCode(aliyun.getSmsCode());
	// 可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
	// 友情提示:如果JSON中需要带换行符,请参照标准的JSON协议对换行符的要求,比如短信内容中包含\r\n的情况在JSON中需要表示成\\r\\n,否则会导致JSON在服务端解析失败
	request.setTemplateParam("{\"code\":\"{code}\",\"product\":\"领课开源\"}".replace("{code}", code));
	// 可选-上行短信扩展码(扩展码字段控制在7位或以下,无特殊需求用户请忽略此字段)
	// request.setSmsUpExtendCode("90997");
	// 可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
	// request.setOutId("yourOutId");
	// 请求失败这里会抛ClientException异常
	SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
	if (sendSmsResponse.getCode() != null && sendSmsResponse.getCode().equals("OK")) {
		// 请求成功
		log.debug(sendSmsResponse.getCode());
		return true;
	} else {
		log.error("发送失败,code={},message={}", sendSmsResponse.getCode(), sendSmsResponse.getMessage());
		return false;
	}
}
 
Example 27
Source Project: FlyCms   Source File: SmsapiService.java    License: MIT License 5 votes vote down vote up
public SendSmsResponse sendSms(String PhoneNumber,String code,String accessKeyId,String accessKeySecret,String signName,String templateCode) 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(PhoneNumber);
    //必填:短信签名-可在短信控制台中找到
    request.setSignName(signName);
    //request.setSignName("猎职网");
    //必填:短信模板-可在短信控制台中找到
    request.setTemplateCode(templateCode);
    //request.setTemplateCode("SMS_126565207");
    //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
    request.setTemplateParam("{\"name\":\"Tom\", \"code\":\""+code+"\"}");

    //选填-上行短信扩展码(无特殊需求用户请忽略此字段)
    //request.setSmsUpExtendCode("90997");

    //可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
    request.setOutId("用户名");
    //hint 此处可能会抛出异常,注意catch
    SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
    return sendSmsResponse;
}
 
Example 28
Source Project: FlyCms   Source File: SmsapiService.java    License: MIT License 5 votes vote down vote up
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 29
Source Project: super-cloudops   Source File: AliyunSmsMessageNotifier.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	super.afterPropertiesSet();

	AliyunSmsNotifyProperties aliyun = config.getAliyun();
	// 设置超时时间-可自行调整
	System.setProperty("sun.net.client.defaultConnectTimeout", aliyun.getDefaultConnectTimeout());
	System.setProperty("sun.net.client.defaultReadTimeout", aliyun.getDefaultReadTimeout());

	// 初始化ascClient,暂时不支持多region(请勿修改)
	IClientProfile profile = DefaultProfile.getProfile(aliyun.getRegionId(), aliyun.getAccessKeyId(),
			aliyun.getAccessKeySecret());
	acsClient = new DefaultAcsClient(profile);
}
 
Example 30
Source Project: zuihou-admin-cloud   Source File: SmsAliStrategy.java    License: Apache License 2.0 5 votes vote down vote up
@Override
    protected SmsResult send(SmsDO smsDO) {
        //可自助调整超时时间
        System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
        System.setProperty("sun.net.client.defaultReadTimeout", "10000");

        try {
            //初始化acsClient,暂不支持region化
            IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", smsDO.getAppId(), smsDO.getAppSecret());
//            DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", PRODUCT, DOMAIN);
            DefaultProfile.addEndpoint("cn-hangzhou", PRODUCT, DOMAIN);
            IAcsClient acsClient = new DefaultAcsClient(profile);

            //组装请求对象-具体描述见控制台-文档部分内容
            SendSmsRequest request = new SendSmsRequest();
            //必填:待发送手机号
            request.setPhoneNumbers(smsDO.getPhone());
            //必填:短信签名-可在短信控制台中找到
            request.setSignName(smsDO.getSignName());
            //必填:短信模板-可在短信控制台中找到
            request.setTemplateCode(smsDO.getTemplateCode());
            //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
            request.setTemplateParam(smsDO.getTemplateParams());

            //可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
            request.setOutId(String.valueOf(smsDO.getTaskId()));

            log.info("阿里短信发送参数={}", JSONObject.toJSONString(request));
            //hint 此处可能会抛出异常,注意catch
            SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);

            log.info("阿里短信发送结果={}", JSONObject.toJSONString(sendSmsResponse));
            return SmsResult.build(ProviderType.ALI, sendSmsResponse.getCode(), sendSmsResponse.getBizId(),
                    sendSmsResponse.getRequestId(), sendSmsResponse.getMessage(), 0);
        } catch (ClientException e) {
            log.warn("阿里短信发送失败:" + smsDO.getPhone(), e);
            return SmsResult.fail(e.getMessage());
        }

    }