use of com.aliyun.dysmsapi20170525.Client in project rocketmq-connect by apache.
the class RocketMQSourceConnector method validate.
@Override
public void validate(KeyValue config) {
if (StringUtils.isBlank(config.getString(RocketMQConstant.ACCESS_KEY_ID)) || StringUtils.isBlank(config.getString(RocketMQConstant.ACCESS_KEY_SECRET)) || StringUtils.isBlank(config.getString(RocketMQConstant.NAMESRV_ADDR)) || StringUtils.isBlank(config.getString(RocketMQConstant.TOPIC)) || StringUtils.isBlank(config.getString(RocketMQConstant.CONSUMER_GROUP))) {
throw new RuntimeException("rocketmq required parameter is null !");
}
try {
Config onsConfig = new Config().setAccessKeyId(config.getString(RocketMQConstant.ACCESS_KEY_ID)).setAccessKeySecret(config.getString(RocketMQConstant.ACCESS_KEY_SECRET));
onsConfig.endpoint = OnsUtils.parseEndpoint(config.getString(RocketMQConstant.NAMESRV_ADDR));
final Client client = new Client(onsConfig);
OnsTopicListRequest onsTopicListRequest = new OnsTopicListRequest().setTopic(config.getString(RocketMQConstant.TOPIC)).setInstanceId(config.getString(RocketMQConstant.INSTANCE_ID));
final OnsTopicListResponse onsTopicListResponse = client.onsTopicList(onsTopicListRequest);
if (onsTopicListResponse.getBody().getData().getPublishInfoDo().isEmpty()) {
throw new RuntimeException("rocketmq required parameter topic does not exist !");
}
OnsGroupListRequest onsGroupListRequest = new OnsGroupListRequest().setInstanceId(config.getString(RocketMQConstant.INSTANCE_ID)).setGroupId(config.getString(RocketMQConstant.CONSUMER_GROUP));
final OnsGroupListResponse onsGroupListResponse = client.onsGroupList(onsGroupListRequest);
if (onsGroupListResponse.getBody().getData().getSubscribeInfoDo().isEmpty()) {
throw new RuntimeException("rocketmq required parameter consumerGroup does not exist !");
}
} catch (Exception e) {
log.error("RocketMQSinkTask | validate | error => ", e);
throw new RuntimeException(e.getMessage());
}
}
use of com.aliyun.dysmsapi20170525.Client 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.aliyun.dysmsapi20170525.Client in project ChatSystem by Dofmor.
the class ClientDriver method main.
public static void main(String[] args) throws ClassNotFoundException, IOException {
System.out.println("Enter ip address: ");
Scanner input = new Scanner(System.in);
String ip = input.nextLine();
ip = ip.trim();
// Enter in own IP address when starting client to connect mutlitple clients
Client client = new Client(ip);
client.run();
input.close();
}
use of com.aliyun.dysmsapi20170525.Client in project eladmin by lWoHvYe.
the class DySMSUtil method createClient.
@SneakyThrows
public static Client createClient() {
Config config = new Config();
config.accessKeyId = AliCloudConfig.ACCESS_KEY_ID;
config.accessKeySecret = AliCloudConfig.ACCESS_KEY_SECRET;
return new Client(config);
}
use of com.aliyun.dysmsapi20170525.Client in project eladmin by lWoHvYe.
the class DySMSUtil method sendSms.
/**
* 发送短信
*
* @param phoneNumbers
* @param signName
* @param templateCode
* @param templateParam
* @return java.lang.String
* @date 2021/11/7 12:53 下午
*/
@SneakyThrows
public static String sendSms(String phoneNumbers, String signName, String templateCode, String templateParam) {
Client client = DySMSUtil.createClient();
// 1.发送短信
SendSmsRequest sendReq = new SendSmsRequest().setPhoneNumbers(phoneNumbers).setSignName(signName).setTemplateCode(templateCode).setTemplateParam(templateParam);
SendSmsResponse sendResp = client.sendSms(sendReq);
String code = sendResp.body.code;
if (!StrUtil.equals(code, "OK")) {
log.error("错误信息: {} ", sendResp.body.message);
return null;
}
return sendResp.body.bizId;
}
Aggregations