xiaoyong931011
2021-03-26 092750acd191ea00862d862d786bfd491e3fdb32
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
package com.xcong.excoin.modules;
 
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
 
import cn.hutool.crypto.SecureUtil;
import com.xcong.excoin.common.exception.GlobalException;
 
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.XmlUtil;
import cn.hutool.http.HttpUtil;
import lombok.extern.slf4j.Slf4j;
 
@Slf4j
public class Sms106Send {
 
    private static final String URL = "http://zzsms365.com/v2sms.aspx?action=send";
 
    private static final String USER_ID = "1654";
    private static final String ACCOUNT = "1369815429";
    private static final String PWD = "1369815429";
 
 
    /**
     * @param phone 手机号
     * @param code  验证码
     * @param time  失效时间
     * @return
     */
    public static boolean sendVerifyCode(String phone, String code, int time) {
        String content = "【HiBit】您的验证码是{},请在{}分钟内输入,请勿泄露给他人,如非本人操作,请及时修改密码。";
        return send(phone, StrUtil.format(content, code, time));
    }
 
    public static boolean sendRechargeMsg(String telphone, Date time, String amount, String orderNo) {
        String content = "【HiBit】尊敬的用户,恭喜您于{}有一笔充值已成功到账,充值数量为{}, 订单号为{}。";
        return send(telphone, StrUtil.format(content, DateUtil.format(time, DatePattern.NORM_DATETIME_MINUTE_PATTERN), amount));
    }
 
    public static boolean sendWithdrawalCoinMsg(String telphone, Date time, String amount) {
        String content = "【HiBit】尊敬的用户,恭喜您于{}提现成功,数量为{}。";
        return send(telphone, StrUtil.format(content, DateUtil.format(time, DatePattern.NORM_DATETIME_MINUTE_PATTERN), amount));
    }
 
    private static boolean send(String telphone, String content) {
        Map<String, Object> data = new HashMap<>();
        Long time = System.currentTimeMillis();
        data.put("userid", USER_ID);
        data.put("timestamp", time);
        data.put("mobile", telphone);
        String signStr = ACCOUNT + PWD + time;
        String sign = SecureUtil.md5(signStr);
        data.put("sign", sign);
        data.put("content", content);
 
        String response = HttpUtil.post(URL, data);
        log.info("短信发送:{}", response);
        if ("Success".equals(XmlUtil.xmlToMap(response).get("returnstatus"))) {
            return true;
        } else {
//            throw new GlobalException((String) XmlUtil.xmlToMap(response).get("message"));
            return false;
        }
    }
 
    public static void main(String[] args) {
        System.out.println(sendVerifyCode("15773002834", "123456", 2));
    }
}