C# 通过阿里云 API 实现企业工商数据查询

简介: C# 通过阿里云 API 实现企业工商数据查询

应用场景

在企业会员后台注册系统中,为验证企业名称是否输入完整且是有效存在的,则可以通过云API服务的方式进行验证及提取相关的基本信息,自动化提取的企业工商其它信息如法人、企业性质、经营地址等也可以提高录入效率和准确率。

本文将以阿里云提供的 API 服务,实现通过企业名称查询工商数据的功能。

关于阿里云企业工商数据查询API

官方介绍其每天更新全国企业、个体工商户的数据。

更多信息内容请参照:https://market.aliyun.com/products/57000002/cmapi029998.html?spm=5176.21213303.J_qCOwPWspKEuWcmp8qiZNQ.32.3ec42f3dzQ6CjW&scm=20140722.S_market@@%E6%95%B0%E6%8D%AE%E4%B8%8EAPI@@cmapi029998._.ID_market@@%E6%95%B0%E6%8D%AE%E4%B8%8EAPI@@cmapi029998-RL_%E4%BC%81%E4%B8%9A%E5%B7%A5%E5%95%86%E6%95%B0%E6%8D%AEapi%E6%8E%A5%E5%8F%A3-LOC_llm-OR_ser-V_3-RE_new2-P0_0#sku=yuncode2399800001开发前请准备如下操作:

1. 注册阿里云账号。

2. 获取开发者 AppCode,后继开发会用到。

开发运行环境

操作系统: Windows Server 2019 DataCenter

.net版本: .netFramework4.0 或以上

开发工具:VS2019  C#

类设计

类 Company (企业类) 设计见下表:

类属性

序号 属性名 类型 说明
1 ErrorMessage string 发生任何异常返回的错误信息
2 ResultJson string 请求返回结果Json完整数据
3 creditCode string 社会统一信用代码
4 faRen string 法人
5 address string 注册地址
6 bussinessDes string 经营范围
7 regType string 公司类型
8 regMoney string 注册资金
9 bussiness string 营业期限

类方法

queryName 和 queryName2 方法均可以查询(调用地址和方式不同,参数一致),调用均返回对应的类属性数据,参数见如下表格:

序号 参数名 类型 说明
1 CompanyName string 传递完整的企业名称

本方法返回 string 类型的对应属性值(如果成功的话)。

实现代码

创建 Company 类

public class Company
{
            public string ResultJson="";
            public string ErrorMessage = "";
            public string creditCode = "";
            public string faRen = "";
            public string address = "";
            public string bussinessDes = "";
            public string regType = "";
            public string regMoney = "";
            public string bussiness = "";
 
