Pu Zhibing
2024-12-17 203abdf7b779e6f8f226e147fa40516b77143f14
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
package com.stylefeng.guns.modular.system.util;
 
import cn.hutool.crypto.SecureUtil;
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;
 
/**
 * @author zhibing.pu
 * @Date 2024/12/17 9:25
 */
public class SmsUtil {
    
    
    /**
     * 发送短信
     * https://doc.zthysms.com/web/#/1/14
     * @param mobile
     * @param content
     */
    public static void sendZTHYSms(String mobile, String content){
        HttpRequest post = HttpUtil.createPost("https://api-shss.zthysms.com/v2/sendSms");
        post.contentType("application/json");
        JSONObject body = new JSONObject();
        Long tKey = System.currentTimeMillis() / 1000;
        body.put("username", "GZAHKJhy");
        body.put("password", SecureUtil.md5(SecureUtil.md5("@zLa@cB0") + tKey));
        body.put("tKey", tKey);
        body.put("mobile", mobile);
        body.put("content", "【安合出行】" + content);
        post.body(body.toJSONString());
        HttpResponse execute = post.execute();
        JSONObject result = JSON.parseObject(execute.body());
        if(200 != result.getInteger("code")){
            throw new RuntimeException(result.getString("msg"));
        }
    }
}