Search in sources :

Example 6 with SendSmsRequest

use of com.aliyun.dysmsapi20170525.models.SendSmsRequest in project MaxKey by dromara.

the class SmsOtpAuthnTencentCloud method produce.

@Override
public boolean produce(UserInfo userInfo) {
    // 手机号
    String mobile = userInfo.getMobile();
    if (mobile != null && !mobile.equals("")) {
        try {
            Credential cred = new Credential(secretId, secretKey);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("sms.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            SmsClient client = new SmsClient(cred, "ap-beijing", clientProfile);
            String token = this.genToken(userInfo);
            String params = "{\"PhoneNumberSet\":[\"" + mobile + "\"]," + "\"TemplateID\":\"" + templateId + "\",\"Sign\":\"" + sign + "\"," + "\"TemplateParamSet\":[\"" + token + "\",\"" + this.interval + "\"]," + "\"SmsSdkAppid\":\"" + smsSdkAppid + "\"}";
            SendSmsRequest req = SendSmsRequest.fromJsonString(params, SendSmsRequest.class);
            SendSmsResponse resp = client.SendSms(req);
            logger.debug("responseString " + SendSmsRequest.toJsonString(resp));
            if (resp.getSendStatusSet()[0].getCode().equalsIgnoreCase("Ok")) {
                this.optTokenStore.store(userInfo, token, userInfo.getMobile(), OtpTypes.SMS);
                return true;
            }
        } catch (Exception e) {
            logger.error(" produce code error ", e);
        }
    }
    return false;
}
Also used : SmsClient(com.tencentcloudapi.sms.v20190711.SmsClient) Credential(com.tencentcloudapi.common.Credential) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) SendSmsRequest(com.tencentcloudapi.sms.v20190711.models.SendSmsRequest) SendSmsResponse(com.tencentcloudapi.sms.v20190711.models.SendSmsResponse)

Example 7 with SendSmsRequest

use of com.aliyun.dysmsapi20170525.models.SendSmsRequest in project knife-starter by 1120023921.

the class KnifeSmsAliServiceImpl method sendSms.

@Override
public AliSmsResult sendSms(AliSms aliSms) {
    try {
        final Client client = knifeSmsAliSenderContext.getClient();
        final SendSmsRequest sendSmsRequest = new SendSmsRequest();
        BeanUtils.copyProperties(aliSms, sendSmsRequest);
        final SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
        return AliSmsResult.builder().msgId(aliSms.getMsgId()).code(sendSmsResponse.getBody().getCode()).errMsg(sendSmsResponse.getBody().getMessage()).build();
    } catch (Exception e) {
        return AliSmsResult.builder().msgId(aliSms.getMsgId()).code("-1").errMsg(e.getMessage()).build();
    }
}
Also used : SendSmsRequest(com.aliyun.dysmsapi20170525.models.SendSmsRequest) Client(com.aliyun.dysmsapi20170525.Client) SendSmsResponse(com.aliyun.dysmsapi20170525.models.SendSmsResponse)

Example 8 with SendSmsRequest

use of com.aliyun.dysmsapi20170525.models.SendSmsRequest in project rhythm by csfwff.

the class VerifycodeMgmtService method sendMsg.

public boolean sendMsg(String[] phoneNumber, String[] templateParam) {
    if (Latkes.getRuntimeMode().equals(Latkes.RuntimeMode.DEVELOPMENT)) {
        LOGGER.log(Level.INFO, "开发模式不真正发送短信,发送的手机号为:{},当前短信验证码为:{}", phoneNumber, templateParam);
        return true;
    } else {
        Credential cred = new Credential(Symphonys.TEN_SMS_SECRET_ID, Symphonys.TEN_SMS_SECRET_KEY);
        SmsClient client = new SmsClient(cred, Symphonys.TEN_SMS_DIYU);
        SendSmsRequest req = new SendSmsRequest();
        req.setSmsSdkAppId(Symphonys.TEN_SMS_SDK_APPID);
        req.setSignName(Symphonys.TEN_SMS_SIGN_NAME);
        req.setTemplateId(Symphonys.TEN_SMS_TEMPLATE_ID);
        req.setPhoneNumberSet(phoneNumber);
        req.setTemplateParamSet(templateParam);
        SendSmsResponse res = null;
        try {
            res = client.SendSms(req);
        } catch (TencentCloudSDKException e) {
            LOGGER.log(Level.ERROR, "Unable send SMS [phoneNumber={}, templateParam={}]", phoneNumber, templateParam);
            return false;
        }
        assert res != null;
        LOGGER.log(Level.INFO, SendSmsResponse.toJsonString(res));
        return true;
    }
}
Also used : SmsClient(com.tencentcloudapi.sms.v20210111.SmsClient) Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) SendSmsRequest(com.tencentcloudapi.sms.v20210111.models.SendSmsRequest) SendSmsResponse(com.tencentcloudapi.sms.v20210111.models.SendSmsResponse)

