| | |
| | | package com.stylefeng.guns.modular.system.util; |
| | | |
| | | |
| | | import cn.hutool.http.ContentType; |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpResponse; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.twilio.Twilio; |
| | | import com.twilio.rest.api.v2010.account.Message; |
| | | import com.twilio.type.PhoneNumber; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.net.ssl.*; |
| | | import java.io.*; |
| | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | @Component |
| | | public class SMSUtil { |
| | | |
| | | //无需修改,用于格式化鉴权头域,给"X-WSSE"参数赋值 |
| | |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | public boolean sendCellulantMessage(String toPhone, String msg){ |
| | | String url = "https://sms.nalosolutions.com/smsbackend/Resl_Nalo/send-message/"; |
| | | HttpRequest post = HttpUtil.createPost(url); |
| | | post.contentType(ContentType.JSON.toString()); |
| | | JSONObject params = new JSONObject(); |
| | | params.put("username", "I-GO"); |
| | | params.put("password", "9wBolBiXskCuzSf"); |
| | | params.put("msisdn", toPhone); |
| | | params.put("message", msg); |
| | | params.put("sender_id", "I-GO"); |
| | | params.put("callback_url", "https://igo.i-go.group/user/base/sendCellulantMessageCallback"); |
| | | params.put("validity", 1); |
| | | post.body(params.toJSONString()); |
| | | System.err.println("短信请求:\n请求地址:" + url + "\n请求参数:" + params.toJSONString()); |
| | | HttpResponse execute = post.execute(); |
| | | String body = execute.body(); |
| | | execute.close(); |
| | | JSONObject jsonObject = JSON.parseObject(body); |
| | | System.err.println("短信响应:" + body); |
| | | Integer status = jsonObject.getInteger("status"); |
| | | if(null != status && 1701 == status){ |
| | | return true; |
| | | }else{ |
| | | return false; |
| | | } |
| | | } |
| | | } |