// ajax请求 func (this *TaoBaoSdk) api(url, method string, result interface{}) error { // Ajax请求 var dataByte []byte err := util.DefaultAjaxPool.Get(&util.Ajax{ Method: method, Url: url, Header: map[string]string{ "Content-Type": "application/x-www-form-urlencoded;charset=utf-8", }, ResponseData: &dataByte, }) if err != nil { return err } // fmt.Printf("%+v\n", string(dataByte)) // 错误结果 errorResult := TaoBaoKeErrorResponse{} err = encoding.DecodeJson(dataByte, &errorResult) if err == nil && errorResult.ErrorResponse.Code != 0 { return errors.New(string(dataByte)) } // 正常结果 err = encoding.DecodeJson(dataByte, &result) if err != nil { return err } return nil }
// 将参数结构体转为map func (this *TaoBaoSdk) getParamMap(param TaoBaoKeParam) (map[string]string, error) { paramMap := map[string]string{} jsonParam, err := encoding.EncodeJson(param) if err != nil { return paramMap, err } err = encoding.DecodeJson(jsonParam, ¶mMap) if err != nil { return paramMap, err } return paramMap, nil }