Example 9 with SendSmsRequest

use of com.aliyun.dysmsapi20170525.models.SendSmsRequest in project austin by ZhongFuCheng3y.

the class TencentSmsScript method assembleReq.

/**
 * 组装发送短信参数
 */
private SendSmsRequest assembleReq(SmsParam smsParam, TencentSmsParam account) {
    SendSmsRequest req = new SendSmsRequest();
    String[] phoneNumberSet1 = smsParam.getPhones().toArray(new String[smsParam.getPhones().size() - 1]);
    req.setPhoneNumberSet(phoneNumberSet1);
    req.setSmsSdkAppId(account.getSmsSdkAppId());
    req.setSignName(account.getSignName());
    req.setTemplateId(account.getTemplateId());
    String[] templateParamSet1 = { smsParam.getContent() };
    req.setTemplateParamSet(templateParamSet1);
    req.setSessionContext(IdUtil.fastSimpleUUID());
    return req;
}
Also used : SendSmsRequest(com.tencentcloudapi.sms.v20210111.models.SendSmsRequest)

Example 10 with SendSmsRequest

use of com.aliyun.dysmsapi20170525.models.SendSmsRequest in project austin by ZhongFuCheng3y.

the class TencentSmsScript method send.

@Override
public List<SmsRecord> send(SmsParam smsParam) throws Exception {
    TencentSmsParam tencentSmsParam = accountUtils.getAccount(smsParam.getSendAccount(), SMS_ACCOUNT_KEY, PREFIX, TencentSmsParam.builder().build());
    SmsClient client = init(tencentSmsParam);
    SendSmsRequest request = assembleReq(smsParam, tencentSmsParam);
    SendSmsResponse response = client.SendSms(request);
    return assembleSmsRecord(smsParam, response, tencentSmsParam);
}
Also used : SmsClient(com.tencentcloudapi.sms.v20210111.SmsClient) SendSmsRequest(com.tencentcloudapi.sms.v20210111.models.SendSmsRequest) TencentSmsParam(com.java3y.austin.handler.domain.TencentSmsParam) SendSmsResponse(com.tencentcloudapi.sms.v20210111.models.SendSmsResponse)

Aggregations

SendSmsRequest (com.aliyun.dysmsapi20170525.models.SendSmsRequest)5 SendSmsResponse (com.aliyun.dysmsapi20170525.models.SendSmsResponse)4 Credential (com.tencentcloudapi.common.Credential)4 ClientProfile (com.tencentcloudapi.common.profile.ClientProfile)4 HttpProfile (com.tencentcloudapi.common.profile.HttpProfile)4 SendSmsRequest (com.tencentcloudapi.sms.v20210111.models.SendSmsRequest)4 Client (com.aliyun.dysmsapi20170525.Client)3 TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)3 SmsClient (com.tencentcloudapi.sms.v20190711.SmsClient)3 SendSmsRequest (com.tencentcloudapi.sms.v20190711.models.SendSmsRequest)3 SendSmsResponse (com.tencentcloudapi.sms.v20190711.models.SendSmsResponse)3 SmsClient (com.tencentcloudapi.sms.v20210111.SmsClient)3 SendSmsResponseBody (com.aliyun.dysmsapi20170525.models.SendSmsResponseBody)2 SendSmsResponse (com.tencentcloudapi.sms.v20210111.models.SendSmsResponse)2 SneakyThrows (lombok.SneakyThrows)2 CollUtil (cn.hutool.core.collection.CollUtil)1 ArrayUtil (cn.hutool.core.util.ArrayUtil)1 Config (com.aliyun.teaopenapi.models.Config)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TencentSmsParam (com.java3y.austin.handler.domain.TencentSmsParam)1