|
@@ -0,0 +1,56 @@
|
|
|
+package com.ruoyi.generator.util;
|
|
|
+
|
|
|
+import com.aliyun.auth.credentials.Credential;
|
|
|
+import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
|
|
|
+import com.aliyun.sdk.service.dysmsapi20170525.AsyncClient;
|
|
|
+import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsRequest;
|
|
|
+import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsResponse;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.ruoyi.common.utils.StringUtils;
|
|
|
+import darabonba.core.client.ClientOverrideConfiguration;
|
|
|
+
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
+
|
|
|
+public class SendSms {
|
|
|
+ public static void sendMsg(String signName, String templateCode, String phoneNumbers, String code) throws ExecutionException, InterruptedException {
|
|
|
+ StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
|
|
|
+ // Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
|
|
|
+ .accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
|
|
|
+ .accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
|
|
|
+ //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // use STS token
|
|
|
+ .build());
|
|
|
+
|
|
|
+ // Configure the Client
|
|
|
+ AsyncClient client = AsyncClient.builder()
|
|
|
+ .region("cn-hangzhou-finance") // Region ID
|
|
|
+ //.httpClient(httpClient) // Use the configured HttpClient, otherwise use the default HttpClient (Apache HttpClient)
|
|
|
+ .credentialsProvider(provider)
|
|
|
+ //.serviceConfiguration(Configuration.create()) // Service-level configuration
|
|
|
+ // Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
|
|
|
+ .overrideConfiguration(
|
|
|
+ ClientOverrideConfiguration.create()
|
|
|
+ // Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
|
|
|
+ .setEndpointOverride("dysmsapi.aliyuncs.com")
|
|
|
+ //.setConnectTimeout(Duration.ofSeconds(30))
|
|
|
+ )
|
|
|
+ .build();
|
|
|
+
|
|
|
+ // Parameter settings for API request
|
|
|
+ SendSmsRequest sendSmsRequest = SendSmsRequest.builder()
|
|
|
+ .signName(StringUtils.nvl(signName, "社区功能"))
|
|
|
+ .templateCode(StringUtils.nvl(templateCode, "SMS_474645121"))
|
|
|
+ .phoneNumbers(StringUtils.nvl(phoneNumbers, "13358039598"))
|
|
|
+ .templateParam("{\"code\":\"" + code + "\"}")
|
|
|
+ // Request-level configuration rewrite, can set Http request parameters, etc.
|
|
|
+ // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
|
|
|
+ .build();
|
|
|
+
|
|
|
+ // Asynchronously get the return value of the API request
|
|
|
+ CompletableFuture<SendSmsResponse> response = client.sendSms(sendSmsRequest);
|
|
|
+ // Synchronously get the return value of the API request
|
|
|
+ SendSmsResponse resp = response.get();
|
|
|
+ System.out.println(new Gson().toJson(resp));
|
|
|
+ client.close();
|
|
|
+ }
|
|
|
+}
|