KKSU
2024-11-18 e143e08a77c00047048a5596bed1d674f967649d
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
package cc.mrbird.febs.common.utils;
 
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
 
import java.io.IOException;
 
@Slf4j
public class InfobipSmsSend {
 
    public static boolean sendSms(String phone,String code){
        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("application/json");
        String appId = "0988dc701f3b79a65e5cbf3769f10a59-8a62bea2-1e45-418d-ac93-eba20c0c4ce0";
        String zw = StrUtil.format("您的验证码:{}。",code);
        String yw = StrUtil.format("you code is :{}。",code);
        String sender = "447491163443";
        String to = phone;
 
        RequestBody body = RequestBody.create(mediaType,
                "{\"messages\":[{\"sender\":\""+sender+"\"" +
                        ",\"destinations\":[{\"to\":\""+to+"\"}]" +
                        ",\"content\":{\"text\":\""+zw+yw+"\"}}]}");
        Request request = new Request.Builder()
                .url("https://m3x5pw.api.infobip.com/sms/3/messages")
                .method("POST", body)
                .addHeader("Authorization", "App " + appId)
                .addHeader("Content-Type", "application/json")
                .addHeader("Accept", "application/json")
                .build();
        try {
            client.newCall(request).execute();
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
 
    public static void main(String[] args) {
        sendSms("15274802129","123456");
    }
 
 
}