diff --git a/service/tianyancha/equity.human_indexnode.go b/service/tianyancha/equity.human_indexnode.go index 4ad3c45a..402e00ab 100644 --- a/service/tianyancha/equity.human_indexnode.go +++ b/service/tianyancha/equity.human_indexnode.go @@ -1,10 +1,11 @@ package tianyancha import ( + "encoding/json" "net/http" ) -type EquityHumanIndexNodeResult struct { +type EquityHumanIndexNodeResponse struct { IsLogin int `json:"isLogin"` Message string `json:"message"` Special string `json:"special"` @@ -12,10 +13,23 @@ type EquityHumanIndexNodeResult struct { VipMessage string `json:"vipMessage"` } -func (app *App) EquityHumanIndexNode(notMustParams ...Params) (body []byte, err error) { +type EquityHumanIndexNodeResult struct { + Result EquityHumanIndexNodeResponse // 结果 + Body []byte // 内容 + Err error // 错误 +} + +func NewEquityHumanIndexNodeResult(result EquityHumanIndexNodeResponse, body []byte, err error) *EquityHumanIndexNodeResult { + return &EquityHumanIndexNodeResult{Result: result, Body: body, Err: err} +} + +func (app *App) EquityHumanIndexNode(notMustParams ...Params) *EquityHumanIndexNodeResult { // 参数 params := app.NewParamsWith(notMustParams...) // 请求 - body, err = app.request("https://capi.tianyancha.com/cloud-equity-provider/v4/equity/humanIndexnode.json", params, http.MethodGet) - return body, err + body, err := app.request("https://capi.tianyancha.com/cloud-equity-provider/v4/equity/humanIndexnode.json", params, http.MethodGet) + // 定义 + var response EquityHumanIndexNodeResponse + err = json.Unmarshal(body, &response) + return NewEquityHumanIndexNodeResult(response, body, err) } diff --git a/service/tianyancha/search.go b/service/tianyancha/search.human_suggest.go similarity index 69% rename from service/tianyancha/search.go rename to service/tianyancha/search.human_suggest.go index f55076dd..a4eb8643 100644 --- a/service/tianyancha/search.go +++ b/service/tianyancha/search.human_suggest.go @@ -1,11 +1,12 @@ package tianyancha import ( + "encoding/json" "fmt" "net/http" ) -type SearchHumanSuggestResult struct { +type SearchHumanSuggestResponse struct { Data struct { Id int `json:"id"` HumanName interface{} `json:"humanName"` @@ -44,7 +45,20 @@ type SearchHumanSuggestResult struct { State string `json:"state"` } -func (app *App) SearchHumanSuggest(key string) (body []byte, err error) { - body, err = app.request(fmt.Sprintf("https://www.tianyancha.com/search/humanSuggest.json?key=%s", key), map[string]interface{}{}, http.MethodGet) - return body, err +type SearchHumanSuggestResult struct { + Result SearchHumanSuggestResponse // 结果 + Body []byte // 内容 + Err error // 错误 +} + +func NewSearchHumanSuggestResult(result SearchHumanSuggestResponse, body []byte, err error) *SearchHumanSuggestResult { + return &SearchHumanSuggestResult{Result: result, Body: body, Err: err} +} + +func (app *App) SearchHumanSuggest(key string) *SearchHumanSuggestResult { + body, err := app.request(fmt.Sprintf("https://www.tianyancha.com/search/humanSuggest.json?key=%s", key), map[string]interface{}{}, http.MethodGet) + // 定义 + var response SearchHumanSuggestResponse + err = json.Unmarshal(body, &response) + return NewSearchHumanSuggestResult(response, body, err) }