iedc-go/dri/aliyun/company.go

135 lines
3.2 KiB
Go
Raw Normal View History

2022-01-16 20:47:39 +00:00
package aliyun
import (
2022-03-12 17:12:29 +00:00
. "code.hoteas.com/golang/hotime/common"
2022-01-16 20:47:39 +00:00
"fmt"
"io/ioutil"
"net/http"
//"fmt"
)
2022-03-12 17:48:54 +00:00
type company struct {
2022-01-16 20:47:39 +00:00
ApiCode string
Url string
}
2022-03-12 17:48:54 +00:00
var Company = company{}
func (that *company) Init(apiCode string) {
2022-01-16 20:47:39 +00:00
//"06c6a07e89dd45c88de040ee1489eef7"
2022-03-12 17:48:54 +00:00
that.ApiCode = apiCode
that.Url = "http://api.81api.com"
2022-01-16 20:47:39 +00:00
}
2022-03-12 17:48:54 +00:00
// GetCompanyOtherAll 获取企业基础信息
func (that *company) GetCompanyOtherAll(name string) Map {
2022-01-22 21:13:19 +00:00
res := Map{}
2022-03-12 17:48:54 +00:00
data, e := that.GetCompanyPatentsInfo(name) //获取专利信息
2022-01-22 21:13:19 +00:00
if e != nil {
fmt.Println(e)
} else {
res["PatentsInfo"] = data.GetMap("data")
}
2022-03-12 17:48:54 +00:00
data, e = that.GetCompanyOtherCopyrightsInfo(name) //获取其他专利
2022-01-22 21:13:19 +00:00
if e != nil {
fmt.Println(e)
} else {
res["OtherCopyrightsInfo"] = data.GetMap("data")
}
2022-03-12 17:48:54 +00:00
data, e = that.GetCompanyTrademarksInfo(name) //获取商标
2022-01-22 21:13:19 +00:00
if e != nil {
fmt.Println(e)
} else {
res["TrademarksInfo"] = data.GetMap("data")
}
2022-03-12 17:48:54 +00:00
data, e = that.GetCompanySoftwareCopyrightsInfo(name) //获取软著
2022-01-22 21:13:19 +00:00
if e != nil {
fmt.Println(e)
} else {
res["SoftwareCopyrightsInfo"] = data.GetMap("data")
}
2022-03-12 17:48:54 +00:00
data, e = that.GetCompanyProfileTags(name) //获取大数据标签
2022-01-22 21:13:19 +00:00
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 获取企业基础信息
2022-03-12 17:48:54 +00:00
func (that *company) GetCompanyBaseInfo(name string) (Map, error) {
2022-01-16 20:47:39 +00:00
url := "/getCompanyBaseInfo/"
2022-03-12 17:48:54 +00:00
body, err := that.basePost(url, name)
2022-01-22 21:13:19 +00:00
return ObjToMap(body), err
}
// GetCompanyPatentsInfo 获取专利信息
2022-03-12 17:48:54 +00:00
func (that *company) GetCompanyPatentsInfo(name string) (Map, error) {
2022-01-22 21:13:19 +00:00
url := "/getCompanyPatentsInfo/"
2022-03-12 17:48:54 +00:00
body, err := that.basePost(url, name)
2022-01-22 21:13:19 +00:00
return ObjToMap(body), err
}
2022-03-12 17:48:54 +00:00
// GetCompanyTrademarksInfo 获取商标信息
func (that *company) GetCompanyTrademarksInfo(name string) (Map, error) {
2022-01-22 21:13:19 +00:00
url := "/getCompanyTrademarksInfo/"
2022-03-12 17:48:54 +00:00
body, err := that.basePost(url, name)
2022-01-22 21:13:19 +00:00
return ObjToMap(body), err
}
2022-03-12 17:48:54 +00:00
// GetCompanySoftwareCopyrightsInfo 获取软著信息
func (that *company) GetCompanySoftwareCopyrightsInfo(name string) (Map, error) {
2022-01-22 21:13:19 +00:00
url := "/getCompanySoftwareCopyrightsInfo/"
2022-03-12 17:48:54 +00:00
body, err := that.basePost(url, name)
2022-01-22 21:13:19 +00:00
return ObjToMap(body), err
}
2022-03-12 17:48:54 +00:00
// GetCompanyOtherCopyrightsInfo 获取其他著作信息
func (that *company) GetCompanyOtherCopyrightsInfo(name string) (Map, error) {
2022-01-22 21:13:19 +00:00
url := "/getCompanyOtherCopyrightsInfo/"
2022-03-12 17:48:54 +00:00
body, err := that.basePost(url, name)
2022-01-22 21:13:19 +00:00
return ObjToMap(body), err
}
2022-03-12 17:48:54 +00:00
// GetCompanyProfileTags 获取大数据标签
func (that *company) GetCompanyProfileTags(name string) (Map, error) {
2022-01-22 21:13:19 +00:00
url := "/getCompanyProfileTags/"
2022-03-12 17:48:54 +00:00
body, err := that.basePost(url, name)
2022-01-22 21:13:19 +00:00
return ObjToMap(body), err
}
2022-03-12 17:48:54 +00:00
func (that *company) basePost(url string, name string) (string, error) {
2022-01-22 21:13:19 +00:00
2022-01-16 20:47:39 +00:00
client := &http.Client{}
2022-03-12 17:48:54 +00:00
reqest, err := http.NewRequest("GET", that.Url+url+name+"/?isRaiseErrorCode=1", nil)
2022-01-16 20:47:39 +00:00
if err != nil {
fmt.Println("Fatal error ", err.Error())
return "", err
}
2022-03-12 17:48:54 +00:00
reqest.Header.Add("Authorization", "APPCODE "+that.ApiCode)
2022-01-16 20:47:39 +00:00
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
}