Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
孙龙
/
kaopu-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d85da14b
authored
Jun 30, 2022
by
Joneq
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
提交代码
parent
bbc578db
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
54 deletions
cmd/main.go
go.mod
internal/logic/tianyancha.go
cmd/main.go
View file @
d85da14b
This diff is collapsed.
Click to expand it.
go.mod
View file @
d85da14b
...
...
@@ -11,6 +11,7 @@ require (
github.com/ichunt2019/go-msgserver v1.0.5
github.com/pkg/errors v0.8.1
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271
github.com/tidwall/gjson v1.14.1
google.golang.org/genproto v0.0.0-20200402124713-8ff61da6d932
google.golang.org/grpc v1.28.1
)
internal/logic/tianyancha.go
View file @
d85da14b
package
logic
import
(
"bytes"
"encoding/gob"
"encoding/json"
"io/ioutil"
"log"
...
...
@@ -8,16 +10,18 @@ import (
"strconv"
"strings"
"time"
"github.com/tidwall/gjson"
)
type
TianYanChaCompanyInfo
struct
{
EstiblishTime
float64
`json:"estiblishTime"`
CompanyOrgType
string
`json:"companyOrgType"`
SocialStaffNum
float64
`json:"socialStaffNum"`
RegCapital
string
`json:"regCapital"`
LegalPersonName
string
`json:"legalPersonName"`
RegLocation
string
`json:"regLocation"`
OrgNumber
string
`json:"orgNumber"`
EstiblishTime
float64
`json:"estiblishTime"`
CompanyOrgType
string
`json:"companyOrgType"`
SocialStaffNum
float64
`json:"socialStaffNum"`
RegCapital
string
`json:"regCapital"`
LegalPersonName
string
`json:"legalPersonName"`
RegLocation
string
`json:"regLocation"`
OrgNumber
string
`json:"orgNumber"`
}
type
ResultStruct
struct
{
...
...
@@ -29,7 +33,7 @@ type TotalResultStruct struct {
}
type
TotalNumResultStruct
struct
{
Total
int64
`json:"total"`
Total
int64
`json:"total"`
Items
[]
map
[
string
]
string
`json:"items"`
}
...
...
@@ -38,24 +42,28 @@ type ChangeInfo struct {
ChangeItem
int64
`json:"changeItem"`
}
const
TIANYANCHATOKEN
=
"4920e638-52c6-43c5-bdec-78affa06bdbe"
const
TIANYANCHATOKEN
=
"4920e638-52c6-43c5-bdec-78affa06bdbe"
//公司信息
const
COMPANYINFOURL
=
"http://open.api.tianyancha.com/services/open/ic/baseinfoV2/2.0"
const
COMPANYINFOURL
=
"http://open.api.tianyancha.com/services/open/ic/baseinfoV2/2.0"
//法律诉讼
const
LAWSUIT
=
"http://open.api.tianyancha.com/services/open/jr/lawSuit/2.0"
const
LAWSUIT
=
"http://open.api.tianyancha.com/services/open/jr/lawSuit/2.0"
//法人变更次数
const
CHANGEINFO
=
"http://open.api.tianyancha.com/services/open/ic/changeinfo/2.0"
const
CHANGEINFO
=
"http://open.api.tianyancha.com/services/open/ic/changeinfo/2.0"
//一体化请求 http://192.168.1.252:8200/companyInfo
const
YITIHUAREQUEST
=
"http://inner_api.ichunt.net/companyInfo"
func
HttpGet
(
companyName
string
)
(
returnDatas
map
[
string
]
string
)
{
func
HttpGet
(
companyName
string
)
(
returnDatas
map
[
string
]
string
)
{
var
totalNum
TotalResultStruct
var
companyTycInfo
ResultStruct
respBody
:=
BasicHttpGet
(
COMPANYINFOURL
,
companyName
)
json
.
Unmarshal
(
respBody
,
&
companyTycInfo
)
respBody
:=
postRequest
(
companyName
,
"base_info"
)
json
.
Unmarshal
(
respBody
,
&
companyTycInfo
)
returnData
:=
make
(
map
[
string
]
string
)
...
...
@@ -75,7 +83,7 @@ func HttpGet(companyName string)(returnDatas map[string]string) {
}
//成立时间
returnData
[
"establishment_time"
]
=
strconv
.
FormatFloat
((
companyTycInfo
.
Result
.
EstiblishTime
/
1000
),
'f'
,
-
1
,
64
)
returnData
[
"establishment_time"
]
=
strconv
.
FormatFloat
((
companyTycInfo
.
Result
.
EstiblishTime
/
1000
),
'f'
,
-
1
,
64
)
returnData
[
"legal_representative"
]
=
companyTycInfo
.
Result
.
LegalPersonName
returnData
[
"com_address"
]
=
companyTycInfo
.
Result
.
RegLocation
returnData
[
"com_organization"
]
=
companyTycInfo
.
Result
.
OrgNumber
...
...
@@ -93,77 +101,114 @@ func HttpGet(companyName string)(returnDatas map[string]string) {
//}
returnData
[
"customer_property"
]
=
"其它"
//参保人数
returnData
[
"social_security_participants"
]
=
strconv
.
FormatFloat
(
companyTycInfo
.
Result
.
SocialStaffNum
,
'f'
,
-
1
,
64
)
returnData
[
"social_security_participants"
]
=
strconv
.
FormatFloat
(
companyTycInfo
.
Result
.
SocialStaffNum
,
'f'
,
-
1
,
64
)
//注册资本
var
capitalNum
float64
if
strings
.
Contains
(
companyTycInfo
.
Result
.
RegCapital
,
"万"
)
{
capitalNum
=
StringTurnFloat64
(
companyTycInfo
.
Result
.
RegCapital
[
:
StringIndex
(
companyTycInfo
.
Result
.
RegCapital
,
"万"
)])
*
10000
}
else
if
strings
.
Contains
(
companyTycInfo
.
Result
.
RegCapital
,
"亿"
)
{
capitalNum
=
StringTurnFloat64
(
companyTycInfo
.
Result
.
RegCapital
[
:
StringIndex
(
companyTycInfo
.
Result
.
RegCapital
,
"亿"
)])
*
100000000
}
else
{
if
strings
.
Contains
(
companyTycInfo
.
Result
.
RegCapital
,
"万"
)
{
capitalNum
=
StringTurnFloat64
(
companyTycInfo
.
Result
.
RegCapital
[
:
StringIndex
(
companyTycInfo
.
Result
.
RegCapital
,
"万"
)])
*
10000
}
else
if
strings
.
Contains
(
companyTycInfo
.
Result
.
RegCapital
,
"亿"
)
{
capitalNum
=
StringTurnFloat64
(
companyTycInfo
.
Result
.
RegCapital
[
:
StringIndex
(
companyTycInfo
.
Result
.
RegCapital
,
"亿"
)])
*
100000000
}
else
{
capitalNum
=
StringTurnFloat64
(
companyTycInfo
.
Result
.
RegCapital
)
}
if
capitalNum
>
9999999999
{
capitalNum
=
9999999999
if
capitalNum
>
9999999999
{
capitalNum
=
9999999999
}
returnData
[
"registered_capital"
]
=
strconv
.
FormatFloat
(
capitalNum
,
'f'
,
-
1
,
64
)
//------------------------------------两年内是否有法律诉讼---------------------------------------//
respBody
=
BasicHttpGet
(
LAWSUIT
,
companyName
)
json
.
Unmarshal
(
respBody
,
&
totalNum
)
respBody
=
postRequest
(
companyName
,
"law_suit"
)
json
.
Unmarshal
(
respBody
,
&
totalNum
)
//防止sql执行字符串超长
if
len
(
string
(
respBody
))
<
120000
{
returnData
[
"tianyancha_json"
]
+=
"||||"
+
string
(
respBody
)
returnData
[
"tianyancha_json"
]
+=
"||||"
+
string
(
respBody
)
}
if
totalNum
.
Result
.
Total
>
0
{
returnData
[
"two_years_no_lawsuit"
]
=
"有"
}
else
{
}
else
{
returnData
[
"two_years_no_lawsuit"
]
=
"无"
}
//------------------------------------两年内是否有法律诉讼---------------------------------------//
//------------------------------------五年内法人变更---------------------------------------//
respBody
=
BasicHttpGet
(
CHANGEINFO
,
companyName
)
json
.
Unmarshal
(
respBody
,
&
totalNum
)
respBody
=
postRequest
(
companyName
,
"change_info"
)
json
.
Unmarshal
(
respBody
,
&
totalNum
)
//防止sql执行字符串超长
if
len
(
string
(
respBody
))
<
120000
{
returnData
[
"tianyancha_json"
]
+=
"||||"
+
string
(
respBody
)
if
len
(
string
(
respBody
))
<
120000
{
returnData
[
"tianyancha_json"
]
+=
"||||"
+
string
(
respBody
)
}
if
len
(
returnData
[
"tianyancha_json"
])
>
40000
{
if
len
(
returnData
[
"tianyancha_json"
])
>
40000
{
returnData
[
"tianyancha_json"
]
=
"字符串过长"
}
var
changeInfoNum
int64
var
changeInfoNum
int64
changeInfoNum
=
0
for
_
,
v
:=
range
totalNum
.
Result
.
Items
{
if
strings
.
Contains
(
v
[
"changeItem"
],
"法定负责人"
)
&&
(
DateTurnInt64
(
v
[
"changeTime"
])
+
(
365
*
86400
*
5
))
<
time
.
Now
()
.
Unix
()
{
changeInfoNum
++
for
_
,
v
:=
range
totalNum
.
Result
.
Items
{
if
strings
.
Contains
(
v
[
"changeItem"
],
"法定负责人"
)
&&
(
DateTurnInt64
(
v
[
"changeTime"
])
+
(
365
*
86400
*
5
))
<
time
.
Now
()
.
Unix
()
{
changeInfoNum
++
}
}
returnData
[
"five_legal_change"
]
=
strconv
.
FormatInt
(
changeInfoNum
,
10
)
returnData
[
"five_legal_change"
]
=
strconv
.
FormatInt
(
changeInfoNum
,
10
)
//------------------------------------五年内法人变更---------------------------------------//
return
returnData
}
func
NetBasicHttpGet
(
url
,
name
string
)(
respBody
[]
byte
)
{
func
postRequest
(
name
,
method
string
)
(
respBody
[]
byte
)
{
//Encode the data
postBody
,
_
:=
json
.
Marshal
(
map
[
string
]
string
{
"keyword"
:
name
,
"region"
:
"1"
,
"select_type"
:
"1"
,
"method"
:
method
,
})
responseBody
:=
bytes
.
NewBuffer
(
postBody
)
//Leverage Go's HTTP Post function to make request
resp
,
err
:=
http
.
Post
(
YITIHUAREQUEST
,
"application/json"
,
responseBody
)
//Handle Error
if
err
!=
nil
{
log
.
Fatalf
(
"An Error Occured %v"
,
err
)
}
defer
resp
.
Body
.
Close
()
//Read the response body
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
log
.
Fatalln
(
err
)
}
jsonx
:=
string
(
body
)
a
:=
gjson
.
Get
(
jsonx
,
"data"
)
.
String
()
return
[]
byte
(
a
)
}
func
GetBytes
(
key
interface
{})
([]
byte
,
error
)
{
var
buf
bytes
.
Buffer
enc
:=
gob
.
NewEncoder
(
&
buf
)
err
:=
enc
.
Encode
(
key
)
if
err
!=
nil
{
return
nil
,
err
}
return
buf
.
Bytes
(),
nil
}
func
NetBasicHttpGet
(
url
,
name
string
)
(
respBody
[]
byte
)
{
req
,
err
:=
http
.
NewRequest
(
"GET"
,
url
,
nil
)
q
:=
req
.
URL
.
Query
()
q
.
Add
(
"pageNum"
,
"1"
)
q
.
Add
(
"name"
,
name
)
q
.
Add
(
"pageNum"
,
"1"
)
q
.
Add
(
"name"
,
name
)
req
.
URL
.
RawQuery
=
q
.
Encode
()
req
.
Header
.
Set
(
"Authorization"
,
TIANYANCHATOKEN
)
req
.
Header
.
Set
(
"Authorization"
,
TIANYANCHATOKEN
)
var
resp
*
http
.
Response
resp
,
err
=
http
.
DefaultClient
.
Do
(
req
)
...
...
@@ -175,15 +220,15 @@ func NetBasicHttpGet(url,name string)(respBody []byte) {
}
//内网访问
func
BasicHttpGet
(
url
,
name
string
)(
respBody
[]
byte
)
{
func
BasicHttpGet
(
url
,
name
string
)
(
respBody
[]
byte
)
{
req
,
err
:=
http
.
NewRequest
(
"GET"
,
"https://bigdata.ichunt.com/tyc_trun.php"
,
nil
)
q
:=
req
.
URL
.
Query
()
q
.
Add
(
"pageNum"
,
"1"
)
q
.
Add
(
"name"
,
name
)
q
.
Add
(
"url"
,
url
)
q
.
Add
(
"token"
,
TIANYANCHATOKEN
)
q
.
Add
(
"pageNum"
,
"1"
)
q
.
Add
(
"name"
,
name
)
q
.
Add
(
"url"
,
url
)
q
.
Add
(
"token"
,
TIANYANCHATOKEN
)
req
.
URL
.
RawQuery
=
q
.
Encode
()
var
resp
*
http
.
Response
resp
,
err
=
http
.
DefaultClient
.
Do
(
req
)
...
...
@@ -192,4 +237,4 @@ func BasicHttpGet(url,name string)(respBody []byte) {
log
.
Print
(
err
)
}
return
body
}
\ No newline at end of file
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment