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中的链接。

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

相关文章
|
2天前
|
监控 安全 数据挖掘
Email 接口API有哪些?具体分析一下阿里云和AOK的优点
本文介绍了常见的Email接口API,如阿里云邮件推送、AOKSend、SendGrid、Mailgun和Amazon SES。阿里云API以其高稳定性和数据分析功能脱颖而出,支持批量发送和多语言;而AOKSend API以易于集成、高安全性和优秀客户支持为亮点。企业在选择时应考虑自身需求和预算,以优化邮件营销效果。
|
2天前
|
监控 安全 搜索推荐
Email发送API的方法?AOKSend和阿里云哪个效果更好?
Email发送API在企业与客户沟通中扮演关键角色,允许自动化和个性化邮件发送。本文比较了AOKSend和阿里云的API:AOKSend以其高送达率、快速发送和详细分析报告脱颖而出,适合中小企业;阿里云则凭借稳定性、大规模发送能力和综合云服务吸引大企业。选择合适API能优化邮件营销效果。
|
4天前
|
人工智能 API
阿里云微服务引擎及 API 网关 2024 年 4 月产品动态
阿里云微服务引擎及 API 网关 2024 年 4 月产品动态。
|
4天前
|
运维 Cloud Native 应用服务中间件
阿里云微服务引擎 MSE 及 API 网关 2024 年 04 月产品动态
阿里云微服务引擎 MSE 面向业界主流开源微服务项目, 提供注册配置中心和分布式协调(原生支持 Nacos/ZooKeeper/Eureka )、云原生网关(原生支持Higress/Nginx/Envoy,遵循Ingress标准)、微服务治理(原生支持 Spring Cloud/Dubbo/Sentinel,遵循 OpenSergo 服务治理规范)能力。API 网关 (API Gateway),提供 APl 托管服务,覆盖设计、开发、测试、发布、售卖、运维监测、安全管控、下线等 API 生命周期阶段。帮助您快速构建以 API 为核心的系统架构.满足新技术引入、系统集成、业务中台等诸多场景需要。
|
4天前
|
存储 数据可视化 数据建模
阿里云大佬叮嘱我务必要科普这个 Elasticsearch API
阿里云大佬叮嘱我务必要科普这个 Elasticsearch API
15 0
|
4天前
|
JSON 文字识别 算法
C# 通过阿里云 API 实现企业营业执照OCR识别
C# 通过阿里云 API 实现企业营业执照OCR识别
|
4天前
|
开发框架 前端开发 .NET
C#编程与Web开发
【4月更文挑战第21天】本文探讨了C#在Web开发中的应用,包括使用ASP.NET框架、MVC模式、Web API和Entity Framework。C#作为.NET框架的主要语言,结合这些工具,能创建动态、高效的Web应用。实际案例涉及企业级应用、电子商务和社交媒体平台。尽管面临竞争和挑战,但C#在Web开发领域的前景将持续拓展。
|
4天前
|
SQL 开发框架 安全
C#编程与多线程处理
【4月更文挑战第21天】探索C#多线程处理,提升程序性能与响应性。了解C#中的Thread、Task类及Async/Await关键字,掌握线程同步与安全,实践并发计算、网络服务及UI优化。跟随未来发展趋势,利用C#打造高效应用。
|
4天前
|
存储 安全 网络安全
C#编程的安全性与加密技术
【4月更文挑战第21天】C#在.NET框架支持下,以其面向对象和高级特性成为安全软件开发的利器。本文探讨C#在安全加密领域的应用,包括使用System.Security.Cryptography库实现加密算法,利用SSL/TLS保障网络传输安全,进行身份验证,并强调编写安全代码的重要性。实际案例涵盖在线支付、企业应用和文件加密,展示了C#在应对安全挑战的同时,不断拓展其在该领域的潜力和未来前景。
|
4天前
|
人工智能 C# 开发者
C#编程中的图形界面设计
【4月更文挑战第21天】本文探讨了C#在GUI设计中的应用,介绍了Windows Forms、WPF和UWP等常用框架,强调了简洁界面、响应式设计和数据绑定等最佳实践。通过实际案例,展示了C#在企业应用、游戏开发和移动应用中的GUI实现。随着技术发展,C#在GUI设计的未来将趋向于跨平台、更丰富的组件和AI集成,为开发者创造更多可能性。