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");
|
}
|
|
|
}
|