yujian
2019-09-03 2ddf5b8a1290123e2d1c05bcc851ec35cd217afc
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
package com.yeshi.fanli.util;
 
import java.io.IOException;
 
import org.json.JSONException;
 
import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import com.github.qcloudsms.httpclient.HTTPException;
import com.yeshi.fanli.exception.config.SMSException;
 
//腾讯短信发送
public class TencentSMSUtil {
 
    /**
     * 发送单一短信
     * 
     * @param phone
     * @param msg
     */
    public static void sendSingleMsg(String phone, String msg) throws SMSException {
        SmsSingleSender ssender = new SmsSingleSender(Integer.parseInt(Constant.smsConfig.getSmsAppId()),
                Constant.smsConfig.getSmsAppKey());
        SmsSingleSenderResult result = null;
        try {
            result = ssender.send(0, "86", phone, msg, "", "");
        } catch (JSONException e) {
            e.printStackTrace();
        } catch (HTTPException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
 
        if (result == null)
            throw new SMSException(2, "短信发送失败");
        if (result.result == 1025) {
            throw new SMSException(result.result, "今日验证码发送超限,请明日再试");
        } else if (result.result != 0) {// 发送失败
            throw new SMSException(result.result, "短信发送失败");
        }
 
    }
 
}