From aa0ef8625daa107761bcbd34bf901b43be0badbb Mon Sep 17 00:00:00 2001 From: fengyarnom Date: Fri, 21 Feb 2025 10:06:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20SIM=20=E5=8D=A1=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beidou/controller/SimCardController.java | 213 +++++++++++++ .../static/api/init_super_admin.json | 20 ++ .../resources/static/api/init_sys_admin.json | 20 ++ .../resources/templates/page/sim_status.html | 278 +++++++++++++++++ .../templates/page/sim_traffic_query.html | 290 ++++++++++++++++++ 5 files changed, 821 insertions(+) create mode 100644 sec-beidou/src/main/java/com/imdroid/beidou/controller/SimCardController.java create mode 100644 sec-beidou/src/main/resources/templates/page/sim_status.html create mode 100644 sec-beidou/src/main/resources/templates/page/sim_traffic_query.html diff --git a/sec-beidou/src/main/java/com/imdroid/beidou/controller/SimCardController.java b/sec-beidou/src/main/java/com/imdroid/beidou/controller/SimCardController.java new file mode 100644 index 00000000..6ae7b822 --- /dev/null +++ b/sec-beidou/src/main/java/com/imdroid/beidou/controller/SimCardController.java @@ -0,0 +1,213 @@ +package com.imdroid.beidou.controller; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.imdroid.beidou.common.Role; +import com.imdroid.beidou.service.CommonExcelService; +import com.imdroid.secapi.dto.*; +import org.apache.http.HttpEntity; +import org.apache.http.util.EntityUtils; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.math.BigDecimal; +import java.security.MessageDigest; +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; + +@Controller +public class SimCardController extends BasicController { + // TODO:这里的常量应该写入 application.properties + private static final String BASE_URL = "http://120.78.169.220:8089"; + private static final String USERNAME = "gzyzdz"; + private static final String KEY = "632629d1269a202c9d49a574623e4e4c"; + + @Autowired + private SimCardsMapper simCardsMapper; + + @RequestMapping("/page/sim_status") + public String simStatus(Model m, HttpSession session) { + initModel(m, session); + + return "/page/sim_status"; + } + + @RequestMapping("/sim/list") + @ResponseBody + public JSONObject list(HttpSession session, + int page, + int limit, + String searchType, + String searchContent, + Integer status) { + Page pageable = new Page<>(page, limit); + + QueryWrapper queryWrapper = new QueryWrapper<>(); + + + if (!StringUtils.isEmpty(searchContent)) { + switch(searchType) { + case "deviceId": + queryWrapper.like("deviceid", searchContent.trim()); + break; + case "iccid": + queryWrapper.like("iccid", searchContent.trim()); + break; + case "simNumber": + queryWrapper.like("msisdn", searchContent.trim()); + break; + } + } + if (status != null) { + queryWrapper.eq("status", status); + } + + queryWrapper.orderByDesc("updatetime"); + IPage cs = simCardsMapper.selectPage(pageable, queryWrapper); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("code", 0); + jsonObject.put("msg", ""); + jsonObject.put("count", cs.getTotal()); + jsonObject.put("data", cs.getRecords()); + System.out.println(jsonObject.toString()); + return jsonObject; + } + + @RequestMapping("/page/sim_traffic_query") + public String simTrafficQuery(Model m, HttpSession session) { + initModel(m, session); + + return "/page/sim_traffic_query"; + } + + // 代理转发 + @RequestMapping("/api/proxy/sim/query") + @ResponseBody + public JSONObject proxySimQuery( + @RequestParam String type, + @RequestParam String content + ){ + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + try { + Map params = new HashMap<>(); + params.put("username", USERNAME); + params.put("key", KEY); + + switch(type) { + case "iccid": + params.put("card", content); + break; + case "deviceId": + if (content.trim().isEmpty()) { + throw new IllegalArgumentException("设备ID不能为空"); + } + SimCard simCard = simCardsMapper.queryByDeviceId(content.trim()); + if (simCard == null) { + throw new IllegalArgumentException("未找到该设备ID对应的SIM卡信息"); + } + params.put("card", simCard.getIccid()); + break; + case "simNumber": + params.put("card", content); + break; + default: + throw new IllegalArgumentException("无效的查询类型: " + type); + } + + params.put("timestamp", String.valueOf(System.currentTimeMillis() / 1000)); + + String signature = calculateSignature(params); + if (signature == null) { + throw new Exception("签名计算失败"); + } + + StringBuilder urlBuilder = new StringBuilder(BASE_URL); + urlBuilder.append("/api/Service/QueryCard?"); + urlBuilder.append("username=").append(USERNAME); + urlBuilder.append("&key=").append(KEY); + urlBuilder.append("&card=").append(params.get("card")); + urlBuilder.append("×tamp=").append(params.get("timestamp")); + urlBuilder.append("&signature=").append(signature); + + httpClient = HttpClients.createDefault(); + HttpGet httpGet = new HttpGet(urlBuilder.toString()); + + // System.out.println("Sending request: " + urlBuilder.toString()); + response = httpClient.execute(httpGet); + HttpEntity entity = response.getEntity(); + + + String result = EntityUtils.toString(entity); + // System.out.println("Received response: " + result); + + return JSONObject.parseObject(result); + + } catch (Exception e) { + // System.out.println("Query failed: " + e.getMessage()); + JSONObject errorResponse = new JSONObject(); + errorResponse.put("Status", 0); + errorResponse.put("Message", "查询失败: " + e.getMessage()); + return errorResponse; + + } finally { + try { + if (response != null) { + response.close(); + } + if (httpClient != null) { + httpClient.close(); + } + } catch (Exception e) { + + } + } + } + + private String calculateSignature(Map params) { + try { + List paramList = new ArrayList<>(); + for (Map.Entry entry : params.entrySet()) { + paramList.add(entry.getKey() + "=" + entry.getValue()); + } + Collections.sort(paramList); + + String paramString = String.join("&", paramList); + MessageDigest md = MessageDigest.getInstance("MD5"); + byte[] digest = md.digest(paramString.getBytes()); + StringBuilder sb = new StringBuilder(); + for (byte b : digest) { + sb.append(String.format("%02x", b)); + } + String signature = sb.toString(); + // System.out.println("Signature: " + signature); + return signature; + + } catch (Exception e) { + //System.out.println("Signature: " + e.getMessage()); + return null; + } + } + +} + + diff --git a/sec-beidou/src/main/resources/static/api/init_super_admin.json b/sec-beidou/src/main/resources/static/api/init_super_admin.json index d9252f57..b8bf9bcb 100644 --- a/sec-beidou/src/main/resources/static/api/init_super_admin.json +++ b/sec-beidou/src/main/resources/static/api/init_super_admin.json @@ -111,6 +111,26 @@ } ] }, + { + "title": "SIM卡管理", + "href": "", + "icon": "fa fa-signal", + "target": "_self", + "child": [ + { + "title": "总览", + "href": "page/sim_status", + "icon": "fa fa-minus", + "target": "_self" + }, + { + "title": "卡信息查询", + "href": "page/sim_traffic_query", + "icon": "fa fa-minus", + "target": "_self" + } + ] + }, { "title": "数据推送", "href": "", diff --git a/sec-beidou/src/main/resources/static/api/init_sys_admin.json b/sec-beidou/src/main/resources/static/api/init_sys_admin.json index 31fa2579..caba7f78 100644 --- a/sec-beidou/src/main/resources/static/api/init_sys_admin.json +++ b/sec-beidou/src/main/resources/static/api/init_sys_admin.json @@ -93,6 +93,26 @@ } ] }, + { + "title": "SIM卡管理", + "href": "", + "icon": "fa fa-signal", + "target": "_self", + "child": [ + { + "title": "总览", + "href": "page/sim_status", + "icon": "fa fa-minus", + "target": "_self" + }, + { + "title": "卡信息查询", + "href": "page/sim_traffic_query", + "icon": "fa fa-minus", + "target": "_self" + } + ] + }, { "title": "数据推送", "href": "", diff --git a/sec-beidou/src/main/resources/templates/page/sim_status.html b/sec-beidou/src/main/resources/templates/page/sim_status.html new file mode 100644 index 00000000..e220984b --- /dev/null +++ b/sec-beidou/src/main/resources/templates/page/sim_status.html @@ -0,0 +1,278 @@ + + + + + SIM卡信息查询 + + + + + + + +
+
+
+ 搜索信息 +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ +
+
+
+
+
+
+
    +
  • 数据表格
  • +
  • 流量图表
  • +
+
+
+
+
+
+
+
+
+
+
+
+ + + + + + + \ No newline at end of file diff --git a/sec-beidou/src/main/resources/templates/page/sim_traffic_query.html b/sec-beidou/src/main/resources/templates/page/sim_traffic_query.html new file mode 100644 index 00000000..1d96e4f0 --- /dev/null +++ b/sec-beidou/src/main/resources/templates/page/sim_traffic_query.html @@ -0,0 +1,290 @@ + + + + + SIM卡信息查询 + + + + + + + +
+
+
+ SIM卡相关信息聚合查询 +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+
+ +
+
+ + + + \ No newline at end of file