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, "短信发送失败"); // } } }