New file |
| | |
| | | package com.stylefeng.guns.modular.system.util; |
| | | |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpResponse; |
| | | import cn.hutool.http.HttpUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @Date 2025/4/30 12:10 |
| | | */ |
| | | @Slf4j |
| | | public class SMSUtil { |
| | | //企业编号 |
| | | private static final String SpCode = "277952"; |
| | | //用户名 |
| | | private static final String LoginName = "xn95128"; |
| | | //接口秘钥 |
| | | private static final String Password = "fadfe94036a41b873150e3e6726236f1"; |
| | | |
| | | |
| | | /** |
| | | * 发送短信 |
| | | * @param UserNumber |
| | | * @param MessageContent |
| | | * @param templateId |
| | | */ |
| | | public static void send(String UserNumber, String MessageContent, String templateId){ |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | String url = "https://api.ums86.com:9600/sms/Api/Send.do"; |
| | | HttpRequest post = HttpUtil.createPost(url); |
| | | post.header("accept", "application/x-www-form-urlencoded"); |
| | | post.charset("GBK"); |
| | | post.form("SpCode", SpCode); |
| | | post.form("LoginName", LoginName); |
| | | post.form("Password", Password); |
| | | post.form("MessageContent", MessageContent); |
| | | post.form("UserNumber", UserNumber); |
| | | post.form("templateId", templateId); |
| | | post.form("SerialNumber", sdf.format(new Date())); |
| | | post.form("f", "1"); |
| | | HttpResponse execute = post.execute(); |
| | | int status = execute.getStatus(); |
| | | if(status != 200){ |
| | | log.error("短信发送失败:{}", execute.body()); |
| | | return; |
| | | } |
| | | String body = execute.body(); |
| | | String[] split = body.split("&"); |
| | | Map<String, String> map = new HashMap<>(); |
| | | for (String s : split) { |
| | | String[] split1 = s.split("="); |
| | | String k = split1[0]; |
| | | String v = null; |
| | | if(split1.length == 2){ |
| | | v = s.split("=")[1]; |
| | | } |
| | | map.put(k, v); |
| | | } |
| | | String result = map.get("result"); |
| | | if(!"0".equals(result)){ |
| | | log.error("短信发送失败:{}", map.get("description")); |
| | | } |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | send("15828353127", "您的验证码:1255,您正在进行身份验证,请勿泄露于他人!", "2431012312847"); |
| | | } |
| | | } |