xiaoyong931011
2020-10-15 9088bdd31984501044a6e2a663cb858637f7ae5c
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
package com.xcong.excoin.modules;
 
import java.util.Date;
import java.util.HashMap;
 
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://www.qf106.com/sms.aspx";
    private static final String ID = "16615";
    private static final String ACCOUNT = "hibit";
    private static final String PASSWORD = "123456";
 
 
    /**
     * @param phone 手机号
     * @param code  验证码
     * @param time  失效时间
     * @return
     */
    public static boolean sendVerifyCode(String phone, String code, int time) {
        String msg = "您的验证码是{},请在{}分钟内输入,请勿泄露给他人,如非本人操作,请及时修改密码。";
        String content = StrUtil.format(msg, code, time);
        return request(phone, content, "验证码");
    }
 
    public static boolean sendRechargeMsg(String phone, String time, String orderNo) {
        String msg = "尊敬的用户,您的帐号于{}有一笔成功充值订单,如有疑问请联系客服,订单编号为{}";
        String content = StrUtil.format(msg, time, orderNo);
        return request(phone, content, "充值");
    }
 
    public static boolean sendWithdrawalMsg(String phone, String time, String orderNo) {
        String msg = "尊敬的用户,您的帐号于{}有一笔成功提现订单,如有疑问请联系客服,订单编号为{}";
        String content = StrUtil.format(msg, time, orderNo);
        return request(phone, content, "提现");
    }
    public static boolean sendWithdrawalCoinMsg(String phone, String time) {
        String msg = "尊敬的用户,您的帐号于{}有一笔成功提现订单,如有疑问请联系客服。";
        String content = StrUtil.format(msg, time);
        return request(phone, content, "提币");
    }
 
    private static boolean request(String phone, String content, String tagName) {
        HashMap<String, Object> param = new HashMap<>();
        param.put("userid", ID);
        param.put("account", ACCOUNT);
        param.put("password", PASSWORD);
        param.put("mobile", phone);
        param.put("content", content);
        param.put("sendTime", DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN));
        param.put("action", "send");
        param.put("checkcontent", 0);
        param.put("taskName", tagName);
        param.put("countnumber", 1);
        param.put("mobilenumber", 1);
        param.put("telephonenumber", 0);
 
        String response = HttpUtil.post(URL, param);
        log.info("发送短信:{}", response);
        if ("Success".equals(XmlUtil.xmlToMap(response).get("returnstatus"))) {
            return true;
        } else {
            throw new GlobalException((String) XmlUtil.xmlToMap(response).get("message"));
        }
    }
 
    public static void main(String[] args) {
        System.out.println(sendVerifyCode("15773002834", "123456", 2));
    }
}