use of com.aliyun.ons20190214.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.ons20190214.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.ons20190214.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.ons20190214.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;
}
use of com.aliyun.ons20190214.Client in project stream-services by Backbase.
the class DbsWebClientConfiguration method dbsWebClient.
/**
* Default Reactive Web Client to be used when interacting with DBS Services. Requires OAuth2 client credentials set
* in application.yml
*
* @param objectMapper The Jackson Object mapper to register serialization and deserialization json
* content.
* @param reactiveOAuth2AuthorizedClientManager Client Manager managing OAuth2 tokens
* @param builder THe Web Client Builder which is already preconfigured using MicroMeter
* instrumentation.
* @return Preconfigured Web Client
*/
@Bean
public WebClient dbsWebClient(ObjectMapper objectMapper, ReactiveOAuth2AuthorizedClientManager reactiveOAuth2AuthorizedClientManager, WebClient.Builder builder, DbsWebClientConfigurationProperties dbsWebClientConfigurationProperties) {
ServerOAuth2AuthorizedClientExchangeFilterFunction oauth2ClientFilter = new ServerOAuth2AuthorizedClientExchangeFilterFunction(reactiveOAuth2AuthorizedClientManager);
oauth2ClientFilter.setDefaultClientRegistrationId(dbsWebClientConfigurationProperties.getDefaultClientRegistrationId());
builder.defaultHeader("Content-Type", MediaType.APPLICATION_JSON.toString()).defaultHeader("Accept", MediaType.APPLICATION_JSON.toString()).filter((clientRequest, exchangeFunction) -> {
final ClientRequest newRequest = Optional.ofNullable(dbsWebClientConfigurationProperties.getAdditionalHeaders()).map(additionalHeaders -> {
log.debug("Adding additional headers: {} from configuration Request: {}", additionalHeaders, clientRequest.url());
return ClientRequest.from(clientRequest).headers(httpHeaders -> httpHeaders.addAll(additionalHeaders)).build();
}).orElse(clientRequest);
return Mono.subscriberContext().flatMap(context -> {
Optional<MultiValueMap<String, String>> forwardHeaders = context.<MultiValueMap<String, String>>getOrEmpty(CONTEXT_KEY_FORWARDED_HEADERS);
log.debug("context contains headers? " + forwardHeaders.isPresent());
log.debug("forward headers:" + forwardHeaders.map(MultiValueMap::toString).orElse("null"));
ClientRequest contextRequest = context.<MultiValueMap<String, String>>getOrEmpty("headers").map(headers -> {
log.debug("Adding additional headers: {} from Reactive subscriber context to Request: {}", headers, clientRequest.url());
return ClientRequest.from(newRequest).headers(httpHeaders -> httpHeaders.addAll(headers)).build();
}).orElse(newRequest);
return exchangeFunction.exchange(contextRequest);
});
}).filter(new CsrfClientExchangeFilterFunction()).filter(oauth2ClientFilter);
if (log.isDebugEnabled()) {
HttpClient httpClient = HttpClient.create().wiretap("reactor.netty.http.client.HttpClient", LogLevel.DEBUG, AdvancedByteBufFormat.TEXTUAL);
builder.clientConnector(new ReactorClientHttpConnector(httpClient));
}
// ensure correct exchange strategy is installed
ExchangeStrategies strategies = ExchangeStrategies.builder().codecs(clientDefaultCodecsConfigurer -> {
Jackson2JsonEncoder encoder = new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON);
Jackson2JsonDecoder decoder = new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON);
clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonEncoder(encoder);
clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonDecoder(decoder);
}).build();
builder.exchangeStrategies(strategies);
return builder.build();
}
Aggregations