You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
4.3 KiB
150 lines
4.3 KiB
4 years ago
|
package tianyan
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"github.com/mitchellh/mapstructure"
|
||
|
"io/ioutil"
|
||
|
"net/http"
|
||
|
"net/url"
|
||
|
"recook/configs"
|
||
|
"strconv"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
token = configs.Config_Tianyan_Token
|
||
|
actionBaseInfo = "https://open.api.tianyancha.com/services/open/ic/baseinfo/2.0"
|
||
|
actionTaxPayer = "https://open.api.tianyancha.com/services/open/m/taxpayer/2.0"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
Company = &company{}
|
||
|
client = &http.Client{}
|
||
|
)
|
||
|
|
||
|
type company struct {
|
||
|
}
|
||
|
|
||
|
type BaseInfo struct {
|
||
|
ActualCapital string `json:"actualCapital"`
|
||
|
Alias string `json:"alias"`
|
||
|
ApprovedTime int64 `json:"approvedTime"`
|
||
|
Base string `json:"base"`
|
||
|
BondName string `json:"bondName"`
|
||
|
BondNum string `json:"bondNum"`
|
||
|
BondType string `json:"bondType"`
|
||
|
BusinessScope string `json:"businessScope"`
|
||
|
CancelDate int64 `json:"cancelDate"`
|
||
|
CancelReason string `json:"cancelReason"`
|
||
|
CompanyOrgType string `json:"companyOrgType"`
|
||
|
CreditCode string `json:"creditCode"`
|
||
|
EstiblishTime int64 `json:"estiblishTime"`
|
||
|
FromTime int64 `json:"fromTime"`
|
||
|
HistoryNames string `json:"historyNames"`
|
||
|
ID int64 `json:"id"`
|
||
|
Industry string `json:"industry"`
|
||
|
IsMicroEnt int64 `json:"isMicroEnt"`
|
||
|
LegalPersonName string `json:"legalPersonName"`
|
||
|
Name string `json:"name"`
|
||
|
OrgNumber string `json:"orgNumber"`
|
||
|
PercentileScore int64 `json:"percentileScore"`
|
||
|
Property3 string `json:"property3"`
|
||
|
RegCapital string `json:"regCapital"`
|
||
|
RegInstitute string `json:"regInstitute"`
|
||
|
RegLocation string `json:"regLocation"`
|
||
|
RegNumber string `json:"regNumber"`
|
||
|
RegStatus string `json:"regStatus"`
|
||
|
RevokeDate int64 `json:"revokeDate"`
|
||
|
RevokeReason string `json:"revokeReason"`
|
||
|
SocialStaffNum int64 `json:"socialStaffNum"`
|
||
|
StaffNumRange string `json:"staffNumRange"`
|
||
|
Tags string `json:"tags"`
|
||
|
TaxNumber string `json:"taxNumber"`
|
||
|
ToTime int64 `json:"toTime"`
|
||
|
Type int64 `json:"type"`
|
||
|
UsedBondName string `json:"usedBondName"`
|
||
|
IndustryAll
|
||
|
}
|
||
|
|
||
|
type IndustryAll struct {
|
||
|
Category string `json:"category"`
|
||
|
CategoryBig string `json:"categoryBig"`
|
||
|
CategoryMiddle string `json:"categoryMiddle"`
|
||
|
}
|
||
|
type response struct {
|
||
|
ErrorCode int `json:"error_code"`
|
||
|
Reason string `json:"reason"`
|
||
|
Result interface{} `json:"result"`
|
||
|
}
|
||
|
|
||
|
// @Style 基础工商信息
|
||
|
func (c *company) BaseInfo(companyName string) (result BaseInfo, err error) {
|
||
|
err = c.exec(actionBaseInfo+"?"+url.Values{"name": []string{companyName}}.Encode(), "", &result)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
type replyTaxPayer struct {
|
||
|
Total int `json:"total"`
|
||
|
Items []TaxPayer `json:"items"`
|
||
|
}
|
||
|
|
||
|
type TaxPayer struct {
|
||
|
Gid int64 `json:"gid"`
|
||
|
TaxpayerQualificationType string `json:"taxpayerQualificationType"`
|
||
|
EndDate string `json:"endDate"`
|
||
|
Name int64 `json:"name"`
|
||
|
Logo string `json:"logo"`
|
||
|
Alias string `json:"alias"`
|
||
|
TaxpayerIdentificationNumber string `json:"taxpayerIdentificationNumber"`
|
||
|
StartDate string `json:"startDate"`
|
||
|
}
|
||
|
|
||
|
// @Style 基础工商信息
|
||
|
func (c *company) TaxPayer(companyId int64) (result []TaxPayer, err error) {
|
||
|
res := replyTaxPayer{}
|
||
|
err = c.exec(actionTaxPayer+"?"+url.Values{"id": []string{strconv.FormatInt(companyId, 10)}}.Encode(), "", &res)
|
||
|
result = res.Items
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// @Style 执行请求
|
||
|
func (c *company) exec(action, data string, result interface{}) error {
|
||
|
bytes, err := request("GET", action, data, map[string]string{
|
||
|
"Authorization": token,
|
||
|
})
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
resp := response{}
|
||
|
if err := json.Unmarshal(bytes, &resp); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
if err := mapstructure.WeakDecode(resp.Result, result); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
// @Style 请求
|
||
|
func request(method, url, data string, headers ...map[string]string) ([]byte, error) {
|
||
|
reqest, err := http.NewRequest(method, url, strings.NewReader(data))
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if len(headers) > 0 {
|
||
|
for key, value := range headers[0] {
|
||
|
reqest.Header.Add(key, value)
|
||
|
}
|
||
|
}
|
||
|
response, err := client.Do(reqest)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer response.Body.Close()
|
||
|
result, err := ioutil.ReadAll(response.Body)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return result, nil
|
||
|
}
|