Pu Zhibing
2025-04-30 46a9e15466ed29133dcf130fb0b529dc8f9d80d3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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");
    }
}