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.
go-library/service/wechatopen/wxa.get_category.go

48 lines
1.8 KiB

package wechatopen
import (
"context"
"github.com/dtapps/go-library/utils/gojson"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
)
type WxaGetCategoryResponse struct {
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
CategoryList []struct {
FirstClass string `json:"first_class"` // 一级类目名称
SecondClass string `json:"second_class"` // 二级类目名称
ThirdClass string `json:"third_class"` // 三级类目名称
FirstId int `json:"first_id"` // 一级类目的 ID 编号
SecondId int `json:"second_id"` // 二级类目的 ID 编号
ThirdId int `json:"third_id"` // 三级类目的 ID 编号
} `json:"category_list"`
}
type WxaGetCategoryResult struct {
Result WxaGetCategoryResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
}
func newWxaGetCategoryResult(result WxaGetCategoryResponse, body []byte, http gorequest.Response) *WxaGetCategoryResult {
return &WxaGetCategoryResult{Result: result, Body: body, Http: http}
}
// WxaGetCategory 获取审核时可填写的类目信息
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/category/get_category.html
func (c *Client) WxaGetCategory(ctx context.Context, authorizerAccessToken string, notMustParams ...gorequest.Params) (*WxaGetCategoryResult, error) {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/get_category?access_token="+authorizerAccessToken, params, http.MethodGet)
if err != nil {
return newWxaGetCategoryResult(WxaGetCategoryResponse{}, request.ResponseBody, request), err
}
// 定义
var response WxaGetCategoryResponse
err = gojson.Unmarshal(request.ResponseBody, &response)
return newWxaGetCategoryResult(response, request.ResponseBody, request), err
}