            public void queryName(string CompanyName)
            {
                
                String host = "http://qianzhan1.market.alicloudapi.com";
                String path = "/CommerceAccurate";
                String method = "GET";
                String appcode = "您的AppCode";
                String querys = "comName=" + System.Web.HttpUtility.UrlEncode(CompanyName);
                String bodys = "";
                String url = host + path;
                HttpWebRequest httpRequest = null;
                HttpWebResponse httpResponse = null;
 
                if (0 < querys.Length)
                {
                    url = url + "?" + querys;
                }
 
                if (host.Contains("https://"))
                {
                    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                    httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
                }
                else
                {
                    httpRequest = (HttpWebRequest)WebRequest.Create(url);
                }
                httpRequest.Method = method;
                httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
                if (0 < bodys.Length)
                {
                    byte[] data = Encoding.UTF8.GetBytes(bodys);
                    using (Stream stream = httpRequest.GetRequestStream())
                    {
                        stream.Write(data, 0, data.Length);
                    }
                }
                try
                {
                    httpResponse = (HttpWebResponse)httpRequest.GetResponse();
                }
                catch (WebException ex)
                {
                    ErrorMessage = ex.Message;
                    httpResponse = (HttpWebResponse)ex.Response;
                    return;
                }
                Stream st = httpResponse.GetResponseStream();
                StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
                ResultJson=(reader.ReadToEnd());
 
                if (ResultJson.IndexOf("查询成功") == -1)
                {
                    return;
                }
                Newtonsoft.Json.Linq.JObject jsonObj = Newtonsoft.Json.Linq.JObject.Parse(ResultJson);
                creditCode = jsonObj["result"]["creditCode"].ToString();
                faRen = jsonObj["result"]["faRen"].ToString();
                address = jsonObj["result"]["address"].ToString();
                bussinessDes = jsonObj["result"]["bussinessDes"].ToString();
                regType = jsonObj["result"]["regType"].ToString();
                regMoney = jsonObj["result"]["regMoney"].ToString();
                bussiness = jsonObj["result"]["bussiness"].ToString();
 
 
            }
            public void queryName2(string CompanyName)
            {
                //Zm1qSqdjl2296ixnA6ODXpglwQKYxkSD
                String host = "https://cardnotwo.market.alicloudapi.com";
                String path = "/company";
                String method = "POST";
                String appcode = ""您的AppCode";";
                String querys = "com=" + System.Web.HttpUtility.UrlEncode(CompanyName);
                String bodys = "";
                String url = host + path;
                HttpWebRequest httpRequest = null;
                HttpWebResponse httpResponse = null;
 
                if (0 < querys.Length)
                {
                    url = url + "?" + querys;
                }
 
                if (host.Contains("https://"))
                {
                    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                    httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
                }
                else
                {
                    httpRequest = (HttpWebRequest)WebRequest.Create(url);
                }
                httpRequest.Method = method;
                httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
                if (0 < bodys.Length)
                {
                    byte[] data = Encoding.UTF8.GetBytes(bodys);
                    using (Stream stream = httpRequest.GetRequestStream())
                    {
                        stream.Write(data, 0, data.Length);
                    }
                }
                try
                {
                    httpResponse = (HttpWebResponse)httpRequest.GetResponse();
                }
                catch (WebException ex)
                {
                    ErrorMessage = ex.Message;
                    httpResponse = (HttpWebResponse)ex.Response;
                    return;
                }
                Stream st = httpResponse.GetResponseStream();
                StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
                ResultJson = (reader.ReadToEnd());
 
                if (ResultJson.IndexOf("查询成功") == -1)
                {
                    return;
                }
                Newtonsoft.Json.Linq.JObject jsonObj = Newtonsoft.Json.Linq.JObject.Parse(ResultJson);
                creditCode = jsonObj["result"]["creditCode"].ToString();
                faRen = jsonObj["result"]["faRen"].ToString();
                address = jsonObj["result"]["address"].ToString();
                bussinessDes = jsonObj["result"]["bussinessDes"].ToString();
                regType = jsonObj["result"]["regType"].ToString();
                regMoney = jsonObj["result"]["regMoney"].ToString();
                bussiness = jsonObj["result"]["bussiness"].ToString();
 
 
            }
}

调用举例

调用判断是否返回社会统一信用代码,示例代码如下:

Company cp = new Company();
cp.queryName2("天津XXXX数码有限公司");
if (cp.creditCode != "")
{
    Response.Write("社会统一信用代码:" + cp.creditCode + "<br>");
    Response.Write("法人:" + cp.faRen + "<br>");
    Response.Write("注册地址:" + cp.address + "<br>");
    Response.Write("营业范围:" + cp.bussinessDes + "<br>");
    Response.Write("企业性质:" + cp.regType + "<br>");
    Response.Write("注册资金:" + cp.regMoney + "<br>");
    Response.Write("营业期限:" + cp.bussiness + "<br>");
}
else
{
    Response.Write("错误信息:" + cp.ErrorMessage + "<br>");
    Response.Write("JSON返回信息:" + cp.ResultJson + "<br>");
}

小结

调用云接口服务需要费用,我们需要根据实际应用进行成本考虑,官方说明如果查询失败则不扣除费用,具体内容可参考本文第二小节关于阿里云企业工商数据查询API中的链接。

