lihao16 hace 10 meses
padre
commit
9a9b9b3f90

+ 1 - 13
inspur-admin/src/main/java/com/inspur/web/controller/work/ElevatorInfoController.java

@@ -120,18 +120,6 @@ public class ElevatorInfoController extends BaseController
     @GetMapping("/phone")
     @Anonymous
     public AjaxResult getRegionInfoByPhoneAPI(String phoneNum){
-        // 360提供的一个接口 能返回省份和城市
-        try {
-            String url = "https://cx.shouji.360.cn/phonearea.php?number=" + phoneNum;
-            String responseBody = HttpUtil.createGet(url).execute().body();
-            JSONObject jsonObject = JSONObject.parseObject(responseBody);
-            if (!"0".equals(jsonObject.getInteger("code").toString())) {
-                AjaxResult.success();
-            }
-            String city = jsonObject.getJSONObject("data").getString("city");
-            return AjaxResult.success(city);
-        }catch (Exception e){
-            return AjaxResult.error(e.getMessage());
-        }
+        return elevatorInfoService.getRegionInfoByPhoneAPI(phoneNum);
     }
 }

+ 4 - 0
inspur-admin/src/main/resources/application.yml

@@ -142,4 +142,8 @@ pbx:
   # 分机测试dev  正式环境用prod
   # active: dev
   active: prod
+  # 手机归属地API地址
+  api:
+    url: http://10.10.11.240:15851/phoneApi/mobile?mobile=
+    appcode: APPCODE 35aa2f6993d84cfab3aa822097468ca1
 

+ 8 - 0
inspur-work/src/main/java/com/inspur/service/IElevatorInfoService.java

@@ -1,5 +1,6 @@
 package com.inspur.service;
 
+import com.inspur.common.core.domain.AjaxResult;
 import com.inspur.domain.ElevatorInfo;
 
 import java.util.List;
@@ -59,4 +60,11 @@ public interface IElevatorInfoService
      * @return 结果
      */
     public int deleteElevatorInfoById(Long id);
+
+    /**
+     * 获取手机号归属地
+     * @param phoneNum
+     * @return
+     */
+    public AjaxResult getRegionInfoByPhoneAPI(String phoneNum);
 }

+ 32 - 0
inspur-work/src/main/java/com/inspur/service/impl/ElevatorInfoServiceImpl.java

@@ -4,13 +4,18 @@ import java.util.List;
 import java.util.UUID;
 import java.util.stream.Collectors;
 
+import cn.hutool.http.HttpUtil;
+import com.alibaba.fastjson2.JSONObject;
+import com.inspur.common.core.domain.AjaxResult;
 import com.inspur.common.utils.DateUtils;
 import com.inspur.domain.ElevatorInfo;
 import com.inspur.domain.ElevatorPersonInfo;
 import com.inspur.mapper.ElevatorInfoMapper;
 import com.inspur.mapper.ElevatorPersonInfoMapper;
 import com.inspur.service.IElevatorInfoService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
@@ -21,6 +26,7 @@ import org.springframework.util.CollectionUtils;
  * @date 2024-10-12
  */
 @Service
