package com.everyday.word.utils; import com.everyday.word.exception.SMSException; import com.github.qcloudsms.SmsSingleSender; import com.github.qcloudsms.SmsSingleSenderResult; import com.github.qcloudsms.httpclient.HTTPException; import org.json.JSONException; import java.io.IOException; /** * @author hxh * @description 腾讯云短信发送工具 * @date 15:22 2025/2/11 * @return **/ public class TencentSMSUtil { /** * @return void * @author hxh * @description 发送单条短信 * @date 15:23 2025/2/11 * @param: phone * @param: msg * @param: smsAppId * @param: smsAppKey **/ public static void sendSingleMsg(String phone, String msg, String smsAppId, String smsAppKey) throws SMSException { SmsSingleSender ssender = new SmsSingleSender(Integer.parseInt(smsAppId), smsAppKey); 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, "短信发送失败"); } } }