admin
2021-10-13 052e1d5c47c4e536fde79074d53b0481c7d4f9b6
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
package org.yeshi.utils.sms;
 
import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import com.github.qcloudsms.httpclient.HTTPException;
import org.json.JSONException;
 
import java.io.IOException;
 
public class TencentSMSUtil {
    /**
     * 发送单一短信
     *
     * @param phone
     * @param msg
     */
    public static SmsSingleSenderResult sendSingleMsg(int appId, String appKey, String phone, String msg) {
        SmsSingleSender ssender = new SmsSingleSender(appId,
                appKey);
        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();
        }
        return result;
 
//        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, "短信发送失败");
//        }
 
    }
}