首页 身份证号码归属地查询 身份证号码归属地查询示例代码 身份证查询[C#]

身份证查询示例代码C#

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

身份证查询

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

class Idcard
{
    private const string AppKey = "YOUR_APPKEY_HERE";   
   
    public static async Task QueryAsync(string idcard)
    {
        try
        {
            using var client = new HttpClient();
            string url = "https://api.jisuapi.com/idcard/query";
            string requestUrl = $"{url}?appkey={AppKey}&idcard={idcard}";

            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["province"]} {result["city"]} {result["town"]} {result["sex"]} {result["birth"]} {result["lastflag"]}");
        }
        catch (HttpRequestException ex)
        {
            Console.WriteLine($"请求出错: {ex.Message}");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"发生错误: {ex.Message}");
        }
    }  
	
    static async Task Main(string[] args)
    {
        await Idcard.QueryAsync("41272519800102067x");
        await Idcard.City2codeAsync("鹿邑");  
    }
}