首页 基站查询 基站查询示例代码 基站查询[C#]

基站查询示例代码C#

作者: 阅读数:1123 上传时间:2025-04-23

基站查询

using System;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

class Cell
{
    private const string AppKey = "YOUR_APPKEY_HERE";   
   
    public static async Task QueryAsync(string mncode,string lac,string cellid,string sid,string nid)
    {
        try
        {
            using var client = new HttpClient();
            string url = "https://api.jisuapi.com/cell/query";
            string requestUrl = $"{url}?appkey={AppKey}&mncode={mncode}&lac={lac}&cellid={cellid}&sid={sid}&nid={nid}";

            HttpResponseMessage response = await client.GetAsync(requestUrl);
            response.EnsureSuccessStatusCode();

            string responseBody = await response.Content.ReadAsStringAsync();
            JObject jsonarr = JObject.Parse(responseBody);

            if ((int)jsonarr["status"] != 0)
            {
                Console.WriteLine(jsonarr["msg"]);
                return;
            }

            JObject result = (JObject)jsonarr["result"];
            Console.WriteLine($"{result["lat"]} {result["lng"]} {result["addr"]} {result["accuracy"]}");
           
        }
        catch (HttpRequestException ex)
        {
            Console.WriteLine($"请求出错: {ex.Message}");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"发生错误: {ex.Message}");
        }
    }
   
    static async Task Main(string[] args)
    {
        await Cell.QueryAsync("46000", "1", "1", "1", "1");
        
    }
}