admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/util/TencentSMSUtil.java
@@ -1,45 +1,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, "短信发送失败");
      }
   }
}
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, "短信发送失败");
      }
   }
}