use of com.tencentcloudapi.sms.v20190711.models.SendSmsResponse in project ballcat by ballcat-projects.
the class TencentSenderImpl method send.
@Override
public SmsSenderResult send(SmsSenderParams sp) {
try {
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint(tencent.getEndpoint());
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
SmsClient client = new SmsClient(cred, tencent.getRegion(), clientProfile);
Map<String, Object> json = new HashMap<>(5);
json.put("PhoneNumberSet", sp.getPhoneNumbers());
json.put("SmsSdkAppid", tencent.getSdkId());
if (tencent.getTemplateId() != null) {
json.put("TemplateID", tencent.getTemplateId());
}
if (StrUtil.isNotEmpty(tencent.getSign())) {
json.put("Sign", tencent.getSign());
}
if (!sp.getTemplateParam().isEmpty()) {
json.put("TemplateParamSet", sp.getTemplateParam());
}
SendSmsRequest req = SendSmsRequest.fromJsonString(om.writeValueAsString(json), SendSmsRequest.class);
SendSmsResponse resp = client.SendSms(req);
return SmsSenderResult.generate(SendSmsRequest.toJsonString(resp), sp.toString(), sp.getPhoneNumbers());
} catch (TencentCloudSDKException | JsonProcessingException e) {
return errRet(TypeEnum.TENCENT, sp.getPhoneNumbers(), "腾讯云平台发送短信出现异常!", e);
}
}
use of com.tencentcloudapi.sms.v20190711.models.SendSmsResponse in project cloud-sdk by mizhousoft.
the class AliyunSendSmsClient method send.
/**
* {@inheritDoc}
*/
@Override
public void send(String phoneNumber, Map<String, String> paramMap, CloudSmsTemplate smsTemplate) throws CloudSDKException {
if (null == smsTemplate) {
throw new CloudSDKException("Sms template is null.");
}
String signName = smsTemplate.getSignName();
String templateId = smsTemplate.getTemplateId().toString();
SendSmsRequest request = new SendSmsRequest();
request.setPhoneNumbers(phoneNumber);
request.setSignName(signName);
request.setTemplateCode(templateId);
try {
if (null != paramMap) {
String templateParam = JSONUtils.toJSONString(paramMap);
request.setTemplateParam(templateParam);
}
SendSmsResponse result = this.client.sendSms(request);
SendSmsResponseBody body = result.getBody();
if (null == body || !"ok".equalsIgnoreCase(body.getCode())) {
throw new CloudSDKException("Send sms failed, code is " + body.code + ", message is " + body.getMessage() + ", request id is " + body.getRequestId() + ", bizId is " + body.getBizId() + '.');
}
} catch (Exception e) {
throw new CloudSDKException("Send sms failed.", e);
}
}
use of com.tencentcloudapi.sms.v20190711.models.SendSmsResponse 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;
}
use of com.tencentcloudapi.sms.v20190711.models.SendSmsResponse 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();
}
}
use of com.tencentcloudapi.sms.v20190711.models.SendSmsResponse 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;
}
}
Aggregations