| | |
| | | package com.stylefeng.guns.modular.system.util; |
| | | |
| | | |
| | | import com.twilio.Twilio; |
| | | import com.twilio.rest.api.v2010.account.Message; |
| | | import com.twilio.type.PhoneNumber; |
| | | |
| | | import javax.net.ssl.*; |
| | | import java.io.*; |
| | | import java.net.URL; |
| | |
| | | sc.init(null, trustAllCerts, null); |
| | | HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 发送Twilio短信 |
| | | * @param toPhone |
| | | * @param msg |
| | | * @return |
| | | */ |
| | | public static boolean sendTwilioMessage(String toPhone, String msg){ |
| | | String ACCOUNT_SID = "AC1fd05e898bd59d17ba72db621afca537"; |
| | | String AUTH_TOKEN = "7cee1a6cb0e2936a9037be577b1ffe57"; |
| | | String formPhone = "+16672740015"; |
| | | try { |
| | | Twilio.init(ACCOUNT_SID, AUTH_TOKEN); |
| | | Message message = Message.creator( |
| | | new PhoneNumber(toPhone), |
| | | new PhoneNumber(formPhone), |
| | | msg |
| | | ).create(); |
| | | System.out.println(message.getSid()); |
| | | Message.Status status = message.getStatus(); |
| | | switch (status.toString()){ |
| | | case "canceled": |
| | | return false; |
| | | case "undelivered": |
| | | return false; |
| | | case "failed": |
| | | return false; |
| | | } |
| | | return true; |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | } |