iedc-go/dri/aliyun/company.go

139 lines
3.1 KiB
Go
Raw Normal View History

2022-01-16 20:47:39 +00:00
package aliyun
import (
2022-01-22 21:13:19 +00:00
. "../../common"
2022-01-16 20:47:39 +00:00
"fmt"
"io/ioutil"
"net/http"
//"fmt"
)
type Company struct {
ApiCode string
Url string
}
func (this *Company) Init(apiCode string) {
//"06c6a07e89dd45c88de040ee1489eef7"
this.ApiCode = apiCode
2022-01-22 21:13:19 +00:00
this.Url = "http://api.81api.com"
2022-01-16 20:47:39 +00:00
}
// GetCompanyBaseInfo 获取企业基础信息
2022-01-22 21:13:19 +00:00
func (this *Company) GetCompanyOtherAll(name string) Map {
res := Map{}
data, e := this.GetCompanyPatentsInfo(name) //获取专利信息
if e != nil {
fmt.Println(e)
} else {
res["PatentsInfo"] = data.GetMap("data")
}
data, e = this.GetCompanyOtherCopyrightsInfo(name) //获取其他专利
if e != nil {
fmt.Println(e)
} else {
res["OtherCopyrightsInfo"] = data.GetMap("data")
}
data, e = this.GetCompanyTrademarksInfo(name) //获取商标
if e != nil {
fmt.Println(e)
} else {
res["TrademarksInfo"] = data.GetMap("data")
}
data, e = this.GetCompanySoftwareCopyrightsInfo(name) //获取软著
if e != nil {
fmt.Println(e)
} else {
res["SoftwareCopyrightsInfo"] = data.GetMap("data")
}
data, e = this.GetCompanyProfileTags(name) //获取大数据标签
if e != nil {
fmt.Println(e)
} else {
2022-02-14 11:10:58 +00:00
res["ProfileTags"] = data.GetSlice("data")
2022-01-22 21:13:19 +00:00
}
return res
}
// GetCompanyBaseInfo 获取企业基础信息
func (this *Company) GetCompanyBaseInfo(name string) (Map, error) {
2022-01-16 20:47:39 +00:00
url := "/getCompanyBaseInfo/"
2022-01-22 21:13:19 +00:00
body, err := this.basePost(url, name)
return ObjToMap(body), err
}
// GetCompanyPatentsInfo 获取专利信息
func (this *Company) GetCompanyPatentsInfo(name string) (Map, error) {
url := "/getCompanyPatentsInfo/"
body, err := this.basePost(url, name)
return ObjToMap(body), err
}
// 获取商标信息
func (this *Company) GetCompanyTrademarksInfo(name string) (Map, error) {
url := "/getCompanyTrademarksInfo/"
body, err := this.basePost(url, name)
return ObjToMap(body), err
}
// 获取软著信息
func (this *Company) GetCompanySoftwareCopyrightsInfo(name string) (Map, error) {
url := "/getCompanySoftwareCopyrightsInfo/"
body, err := this.basePost(url, name)
return ObjToMap(body), err
}
// 获取其他著作信息
func (this *Company) GetCompanyOtherCopyrightsInfo(name string) (Map, error) {
url := "/getCompanyOtherCopyrightsInfo/"
body, err := this.basePost(url, name)
return ObjToMap(body), err
}
// 获取大数据标签
func (this *Company) GetCompanyProfileTags(name string) (Map, error) {
url := "/getCompanyProfileTags/"
body, err := this.basePost(url, name)
return ObjToMap(body), err
}
func (this *Company) basePost(url string, name string) (string, error) {
2022-01-16 20:47:39 +00:00
client := &http.Client{}
reqest, err := http.NewRequest("GET", this.Url+url+name+"/?isRaiseErrorCode=1", nil)
if err != nil {
fmt.Println("Fatal error ", err.Error())
return "", err
}
reqest.Header.Add("Authorization", "APPCODE "+this.ApiCode)
response, err := client.Do(reqest)
defer response.Body.Close()
if err != nil {
fmt.Println("Fatal error ", err.Error())
return "", err
}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return "", err
}
2022-01-22 21:13:19 +00:00
res := string(body)
fmt.Println(res)
return res, err
2022-01-16 20:47:39 +00:00
}
var DefaultCompany Company
func init() {
DefaultCompany = Company{}
}