Skip to content

Commit efec108

Browse files
committed
增加天眼查OPENAPI接口,增加风鸟接口,优化请求函数
1 parent 7e971da commit efec108

File tree

20 files changed

+744
-300
lines changed

20 files changed

+744
-300
lines changed

common/common.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package common
2+
3+
import (
4+
"crypto/tls"
5+
"github.com/imroc/req/v3"
6+
"time"
7+
)
8+
9+
func NewClient(headers map[string]string, op *ENOptions) *req.Request {
10+
c := req.C()
11+
c.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}) // 忽略证书验证
12+
c.SetTLSFingerprintChrome()
13+
c.SetCommonHeaders(headers)
14+
if op.GetENConfig().UserAgent != "" {
15+
c.SetUserAgent(op.GetENConfig().UserAgent)
16+
}
17+
if op.Proxy != "" {
18+
c.SetProxyURL(op.Proxy)
19+
}
20+
c.SetTimeout(time.Duration(op.TimeOut) * time.Minute)
21+
time.Sleep(time.Duration(op.GetDelayRTime()) * time.Second)
22+
return c.R()
23+
}

common/config.go

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package common
22

33
import (
4-
"fmt"
54
"path/filepath"
65
"time"
76

@@ -50,6 +49,8 @@ type ENOptions struct {
5049
OutPutType string // 导出文件类型
5150
IsApiMode bool
5251
IsMCPServer bool
52+
IsPlugins bool // 是否作为后置插件查询
53+
IsFast bool // 是否快速查询
5354
ENConfig *ENConfig
5455
BranchFilter string
5556
}
@@ -70,6 +71,8 @@ type EnsGo struct {
7071
Rf string // 返回数据关键词 TYC
7172
DataModuleId int // 企点获取数据ID点
7273
AppParams [2]string // 插件需要获取的参数
74+
Price float32 // 价格
75+
Ex []string // 扩展字段
7376
}
7477

7578
// ENsD 通用返回内容格式
@@ -91,7 +94,6 @@ func (h *ENOptions) GetDelayRTime() int64 {
9194
}
9295

9396
func (h *ENOptions) GetENConfig() *ENConfig {
94-
fmt.Println(h.KeyWord)
9597
return h.ENConfig
9698
}
9799

@@ -120,13 +122,15 @@ var DefaultAllInfos = []string{"icp", "weibo", "wechat", "app", "weibo", "job",
120122
var DefaultInfos = []string{"icp", "weibo", "wechat", "app", "wx_app"}
121123
var CanSearchAllInfos = []string{"enterprise_info", "icp", "weibo", "wechat", "app", "job", "wx_app", "copyright", "supplier", "invest", "branch", "holds", "partner"}
122124
var DeepSearch = []string{"invest", "branch", "holds", "supplier"}
123-
var ENSTypes = []string{"aqc", "tyc", "kc", "miit"}
125+
var ENSTypes = []string{"aqc", "tyc", "kc", "miit", "tycapi", "rb"}
124126
var ScanTypeKeys = map[string]string{
125127
"aqc": "爱企查",
126128
"qcc": "企查查",
127129
"tyc": "天眼查",
130+
"tycapi": "天眼查",
128131
"xlb": "小蓝本",
129132
"kc": "快查",
133+
"rb": "风鸟",
130134
"all": "全部查询",
131135
"aldzs": "阿拉丁",
132136
"coolapk": "酷安市场",
@@ -137,34 +141,38 @@ var ScanTypeKeys = map[string]string{
137141

138142
// ENConfig YML配置文件,更改时注意变更 cfgYV 版本
139143
type ENConfig struct {
140-
Version float64 `yaml:"version"`
141-
Cookies struct {
142-
Aldzs string `yaml:"aldzs"`
143-
Aiqicha string `yaml:"aiqicha"`
144-
Qidian string `yaml:"qidian"`
145-
KuaiCha string `yaml:"kuaicha"`
146-
Tianyancha string `yaml:"tianyancha"`
147-
Tycid string `yaml:"tycid"`
148-
AuthToken string `yaml:"auth_token"`
149-
QiMai string `yaml:"qimai"`
144+
Version float64 `yaml:"version"`
145+
UserAgent string `yaml:"user_agent"` // 自定义 User-Agent
146+
Cookies struct {
147+
Aldzs string `yaml:"aldzs"`
148+
Aiqicha string `yaml:"aiqicha"`
149+
Qidian string `yaml:"qidian"`
150+
KuaiCha string `yaml:"kuaicha"`
151+
Tianyancha string `yaml:"tianyancha"`
152+
Tycid string `yaml:"tycid"`
153+
TycApiToken string `yaml:"tyc_api_token"`
154+
RiskBird string `yaml:"risk_bird"`
155+
AuthToken string `yaml:"auth_token"`
156+
QiMai string `yaml:"qimai"`
150157
}
151158
App struct {
152159
MiitApi string `yaml:"miit_api"`
153160
}
154161
}
155162

156163
var cfgYName = filepath.Join(utils.GetConfigPath(), "config.yaml")
157-
var cfgYV = 0.5
158-
var configYaml = `version: 0.5
164+
var cfgYV = 0.6
165+
var configYaml = `version: 0.6
166+
user_agent: "" # 自定义 User-Agent(可设置为获取Cookie的浏览器)
159167
app:
160168
miit_api: '' # HG-ha的ICP_Query (非狼组维护,团队成员请使用内部版本)
161169
cookies:
162170
aiqicha: '' # 爱企查 Cookie
163171
tianyancha: '' # 天眼查 Cookie
164172
tycid: '' # 天眼查 CApi ID(capi.tianyancha.com)
173+
tyc_api_token: '' # 天眼查 官方API Token(https://open.tianyancha.com)
165174
auth_token: '' # 天眼查 Token (capi.tianyancha.com)
166-
qcc: '' # 企查查 Cookie
167-
qcctid: '' # 企查查 TID console.log(window.tid)
175+
risk_bird: '' # 风鸟 Cookie
168176
aldzs: '' # 阿拉丁 Cookie
169177
xlb: '' # 小蓝本 Token
170178
qimai: '' # 七麦数据 Cookie

common/flag.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ func Flag(Info *ENOptions) {
4646
flag.StringVar(&Info.OutPutType, "out-type", "xlsx", "导出的文件后缀 默认xlsx")
4747
flag.BoolVar(&Info.IsDebug, "debug", false, "是否显示debug详细信息")
4848
flag.BoolVar(&Info.IsShow, "is-show", true, "是否展示信息输出")
49+
flag.BoolVar(&Info.IsFast, "is-fast", false, "跳过数量校验,直接开启查询")
50+
flag.BoolVar(&Info.IsPlugins, "is-plugin", false, "是否以插件功能运行,默认false")
4951
//其他设定
5052
flag.BoolVar(&Info.IsGroup, "is-group", false, "查询关键词为集团")
5153
flag.BoolVar(&Info.IsApiMode, "api", false, "API模式运行")

common/utils/utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ func TBS(h []string, ep []string, name string, data []gjson.Result) {
215215
table.Render()
216216
}
217217

218+
// MergeMap 合并map
219+
// s: 源map,list: 目标map
218220
func MergeMap(s map[string][]map[string]string, list map[string][]map[string]string) {
219221
for k, v := range s {
220222
if l, ok := list[k]; ok {

interface/enscan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
type ENScan interface {
9-
AdvanceFilter() ([]gjson.Result, error)
9+
AdvanceFilter(name string) ([]gjson.Result, error)
1010
GetENMap() map[string]*common.EnsGo
1111
GetEnsD() common.ENsD
1212
GetCompanyBaseInfoById(pid string) (gjson.Result, map[string]*common.EnsGo)

internal/aiqicha/aiqicha.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ type AQC struct {
1919
}
2020

2121
// AdvanceFilter 筛选过滤
22-
func (h *AQC) AdvanceFilter() ([]gjson.Result, error) {
23-
name := h.Options.KeyWord
22+
func (h *AQC) AdvanceFilter(name string) ([]gjson.Result, error) {
2423
urls := "https://aiqicha.baidu.com/s?q=" + urlTool.QueryEscape(name) + "&t=0"
2524
//urls := "https://aiqicha.baidu.com/s/advanceFilterAjax?q=" + urlTool.QueryEscape(name) + "&p=1&s=10&f={}"
26-
content := GetReq(urls, h.Options)
25+
content := h.req(urls)
2726
content = strings.ReplaceAll(content, "<em>", "⌈")
2827
content = strings.ReplaceAll(content, "<\\/em>", "⌋")
2928
rq, _ := pageParseJson(content)
@@ -55,7 +54,7 @@ func (h *AQC) GetEnsD() common.ENsD {
5554
func (h *AQC) GetCompanyBaseInfoById(pid string) (gjson.Result, map[string]*common.EnsGo) {
5655
// 企业基本信息
5756
urls := "https://aiqicha.baidu.com/detail/basicAllDataAjax?pid=" + pid
58-
baseRes := GetReq(urls, h.Options)
57+
baseRes := h.req(urls)
5958
res := gjson.Get(baseRes, "data.basicData")
6059
// 修复没有pid的问题
6160
r, _ := sjson.Set(res.Raw, "pid", pid)
@@ -64,7 +63,7 @@ func (h *AQC) GetCompanyBaseInfoById(pid string) (gjson.Result, map[string]*comm
6463
ensInfoMap := getENMap()
6564
// 获取企业信息列表
6665
enInfoUrl := "https://aiqicha.baidu.com/compdata/navigationListAjax?pid=" + pid
67-
enInfoRes := GetReq(enInfoUrl, h.Options)
66+
enInfoRes := h.req(enInfoUrl)
6867
// 初始化数量数据
6968
if gjson.Get(enInfoRes, "status").String() == "0" {
7069
for _, s := range gjson.Get(enInfoRes, "data").Array() {
@@ -93,14 +92,14 @@ func (h *AQC) GetCompanyBaseInfoById(pid string) (gjson.Result, map[string]*comm
9392
}
9493

9594
func (h *AQC) GetEnInfoList(pid string, enMap *common.EnsGo) ([]gjson.Result, error) {
96-
listData := getInfoList(pid, enMap.Api, h.Options)
95+
listData := h.getInfoList(pid, enMap.Api, h.Options)
9796
return listData, nil
9897
}
9998

10099
// getInfoList 获取信息列表
101-
func getInfoList(pid string, types string, options *common.ENOptions) []gjson.Result {
100+
func (h *AQC) getInfoList(pid string, types string, options *common.ENOptions) []gjson.Result {
102101
urls := "https://aiqicha.baidu.com/" + types + "?pid=" + pid
103-
content := GetReq(urls, options)
102+
content := h.req(urls)
104103
var listData []gjson.Result
105104
if gjson.Get(content, "status").String() == "0" {
106105
data := gjson.Get(content, "data")
@@ -115,7 +114,7 @@ func getInfoList(pid string, types string, options *common.ENOptions) []gjson.Re
115114
for i := 1; int(pageCount) >= i; i++ {
116115
gologger.Info().Msgf("当前:%s,%d\n", types, i)
117116
reqUrls := urls + "&p=" + strconv.Itoa(i)
118-
content = GetReq(reqUrls, options)
117+
content = h.req(reqUrls)
119118
listData = append(listData, gjson.Get(string(content), "data.list").Array()...)
120119
}
121120
} else {

internal/aiqicha/bean.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package aiqicha
22

33
import (
4-
"crypto/tls"
54
"fmt"
6-
"github.com/imroc/req/v3"
75
"github.com/tidwall/gjson"
86
"github.com/wgpsec/ENScan/common"
97
"github.com/wgpsec/ENScan/common/gologger"
@@ -95,38 +93,26 @@ func getENMap() map[string]*common.EnsGo {
9593

9694
}
9795

98-
func GetReq(url string, options *common.ENOptions) string {
99-
client := req.C()
100-
client.SetTLSFingerprintChrome()
101-
client.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
102-
client.SetTimeout(time.Duration(options.TimeOut) * time.Minute)
103-
if options.Proxy != "" {
104-
client.SetProxyURL(options.Proxy)
105-
}
106-
client.SetCommonHeaders(map[string]string{
96+
func (h *AQC) req(url string) string {
97+
c := common.NewClient(map[string]string{
10798
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36 Edg/98.0.1108.43",
10899
"Accept": "text/html, application/xhtml+xml, image/jxr, */*",
109-
"Cookie": options.ENConfig.Cookies.Aiqicha,
100+
"Cookie": h.Options.ENConfig.Cookies.Aiqicha,
110101
"Referer": "https://aiqicha.baidu.com/",
111-
})
112-
//加入随机延时
113-
time.Sleep(time.Duration(options.GetDelayRTime()) * time.Second)
114-
resp, err := client.R().Get(url)
102+
}, h.Options)
103+
resp, err := c.Get(url)
115104

116105
if err != nil {
117-
if options.Proxy != "" {
118-
client.SetProxy(nil)
119-
}
120106
gologger.Error().Msgf("【AQC】请求发生错误, %s 5秒后重试\n%s\n", url, err)
121107
time.Sleep(5 * time.Second)
122-
return GetReq(url, options)
108+
return h.req(url)
123109
}
124110
if resp.IsSuccessState() {
125111
if strings.Contains(resp.String(), "百度安全验证") {
126112
gologger.Error().Msgf("【AQC】需要安全验证,请打开浏览器进行验证后操作,10秒后重试! %s \n", "https://aiqicha.baidu.com/")
127113
gologger.Debug().Msgf("URL:%s\n\n%s", url, resp.String())
128114
time.Sleep(10 * time.Second)
129-
return GetReq(url, options)
115+
return h.req(url)
130116
}
131117
return resp.String()
132118
} else if resp.StatusCode == 403 {

internal/kuaicha/kuaicha.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ type KC struct {
1414
Options *common.ENOptions
1515
}
1616

17-
func (h *KC) AdvanceFilter() ([]gjson.Result, error) {
18-
name := h.Options.KeyWord
17+
func (h *KC) AdvanceFilter(name string) ([]gjson.Result, error) {
1918
url := "https://www.kuaicha365.com/enterprise_info_app/V1/search/company_search_pc"
2019
searchStr := `{"search_conditions":[],"keyword":"` + name + `","page":1,"page_size":20}"}`
21-
content := GetReq(url, searchStr, h.Options)
20+
content := h.req(url, searchStr)
2221
content = strings.ReplaceAll(content, "<em>", "⌈")
2322
content = strings.ReplaceAll(content, "</em>", "⌋")
2423
enList := gjson.Get(content, "data.list").Array()
@@ -40,7 +39,7 @@ func (h *KC) GetEnsD() common.ENsD {
4039

4140
func (h *KC) GetCompanyBaseInfoById(pid string) (gjson.Result, map[string]*common.EnsGo) {
4241
ensInfoMap := getENMap()
43-
detailRess := GetReq("https://www.kuaicha365.com/open/app/v1/pc_enterprise/basic/info?org_id="+pid, "", h.Options)
42+
detailRess := h.req("https://www.kuaicha365.com/open/app/v1/pc_enterprise/basic/info?org_id="+pid, "")
4443
detailRes := gjson.Get(detailRess, "data")
4544
// 匹配统计数据,需要从页面中提取数据来判断
4645
for k, _ := range ensInfoMap {
@@ -50,17 +49,17 @@ func (h *KC) GetCompanyBaseInfoById(pid string) (gjson.Result, map[string]*commo
5049
}
5150

5251
func (h *KC) GetEnInfoList(pid string, enMap *common.EnsGo) ([]gjson.Result, error) {
53-
return getInfoList(pid+enMap.Fids, enMap.Api, h.Options), nil
52+
return h.getInfoList(pid+enMap.Fids, enMap.Api, h.Options), nil
5453
}
5554

56-
func getInfoList(pid string, types string, options *common.ENOptions) []gjson.Result {
55+
func (h *KC) getInfoList(pid string, types string, options *common.ENOptions) []gjson.Result {
5756
urls := "https://www.kuaicha365.com/" + types
5857
if strings.Contains(types, "open/app/v1") {
5958
urls += "?page_size=10" + "&org_id=" + pid
6059
} else {
6160
urls += "?pageSize=10&&orgid=" + pid
6261
}
63-
content := GetReq(urls+"&page=1", "", options)
62+
content := h.req(urls+"&page=1", "")
6463
var listData []gjson.Result
6564
if gjson.Get(content, "status_code").String() == "0" {
6665
data := gjson.Get(content, "data")
@@ -71,7 +70,7 @@ func getInfoList(pid string, types string, options *common.ENOptions) []gjson.Re
7170
for i := 1; int(math.Ceil(float64(pageCount)/float64(10))) >= i; i++ {
7271
gologger.Info().Msgf("当前:%s,%d\n", types, i)
7372
reqUrls := urls + "&page=" + strconv.Itoa(i)
74-
content = GetReq(reqUrls, "", options)
73+
content = h.req(reqUrls, "")
7574
listData = append(listData, gjson.Get(content, "data.list").Array()...)
7675
}
7776
} else {

internal/kuaicha/utils.go

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package kuaicha
22

33
import (
4-
"crypto/tls"
5-
"github.com/imroc/req/v3"
64
"github.com/wgpsec/ENScan/common"
75
"github.com/wgpsec/ENScan/common/gologger"
86
"time"
@@ -93,43 +91,28 @@ func getENMap() map[string]*common.EnsGo {
9391

9492
}
9593

96-
func GetReq(url string, data string, options *common.ENOptions) string {
97-
client := req.C()
98-
client.SetTLSFingerprintChrome()
99-
client.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
100-
client.SetTimeout(time.Duration(options.TimeOut) * time.Minute)
101-
if options.Proxy != "" {
102-
client.SetProxyURL(options.Proxy)
103-
}
104-
client.SetCommonHeaders(map[string]string{
94+
func (h *KC) req(url string, data string) string {
95+
c := common.NewClient(map[string]string{
10596
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36 Edg/98.0.1108.43",
10697
"Accept": "text/html, application/xhtml+xml, image/jxr, */*",
10798
"Content-Type": "application/json;charset=UTF-8",
108-
"Cookie": options.ENConfig.Cookies.KuaiCha,
99+
"Cookie": h.Options.ENConfig.Cookies.KuaiCha,
109100
"Source": "PC",
110101
"Referer": "https://www.kuaicha365.com/search-result?",
111-
})
112-
//加入随机延时
113-
time.Sleep(time.Duration(options.GetDelayRTime()) * time.Second)
114-
clientR := client.R()
102+
}, h.Options)
115103

116104
method := "GET"
117-
if data == "" {
118-
method = "GET"
119-
} else {
105+
if data != "" {
120106
method = "POST"
121-
clientR.SetBody(data)
107+
c.SetBody(data)
122108
}
123109

124-
resp, err := clientR.Send(method, url)
110+
resp, err := c.Send(method, url)
125111

126112
if err != nil {
127-
if options.Proxy != "" {
128-
client.SetProxy(nil)
129-
}
130113
gologger.Error().Msgf("【KC】请求发生错误, %s 5秒后重试\n%s\n", url, err)
131114
time.Sleep(5 * time.Second)
132-
return GetReq(url, data, options)
115+
return h.req(url, data)
133116
}
134117
if resp.IsSuccessState() {
135118
return resp.String()

0 commit comments

Comments
 (0)