tsurumure 5 сар өмнө
parent
commit
143c5edc5c

+ 15 - 6
src/main/java/com/backendsys/modules/sms/service/impl/SmsServiceImpl.java

@@ -1,6 +1,8 @@
 package com.backendsys.modules.sms.service.impl;
 
+import cn.hutool.core.convert.Convert;
 import cn.hutool.core.util.RandomUtil;
+import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.backendsys.exception.CustException;
 import com.backendsys.modules.common.config.redis.utils.RedisUtil;
@@ -60,13 +62,20 @@ public class SmsServiceImpl implements com.backendsys.modules.sms.service.SmsSer
         String[] phoneNumberSet = {"+" + phoneAreaCode + phone};
         SendSmsResponse sendSmsResponse = tencentSmsService.send(TEMPLATE_ID_COMMON, templateParamSet, phoneNumberSet);
         if (sendSmsResponse != null) {
-            SendStatus[] sendStatuses = sendSmsResponse.getSendStatusSet();
-            if (sendStatuses.length > 0) {
+            SendStatus[] response = sendSmsResponse.getSendStatusSet();
+            if (response.length > 0) {
                 // for (int i = 0; i < sendStatuses.length; ++i) {
-                if (!sendStatuses[0].getCode().equals("Ok")) {
-                    String sendStatusStr = JSONUtil.toJsonStr(sendStatuses[0]);
-                    log.error(sendStatusStr);
-                    throw new CustException("发送失败", ResultEnum.REMOTE_EXCEPTION.getCode(), sendStatuses[1]);
+                if (response[0] != null && !response[0].getCode().equals("Ok")) {
+                    // String sendStatusStr = JSONUtil.toJsonStr(sendStatuses[0]);
+                    if (response.length > 1) {
+                        throw new CustException("发送失败", ResultEnum.REMOTE_EXCEPTION.getCode(), response[1]);
+                    } else {
+                        JSONObject sendStatusesObj = JSONUtil.parseObj(response[0]);
+                        System.out.println("sendStatusesObj = " + sendStatusesObj);
+                        String message = Convert.toStr(sendStatusesObj.get("Message"));
+                        System.out.println("message = " + message);
+                        throw new CustException(message, ResultEnum.REMOTE_EXCEPTION.getCode(), message);
+                    }
                 }
             }
         }