感谢您的阅读,希望本文能够对您有所帮助。

相关文章
|
API 微服务
阿里云微服务引擎 MSE 及 API 网关 2025 年 9 月产品动态
阿里云微服务引擎 MSE 及 API 网关 2025 年 9 月产品动态。
1302 79
|
运维 Cloud Native 应用服务中间件
阿里云微服务引擎 MSE 及 API 网关 2025 年 9 月产品动态
阿里云微服务引擎 MSE 面向业界主流开源微服务项目, 提供注册配置中心和分布式协调(原生支持 Nacos/ZooKeeper/Eureka )、云原生网关(原生支持Higress/Nginx/Envoy,遵循Ingress标准)、微服务治理(原生支持 Spring Cloud/Dubbo/Sentinel,遵循 OpenSergo 服务治理规范)能力。API 网关 (API Gateway),提供 APl 托管服务,覆盖设计、开发、测试、发布、售卖、运维监测、安全管控、下线等 API 生命周期阶段。帮助您快速构建以 API 为核心的系统架构.满足新技术引入、系统集成、业务中台等诸多场景需要。
895 142
|
人工智能 自然语言处理 安全
探索 API 的无限可能:阿里云的卓越引领
API是数字化时代的“万能钥匙”,阿里云凭借云控制API、API网关、OpenAPI Explorer等产品,构建全方位API生态,助力企业高效集成、安全管控与创新升级,推动电商、制造等行业智能化转型,引领未来科技浪潮。
584 10
|
供应链 安全 API
唯品会:利用银行转账API实现企业采购对公支付的技术实践
企业采购支付面临合规、效率与对账难题。唯品会通过银行API实现银企直连,构建安全高效对公支付系统,支持ISO 20022标准与多重风控,支付耗时从72小时降至90秒,错误率下降98%,推动供应链数字化升级。(236字)
|
人工智能 运维 监控
阿里云 API 聚合实战:破解接口碎片化难题,3 类场景方案让业务响应提速 60%
API聚合破解接口碎片化困局,助力开发者降本增效。通过统一中间层整合微服务、第三方接口与AI模型,实现调用次数减少60%、响应提速70%。阿里云实测:APISIX+函数计算+ARMS监控组合,支撑百万级并发,故障定位效率提升90%。
1040 0
|
人工智能 API 监控
告别多接口拼凑!阿里云 API 模型聚合实现技术能力协同跃迁
API聚合整合400+国内外AI模型,统一接口、屏蔽差异,降低开发与维护成本,提升效率与系统稳定性,助力开发者高效应对多API调用困境。
1435 0
|
XML 前端开发 C#
C#编程实践:解析HTML文档并执行元素匹配
通过上述步骤,可以在C#中有效地解析HTML文档并执行元素匹配。HtmlAgilityPack提供了一个强大而灵活的工具集,可以处理各种HTML解析任务。
614 19
|
C# 开发者
C# 一分钟浅谈:Code Contracts 与契约编程
【10月更文挑战第26天】本文介绍了 C# 中的 Code Contracts,这是一个强大的工具,用于通过契约编程增强代码的健壮性和可维护性。文章从基本概念入手,详细讲解了前置条件、后置条件和对象不变量的使用方法,并通过具体代码示例进行了说明。同时,文章还探讨了常见的问题和易错点,如忘记启用静态检查、过度依赖契约和性能影响,并提供了相应的解决建议。希望读者能通过本文更好地理解和应用 Code Contracts。
575 3
|
监控 算法 C#
C#与Halcon联合编程实现鼠标控制图像缩放、拖动及ROI绘制
C#与Halcon联合编程实现鼠标控制图像缩放、拖动及ROI绘制
2786 0
|
存储 安全 编译器
学懂C#编程:属性(Property)的概念定义及使用详解
通过深入理解和使用C#的属性,可以编写更清晰、简洁和高效的代码,为开发高质量的应用程序奠定基础。
1715 12