xiongzhu 3 yıl önce
ebeveyn
işleme
b042c08938

+ 10 - 10
src/main/java/com/izouma/awesomeAdmin/service/sms/AliSmsService.java

@@ -1,5 +1,7 @@
 package com.izouma.awesomeAdmin.service.sms;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.aliyuncs.CommonRequest;
 import com.aliyuncs.CommonResponse;
 import com.aliyuncs.DefaultAcsClient;
@@ -15,8 +17,6 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.RandomStringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.configurationprocessor.json.JSONException;
-import org.springframework.boot.configurationprocessor.json.JSONObject;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
@@ -60,21 +60,21 @@ public class AliSmsService implements SmsService {
                 throw new BusinessException("发送失败,请稍后再试", response.getHttpStatus() + "," + response.getData());
             }
             log.info("send sms response {}", response.getData());
-            JSONObject jsonObject = new JSONObject(response.getData());
+            JSONObject jsonObject = JSON.parseObject(response.getData());
             if (!"ok".equalsIgnoreCase(jsonObject.getString("Code"))) {
                 throw new BusinessException("发送失败,请稍后再试", jsonObject.getString("Message"));
             }
             smsRecordRepo.expire(phone);
             String sessionId = RandomStringUtils.randomAlphabetic(10);
             smsRecordRepo.save(SmsRecord.builder()
-                                        .sessionId(sessionId)
-                                        .phone(phone)
-                                        .code(code)
-                                        .expiresAt(LocalDateTime.now().plusMinutes(5))
-                                        .expired(false)
-                                        .build());
+                    .sessionId(sessionId)
+                    .phone(phone)
+                    .code(code)
+                    .expiresAt(LocalDateTime.now().plusMinutes(5))
+                    .expired(false)
+                    .build());
             return sessionId;
-        } catch (ClientException | JSONException e) {
+        } catch (Exception e) {
             e.printStackTrace();
             throw new BusinessException("发送失败,请稍后再试", e.getMessage());
         }