puzhibing
2024-01-12 aec323b302fdc60429ecf8944e40ebae1a85a7fa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.ruoyi.member.util;
 
import com.alibaba.nacos.shaded.com.google.gson.Gson;
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 darabonba.core.client.ClientOverrideConfiguration;
 
import java.util.concurrent.CompletableFuture;
 
/**
 * @author jqs34
 * @version 1.0
 * @classname MsgUtils
 * @description: TODO
 * @date 2023 2023/8/6 12:48
 */
 
 
 
 
public class MsgUtils {
 
 
    public static void sendMsg(String phoneNumber,Integer sendType,String sendContent) throws Exception {
 
        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                .accessKeyId("LTAI5tAfKFuhyKFH12CTkXFj")
                .accessKeySecret("tIBRuonHuQQPdcYrmlCdXlexOSwVXe")
                .build());
 
        AsyncClient client = AsyncClient.builder()
                .credentialsProvider(provider)
                .overrideConfiguration(
                        ClientOverrideConfiguration.create()
                                // Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
                                .setEndpointOverride("dysmsapi.aliyuncs.com")
                )
                .build();
 
        SendSmsRequest sendSmsRequest = SendSmsRequest.builder()
                .phoneNumbers(phoneNumber)
                .signName("鸿瑞堂")
                .templateCode("SMS_464381169")
                .templateParam(sendContent)
                .build();
 
        CompletableFuture<SendSmsResponse> response = client.sendSms(sendSmsRequest);
        SendSmsResponse resp = response.get();
        System.out.println(new Gson().toJson(resp));
        client.close();
    }
 
}