新版仿ok交易所-后端
1
zyy
2025-12-18 2462671fc9f457a50eb584d852e6273aec2a5a37
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package com.yami.trading.common.manager.sms;
 
import lombok.extern.slf4j.Slf4j;
 
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
 
@Slf4j
public class SmsManager {
    /**
     * 发送的短信接口类型 tiantian---天天---smsSendService--->>>>--
     * moduyun---摩杜云---smsSingleSender
     */
    public void send(String sendCodeType, String user, String password, boolean inter,
                     String mobile, String content) {
        if ("tiantian".equals(sendCodeType)) {
            String dest = "";
            String ip = "";
            if (inter) {
                ip = "210.51.190.232";
                int port = 8085;
                HttpClientUtil util = new HttpClientUtil(ip, port, "/mt/MT3.ashx");
                String ServiceID = "SEND";
                // 目的号码
                dest = mobile;
                // 原号码
                String sender = "";
                // 短信内容
                String msg = content;
                // UTF-16BE
                String hex = WebNetEncode.encodeHexStr(0, msg);
                hex = hex.trim() + "&codec=0";
//                util.sendPostMessage(user, pwd, ServiceID, dest, sender, hex);
                log.info("tiantian--" + mobile + ",短信内容:" + content + "--验证码发送返回信息 = "
                        + util.sendPostMessage(user, password, ServiceID, dest, sender, hex));
//                    System.out.println("验证码发送返回信息 = " + util.sendPostMessage( user,  pwd,  ServiceID,  dest,  sender,  hex));
            } else {
                ip = "210.51.190.233";
                int port = 8085;
                HttpClientUtil util = new HttpClientUtil(ip, port, "/mt/MT3.ashx");
                String ServiceID = "SEND";
                // 目的号码
                dest = mobile;
                // 原号码
                String sender = "";
                // 短信内容
                String msg = content;
                // UTF-16BE
                String hex = WebNetEncode.encodeHexStr(8, msg);
                hex = hex.trim() + "&codec=8";
//                util.sendPostMessage(user, pwd, ServiceID, dest, sender, hex);
                log.info("tiantian--" + mobile + ",短信内容:" + content + "--验证码发送返回信息 = "
                        + util.sendPostMessage(user, password, ServiceID, dest, sender, hex));
            }
        } else if ("smsbao".equals(sendCodeType)) {
            String httpUrl = null;
            if (inter) {
                // 国际
                httpUrl = "http://api.smsbao.com/wsms";
                // 国际
//                httpUrl = "http://iauhnbqszxl.site";
            } else {
                httpUrl = "http://api.smsbao.com/sms";
//                httpUrl = "http://xahsdfg.site";
            }
            StringBuffer httpArg = new StringBuffer();
            httpArg.append("u=").append(user).append("&");
            httpArg.append("p=").append(md5(password)).append("&");
            if (inter) {
                // 国际
                httpArg.append("m=").append(encodeUrlString("+", "UTF-8") + mobile).append("&");
            } else {
                httpArg.append("m=").append(mobile.substring(2, mobile.length()))
                        .append("&");
            }
            httpArg.append("c=").append(encodeUrlString(content, "UTF-8"));
            String result = request(httpUrl, httpArg.toString());
            if (!"0".equals(result)) {
                log.info("Smsbao--" + mobile + ",短信内容:" + content + "--验证码发送失败 ");
            } else {
                log.info("Smsbao--" + mobile + ",短信内容:" + content + "--验证码发送成功 ");
            }
        }
    }
 
    public static String request(String httpUrl, String httpArg) {
        BufferedReader reader = null;
        String result = null;
        StringBuffer sbf = new StringBuffer();
        httpUrl = httpUrl + "?" + httpArg;
        try {
            URL url = new URL(httpUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.connect();
            InputStream is = connection.getInputStream();
            reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            String strRead = reader.readLine();
            if (strRead != null) {
                sbf.append(strRead);
                while ((strRead = reader.readLine()) != null) {
                    sbf.append("\n");
                    sbf.append(strRead);
                }
            }
            reader.close();
            result = sbf.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
 
    public static String md5(String plainText) {
        StringBuffer buf = null;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(plainText.getBytes());
            byte b[] = md.digest();
            int i;
            buf = new StringBuffer("");
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return buf.toString();
    }
 
    public static String encodeUrlString(String str, String charset) {
        String strret = null;
        if (str == null)
            return str;
        try {
            strret = java.net.URLEncoder.encode(str, charset);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return strret;
    }
}