+@Slf4j
 public class ElevatorInfoServiceImpl implements IElevatorInfoService
 {
     @Autowired
@@ -29,6 +35,12 @@ public class ElevatorInfoServiceImpl implements IElevatorInfoService
     @Autowired
     private ElevatorPersonInfoMapper elevatorPersonInfoMapper;
 
+    @Value("${pbx.api.url}")
+    private String regionPhoneAPIUrl;
+
+    @Value("${pbx.api.appcode}")
+    private String regionPhoneAppCode;
+
     /**
      * 查询电梯信息
      *
@@ -153,4 +165,24 @@ public class ElevatorInfoServiceImpl implements IElevatorInfoService
     {
         return elevatorInfoMapper.deleteElevatorInfoById(id);
     }
+
+    @Override
+    public AjaxResult getRegionInfoByPhoneAPI(String phoneNum) {
+        // 360提供的一个接口 能返回省份和城市
+        try {
+            String url = regionPhoneAPIUrl + phoneNum;
+            log.info("getRegionInfoByPhoneAPI url : {}",url);
+            String responseBody = HttpUtil.createGet(url).header("Authorization",regionPhoneAppCode)
+                    .execute().body();
+            log.info("getRegionInfoByPhoneAPI response body {}", responseBody);
+            JSONObject jsonObject = JSONObject.parseObject(responseBody);
+            if (!"200".equals(jsonObject.getInteger("ret").toString())) {
+                return AjaxResult.error();
+            }
+            String city = jsonObject.getJSONObject("data").getString("city");
+            return AjaxResult.success(city);
+        }catch (Exception e){
+            return AjaxResult.error(e.getMessage());
+        }
+    }
 }

+ 19 - 13
inspur-work/src/main/java/com/inspur/thrid/impl/PBXServiceImpl.java

@@ -70,6 +70,12 @@ public class PBXServiceImpl implements IPBXService {
     @Value("${pbx.active}")
     private String pbxActive;
 
+    @Value("${pbx.api.url}")
+    private String regionPhoneAPIUrl;
+
+    @Value("${pbx.api.appcode}")
+    private String regionPhoneAppCode;
+
     @Autowired
     private ISysConfigService configService;
 
@@ -78,6 +84,8 @@ public class PBXServiceImpl implements IPBXService {
 
     private static final String SUCCESS = "0";
 
+    private static final String API_SUCCESS = "200";
+
     @Autowired
     private ElevatorWorkOrderMapper elevatorWorkOrderMapper;
 
@@ -854,6 +862,10 @@ public class PBXServiceImpl implements IPBXService {
             if (StringUtils.isEmpty(toPhone) || toPhone.length() == 4) {
                 continue;
             }
+            // 如果手机号开头是0 去除掉0
+            if (toPhone.startsWith("0")) {
+                toPhone = toPhone.substring(1,12);
+            }
             String callId = redisCache.getCacheObject(PBXConstant.PBX_TRANSFER_CODE_KEY + toPhone);
             if (StringUtils.isEmpty(callId)) {
                 log.info("no cache transferToValue,key : {}",PBXConstant.PBX_TRANSFER_CODE_KEY + toPhone);
@@ -869,8 +881,6 @@ public class PBXServiceImpl implements IPBXService {
                 startRecordVoice(channelId);
             }
         }
-
-
     }
 
     private void startRecordVoice(String channelId) {
@@ -1081,13 +1091,16 @@ public class PBXServiceImpl implements IPBXService {
      * @param phoneNum 手机号
      * @return 归属地
      */
-    public static String getRegionInfoByPhoneAPI(String phoneNum){
+    public String getRegionInfoByPhoneAPI(String phoneNum){
         // 360提供的一个接口 能返回省份和城市
         try {
-            String url = "https://cx.shouji.360.cn/phonearea.php?number=" + phoneNum;
-            String responseBody = HttpUtil.createGet(url).execute().body();
+            String url = regionPhoneAPIUrl + phoneNum;
+            log.info("getRegionInfoByPhoneAPI url : {}",url);
+            String responseBody = HttpUtil.createGet(url).header("Authorization",regionPhoneAppCode)
+                    .execute().body();
+            log.info("getRegionInfoByPhoneAPI response body {}", responseBody);
             JSONObject jsonObject = JSONObject.parseObject(responseBody);
-            if (!SUCCESS.equals(jsonObject.getInteger("code").toString())) {
+            if (!API_SUCCESS.equals(jsonObject.getInteger("ret").toString())) {
                 return "";
             }
             String city = jsonObject.getJSONObject("data").getString("city");
@@ -1130,11 +1143,4 @@ public class PBXServiceImpl implements IPBXService {
         phoneNumber.setNationalNumber(Long.parseLong(phone));
         return phoneNumber;
     }
-
-    public static void main(String[] args) {
-
-        String phoneNum = "19909918878";
-        System.out.println(getRegionInfoByPhoneAPI(phoneNum));
-
-    }
 }