From b997fbe016ace57406e8938ebba3f8c176fbabf9 Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期五, 04 八月 2023 10:34:30 +0800 Subject: [PATCH] 新增加国外短信 --- UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/SMSUtil.java | 63 ++++++++++++++++++++++++++++++- 1 files changed, 60 insertions(+), 3 deletions(-) diff --git a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/SMSUtil.java b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/SMSUtil.java index 34df1e4..a57141c 100644 --- a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/SMSUtil.java +++ b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/SMSUtil.java @@ -1,6 +1,10 @@ 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; @@ -228,10 +232,63 @@ } - public static void main(String[] args) { + /** + * 发送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 { - SMSUtil.send_huawei_sms("b793ae3d41a049059197bfe92cf8bc83", "+233500666666", "[\"1234\"]"); - } catch (Exception e) { + 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; + } + } + + + + + public static void main(String[] args) { +// try { +// SMSUtil.send_huawei_sms("b793ae3d41a049059197bfe92cf8bc83", "+233500666666", "[\"1234\"]"); +// } catch (Exception e) { +// e.printStackTrace(); +// } + + // Find your Account SID and Auth Token at twilio.com/console + // and set the environment variables. See http://twil.io/secure + String ACCOUNT_SID = "AC1fd05e898bd59d17ba72db621afca537"; + String AUTH_TOKEN = "7cee1a6cb0e2936a9037be577b1ffe57"; + try { + Twilio.init(ACCOUNT_SID, AUTH_TOKEN); + Message message = Message.creator( + new PhoneNumber("+233500666666"), + new PhoneNumber("+16672740015"), + "This is the ship that made the Kessel Run in fourteen parsecs?" + ).create(); + System.out.println(message.getSid()); + }catch (Exception e){ e.printStackTrace(); } } -- Gitblit v1.7.1