提交 47afeff1 authored 作者: 张立波's avatar 张立波

Merge branch 'itao'

...@@ -27,7 +27,7 @@ type NotifyGoodsData struct { ...@@ -27,7 +27,7 @@ type NotifyGoodsData struct {
type ThirdGoods struct { type ThirdGoods struct {
ThirdId interface{} `json:"third_id"` //三方商品id ThirdId interface{} `json:"third_id"` //三方商品id
Skus []int `json:"skus"` //三方规格id Skus []int `json:"skus,omitempty"` //三方规格id
} }
//通知消息系统 //通知消息系统
......
...@@ -86,9 +86,9 @@ func (s *Config) Post(ctx context.Context, method string, params g.Map) (str str ...@@ -86,9 +86,9 @@ func (s *Config) Post(ctx context.Context, method string, params g.Map) (str str
ctx = context.WithValue(ctx, "Method", "POST") ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", Url) ctx = context.WithValue(ctx, "URI", Url)
if err != nil { if err != nil {
g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(PkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else { } else {
g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】响应【%v】响应时间【%v】", str, gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", str, gtime.TimestampMilli()-Start)
} }
}() }()
str = resp.ReadAllString() str = resp.ReadAllString()
......
...@@ -15,6 +15,7 @@ type Config struct { ...@@ -15,6 +15,7 @@ type Config struct {
AppKey string AppKey string
AppSecret string AppSecret string
API string API string
DB int
} }
var server *Config var server *Config
...@@ -24,6 +25,9 @@ const CacheKey = "dwd:token" ...@@ -24,6 +25,9 @@ const CacheKey = "dwd:token"
func New(req *Config) { func New(req *Config) {
server = req server = req
if server.DB == 0 {
server.DB = 10
}
return return
} }
...@@ -89,7 +93,7 @@ func post(ctx context.Context, method string, req interface{}) (res *CommonRes, ...@@ -89,7 +93,7 @@ func post(ctx context.Context, method string, req interface{}) (res *CommonRes,
ctx = context.WithValue(ctx, "Method", "POST") ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", method) ctx = context.WithValue(ctx, "URI", method)
if err != nil { if err != nil {
g.Log().Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", request.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(PkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", request.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else { } else {
g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", request.MustToJsonString(), str, gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", request.MustToJsonString(), str, gtime.TimestampMilli()-Start)
} }
......
...@@ -52,7 +52,7 @@ func (s *tokenDwd) Access(ctx context.Context) (res string, err error) { ...@@ -52,7 +52,7 @@ func (s *tokenDwd) Access(ctx context.Context) (res string, err error) {
defer func() { defer func() {
_ = conn.Close() _ = conn.Close()
}() }()
_, _ = conn.DoVar("SELECT", 10) _, _ = conn.DoVar("SELECT", server.DB)
cache, _ := conn.DoVar("HGETALL", CacheKey) cache, _ := conn.DoVar("HGETALL", CacheKey)
if !cache.IsEmpty() { if !cache.IsEmpty() {
_ = cache.Scan(&s) _ = cache.Scan(&s)
...@@ -90,7 +90,7 @@ func (s *tokenDwd) post(ctx context.Context, req interface{}) (res string, err e ...@@ -90,7 +90,7 @@ func (s *tokenDwd) post(ctx context.Context, req interface{}) (res string, err e
ctx = context.WithValue(ctx, "Method", "POST") ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", "token") ctx = context.WithValue(ctx, "URI", "token")
if err != nil { if err != nil {
g.Log().Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", request.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(PkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", request.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else { } else {
g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", request.MustToJsonString(), res, gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", request.MustToJsonString(), res, gtime.TimestampMilli()-Start)
} }
......
...@@ -48,7 +48,7 @@ func post(ctx context.Context, method string, req interface{}) (res string, err ...@@ -48,7 +48,7 @@ func post(ctx context.Context, method string, req interface{}) (res string, err
ctx = context.WithValue(ctx, "Method", "POST") ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", Url) ctx = context.WithValue(ctx, "URI", Url)
if err != nil { if err != nil {
g.Log().Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else { } else {
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v】", param.MustToJsonString(), res, gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v】", param.MustToJsonString(), res, gtime.TimestampMilli()-Start)
} }
......
...@@ -6,52 +6,57 @@ import ( ...@@ -6,52 +6,57 @@ import (
"crypto/sha1" "crypto/sha1"
"encoding/hex" "encoding/hex"
"github.com/gogf/gf/encoding/gjson" "github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/frame/g" "github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gtime" "github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/util/gconv" "github.com/gogf/gf/util/gconv"
"net/url"
"sort" "sort"
"strings" "strings"
"time" "time"
) )
type Config struct { type Config struct {
ApiUrl string ApiUrl string
AppKey string AppKey string
AppSecret string AppSecret string
AccessToken string DB int
} }
var server *Config var server *Config
const PkgName = "itao" const PkgName = "itao"
const CacheKey = "itao:token"
const Host = "https://open.huoju6.com/openapi/param2/1/com.huoju6.open/"
func New(req *Config) { func New(req *Config) {
server = req server = req
if server.DB == 0 {
server.DB = 10
}
return return
} }
type CommonRes struct { type CommonRes struct {
Success bool `json:"success"` Success bool `json:"success"`
ErrorCode string `json:"errorCode"` ErrCode string `json:"errCode"`
ErrorMessage string `json:"errorMessage"` ErrMsg string `json:"errMsg"`
} }
func (s *Config) CreateSign(signStr string) (sign string) { func generate(req string) (res string) {
//拼接参数 //拼接参数
appSecret := []byte(s.AppSecret) mac := hmac.New(sha1.New, []byte(server.AppSecret))
mac := hmac.New(sha1.New, appSecret) mac.Write([]byte(req))
mac.Write([]byte(signStr))
mdStr := hex.EncodeToString(mac.Sum(nil)) mdStr := hex.EncodeToString(mac.Sum(nil))
sign = strings.ToUpper(mdStr) res = strings.ToUpper(mdStr)
return return
} }
func (s *Config) sign(method string, param g.Map) g.Map { func sign(method string, req g.Map) (err error) {
var keys []string var keys []string
param["_aop_timestamp"] = gtime.Now().TimestampMilliStr() req["_aop_timestamp"] = gtime.Now().TimestampMilliStr()
mewparam := param for k := range req {
for k := range mewparam {
keys = append(keys, k) keys = append(keys, k)
} }
...@@ -61,23 +66,35 @@ func (s *Config) sign(method string, param g.Map) g.Map { ...@@ -61,23 +66,35 @@ func (s *Config) sign(method string, param g.Map) g.Map {
for _, v := range keys { for _, v := range keys {
if v != "_aop_signature" { if v != "_aop_signature" {
signStr += v signStr += v
signStr += gconv.String(mewparam[v]) signStr += gconv.String(req[v])
} }
} }
//拼接参数 //拼接参数
signStr = "param2/1/" + method + "/" + s.AppKey + signStr signStr = "param2/1/com.huoju6.open/" + method + "/" + server.AppKey + signStr
param["_aop_signature"] = s.CreateSign(signStr) req["_aop_signature"] = generate(signStr)
return
return param
} }
func (s *Config) Post(ctx context.Context, method string, params g.Map) (str string, err error) { func (s *Config) Post(ctx context.Context, method string, params g.Map) (str string, err error) {
params["access_token"], err = AccessToken(ctx)
if err != nil {
return
}
str, err = Post(ctx, method, params)
return
}
func Post(ctx context.Context, method string, params g.Map) (str string, err error) {
Start := gtime.TimestampMilli() Start := gtime.TimestampMilli()
allparams := s.sign(method, params) err = sign(method, params)
Url := s.ApiUrl + method + "/" + s.AppKey if err != nil {
return
}
Url := Host + method + "/" + server.AppKey
Request := g.Client() Request := g.Client()
Request.SetHeader("Content-Type", "application/x-www-form-urlencoded") Request.SetHeader("Content-Type", "application/x-www-form-urlencoded")
resp, err := Request.Timeout(time.Second*5).Post(Url, allparams) resp, err := Request.Timeout(time.Second*5).Get(Url, params)
defer func() { defer func() {
_ = resp.Close() _ = resp.Close()
...@@ -95,3 +112,101 @@ func (s *Config) Post(ctx context.Context, method string, params g.Map) (str str ...@@ -95,3 +112,101 @@ func (s *Config) Post(ctx context.Context, method string, params g.Map) (str str
return return
} }
func (s *Config) Get(ctx context.Context, method string, params g.Map) (str string, err error) {
params["access_token"], err = AccessToken(ctx)
if err != nil {
return
}
str, err = Get(ctx, method, params)
return
}
func Get(ctx context.Context, method string, params g.Map) (str string, err error) {
Start := gtime.TimestampMilli()
err = sign(method, params)
if err != nil {
return
}
Url := Host + method + "/" + server.AppKey
Request := g.Client()
Values := url.Values{}
for k, v := range params {
Values.Add(k, gconv.String(v))
}
Request.SetHeader("Content-Type", "application/x-www-form-urlencoded")
resp, err := Request.Timeout(time.Second * 5).Get(Url + "?" + Values.Encode())
defer func() {
_ = resp.Close()
paramStr := gjson.New(params).MustToJsonString()
ctx = context.WithValue(ctx, "Method", "GET")
ctx = context.WithValue(ctx, "URI", Url)
if err != nil {
g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%vms】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】响应【%v】响应时间【%vms】", paramStr, str, gtime.TimestampMilli()-Start)
}
}()
str = resp.ReadAllString()
return
}
func AccessToken(ctx context.Context) (res string, err error) {
var conn = g.Redis().Conn()
defer func() {
_ = conn.Close()
}()
_, _ = conn.DoVar("SELECT", server.DB)
cache, _ := conn.DoVar("HGETALL", CacheKey)
if cache.IsEmpty() {
g.Log().Ctx(ctx).Cat(PkgName).Line(true).Info("获取token失败")
err = gerror.New("获取token失败")
return
}
var result *AuthTokenRes
_ = gjson.New(cache).Scan(&result)
if result == nil {
g.Log().Ctx(ctx).Cat(PkgName).Line(true).Info("获取token失败")
err = gerror.New("获取token失败")
return
}
if result.AccessToken == "" || result.AccessTokenExpireTime < gtime.TimestampMilli() {
result, err = RefreshToken(ctx)
}
res = result.AccessToken
return
}
//RefreshToken 刷新
func RefreshToken(ctx context.Context) (res *AuthTokenRes, err error) {
var conn = g.Redis().Conn()
defer func() {
_ = conn.Close()
}()
_, _ = conn.DoVar("SELECT", server.DB)
cache, _ := conn.DoVar("HGETALL", CacheKey)
if cache.IsEmpty() {
g.Log().Ctx(ctx).Cat(PkgName).Line(true).Info("获取token失败")
err = gerror.New("获取token失败")
return
}
_ = gjson.New(cache).Scan(&res)
if res.AccessTokenExpireTime > gtime.Now().Add(time.Hour).TimestampMilli() {
return
}
res, err = Auth.Token(ctx, res.RefreshToken, 2)
if err != nil {
return
}
if res.Code != "success" {
g.Log().Ctx(ctx).Cat(PkgName).Line(true).Info("获取token失败")
err = gerror.New("获取token失败")
return
}
_, _ = conn.Do("HMSET", CacheKey, "accessToken", res.AccessToken, "accessTokenExpireTime", res.AccessTokenExpireTime)
return
}
...@@ -47,7 +47,7 @@ type AddressDivisionRes struct { ...@@ -47,7 +47,7 @@ type AddressDivisionRes struct {
//Division 行政区划 //Division 行政区划
func (s addressItao) Division(ctx context.Context, req AddressDivisionReq) (res *AddressDivisionRes, err error) { func (s addressItao) Division(ctx context.Context, req AddressDivisionReq) (res *AddressDivisionRes, err error) {
method := "com.alibaba.c2m/ltao.delivery.queryDivision" method := "tt.order.queryDivision"
result, err := server.Post(ctx, method, g.Map{ result, err := server.Post(ctx, method, g.Map{
"param": req, "param": req,
...@@ -64,24 +64,22 @@ type AddressParseReq struct { ...@@ -64,24 +64,22 @@ type AddressParseReq struct {
type AddressParseRes struct { type AddressParseRes struct {
Result struct { Result struct {
Result struct { City string `json:"city"`
City string `json:"city"` CityId int `json:"cityId"`
CityId int `json:"cityId"` District string `json:"district"`
District string `json:"district"` DistrictId int `json:"districtId"`
DistrictId int `json:"districtId"` Prov string `json:"prov"`
Prov string `json:"prov"` ProvId int `json:"provId"`
ProvId int `json:"provId"` Town string `json:"town"`
Town string `json:"town"` TownId int `json:"townId"`
TownId int `json:"townId"`
} `json:"result"`
Success bool `json:"success"`
} `json:"result"` } `json:"result"`
Success bool `json:"success"`
} }
//Parse 地址解析 //Parse 地址解析
// 省、市必传 // 省、市必传
func (s addressItao) Parse(ctx context.Context, req AddressParseReq) (res *AddressParseRes, err error) { func (s addressItao) Parse(ctx context.Context, req AddressParseReq) (res *AddressParseRes, err error) {
method := "com.alibaba.c2m/ltao.delivery.validate" method := "tt.address.validate"
result, err := server.Post(ctx, method, g.Map{ result, err := server.Post(ctx, method, g.Map{
"param": req, "param": req,
......
package itao
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type auth struct {
}
var Auth = auth{}
type AuthStatusRes struct {
Code string `json:"code"`
Message string `json:"message"`
}
//Status 授权状态
func (s auth) Status(ctx context.Context) (res *AuthStatusRes, err error) {
method := "tt.authority.checkAuthStatus"
result, err := server.Get(ctx, method, g.Map{
"bId": server.AppKey,
})
_ = gjson.New(result).Scan(&res)
return
}
type AuthQrCodeRes struct {
Code string `json:"code"`
Message string `json:"message"`
TempCode string `json:"tempCode"`
TempCodeExpireTime string `json:"tempCodeExpireTime"`
QrCodeUrl string `json:"qrCodeUrl"`
}
//QrCode 二维码
func (s auth) QrCode(ctx context.Context) (res *AuthQrCodeRes, err error) {
method := "tt.authority.generateQrCode"
result, err := Get(ctx, method, g.Map{
"bId": server.AppKey,
})
_ = gjson.New(result).Scan(&res)
return
}
type AuthTokenRes struct {
Code string `json:"code"`
Message string `json:"message"`
RefreshToken string `json:"refreshToken"`
AccessToken string `json:"accessToken"`
AccessTokenExpireTime int64 `json:"accessTokenExpireTime"`
RefreshTokenExpireTime int64 `json:"refreshTokenExpireTime"`
TaoteId string `json:"taoteId"`
TaoteNickName string `json:"taoteNickName"`
Feature string `json:"feature"`
GwTraceId string `json:"gw_trace_id"`
}
//Token 授权
func (s auth) Token(ctx context.Context, code string, Type int) (res *AuthTokenRes, err error) {
method := "tt.auth.getAccessToken"
var request = g.Map{
"bId": server.AppKey,
}
if Type == 1 {
request["code"] = code //临时令牌
request["grantType"] = "code"
} else {
request["refreshToken"] = code //刷新令牌
request["grantType"] = "refreshToken"
}
result, err := Get(ctx, method, request)
_ = gjson.New(result).Scan(&res)
return
}
//Unbind 注销授权
func (s auth) Unbind(ctx context.Context) (res *AuthTokenRes, err error) {
method := "tt.authority.unbind"
result, err := server.Get(ctx, method, g.Map{
"bId": server.AppKey,
})
_ = gjson.New(result).Scan(&res)
return
}
...@@ -4,182 +4,384 @@ import ( ...@@ -4,182 +4,384 @@ import (
"context" "context"
"github.com/gogf/gf/encoding/gjson" "github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g" "github.com/gogf/gf/frame/g"
"github.com/gogf/gf/util/gconv"
) )
type goodsItao struct { type goods struct {
} }
var Goods = goodsItao{} var Goods = goods{}
type GoodsDetailRes struct { type GoodsListReq struct {
Q string `json:"q,omitempty"` //关键词
SessionId string `json:"sessionId,omitempty"` //长度不要超过32位,用来分页去重,当前请求只是翻页,则这个值不要改变
Sort string `json:"sort,omitempty"` //排序参数
// 价格降序:sort=price:des
//价格升序:sort=price:asc
//综合排序:sort=popular:des
//销量降序:sort=sales:des
//客户响应率倒序 sort=cst_reply_rate:des
//客户响应率正序 sort=cst_reply_rate:acs
//好评率倒序 sort=pos_review_all_rate_30d:des
//好评率正序 sort=pos_review_all_rate:acs
//退货率倒序 sort=tj_pinzhi_rfd_rate:des
//退货率正序 sort=tj_pinzhi_rfd_rate:acs
//发货时效倒序 sort=ship_ord_rate_7d_104:des
//发货时效正序 sort=ship_ord_rate_7d_104:acs
Price string `json:"price,omitempty"` //价格筛选
//89~248 从89元到248元
//89~ 大于89元
//~248 小于248元
Cate string `json:"cate,omitempty"` //一级类目筛选
S int `json:"s"` //默认0,不是页码,是每次查询的起始位置,相当于 页码x每页数量
N int `json:"n"` //默认20, 每页数量,建议值10,不宜过大
Feature string `json:"feature,omitempty"` //字符串,不是json 请求示例 :{\"poolId\":\"1001\"}
//目前支持的key
//精选商品池映射 poolId
//退货率 refundRateBegin
//退货率 refundRateEnd
//好评率 posReviewRateBegin
//好评率 posReviewRateEnd
//客服响应率 cstRateBegin
//客服响应率 cstRateEnd
//发货时效 shipRateBegin
//发货时效 shipRateEnd
}
type GoodsListRes struct {
Result struct { Result struct {
DebugInfoMap struct { Auctions []struct {
TraceId string `json:"traceId"` Category string `json:"category"`
} `json:"debugInfoMap"` CstRate string `json:"cstRate"`
EnterNewLink string `json:"enterNewLink"` LevelOneCat string `json:"levelOneCat"`
Item struct { Nid string `json:"nid"`
CategoryId []string `json:"categoryId"` PictUrl string `json:"pictUrl"`
CategoryName []string `json:"categoryName"` PosReviewRate string `json:"posReviewRate"`
City string `json:"city"` RefundRate string `json:"refundRate"`
FastPostFee int `json:"fastPostFee"` ReservePrice string `json:"reservePrice"`
Images []string `json:"images"` ShipIn24 string `json:"shipIn24"`
ItemId string `json:"itemId"` ShipRate string `json:"shipRate"`
ItemServices []struct { TejiaTotalSoldQuantity string `json:"tejiaTotalSoldQuantity"`
ActionTitle string `json:"actionTitle,omitempty"` Title string `json:"title"`
ActionUrl string `json:"actionUrl,omitempty"` ZkFinalPrice string `json:"zkFinalPrice"`
Desc string `json:"desc"` } `json:"auctions"`
Title string `json:"title"` PageIndex int `json:"pageIndex"`
} `json:"itemServices"` PageSize int `json:"pageSize"`
MainPic string `json:"mainPic"` TotalCount int `json:"totalCount"`
OrdinaryPostFee int `json:"ordinaryPostFee"`
Props []struct {
Content string `json:"content"`
Word string `json:"word"`
} `json:"props"`
Prov string `json:"prov"`
Receipt bool `json:"receipt"`
SoldQuantity int `json:"soldQuantity"`
Status int `json:"status"`
Title string `json:"title"`
} `json:"item"`
Seller struct {
ShopName string `json:"shopName"`
} `json:"seller"`
SkuBase struct {
Props []struct {
Name string `json:"name"`
Pid string `json:"pid"`
Values []struct {
Image string `json:"image"`
Name string `json:"name"`
Vid string `json:"vid"`
} `json:"values"`
} `json:"props"`
Skus []struct {
PropPath string `json:"propPath"`
SkuId string `json:"skuId"`
} `json:"skus"`
} `json:"skuBase"`
SkuCore struct {
DefaultSkuId int64 `json:"defaultSkuId"`
Sku2Info map[string]GoodsItem `json:"sku2info"`
} `json:"skuCore"`
} `json:"result"` } `json:"result"`
} }
func (goods) List(ctx context.Context, req GoodsListReq) (res *GoodsListRes, err error) {
method := "tt.item.list.v2"
result, err := server.Get(ctx, method, g.Map{
"request": req,
})
_ = gjson.New(result).Scan(&res)
return
}
type GoodsDetailReq struct {
AppKey int `json:"appKey"`
ItemId string `json:"itemId"`
SkuId string `json:"skuId,omitempty"`
}
type GoodsDetailRes struct {
ErrorMessage string `json:"error_message"`
ErrorCode string `json:"error_code"`
DebugInfoMap struct {
TraceId string `json:"traceId"`
} `json:"debugInfoMap"`
EnterNewLink string `json:"enterNewLink"`
Item struct {
CategoryId []string `json:"categoryId"` //商品的类目列表,从一级类目开始
CategoryName []string `json:"categoryName"` //商品的类目标题
City string `json:"city"`
FastPostFee int `json:"fastPostFee"` //商品的快递费用
Images []string `json:"images"`
ItemId string `json:"itemId"` //商品id
ItemServices []struct {
ActionTitle string `json:"actionTitle,omitempty"`
ActionUrl string `json:"actionUrl,omitempty"`
Desc string `json:"desc"`
Title string `json:"title"`
} `json:"itemServices"`
MainPic string `json:"mainPic"`
OrdinaryPostFee int `json:"ordinaryPostFee"` //商品的平邮费用
Props []struct {
Content string `json:"content"`
Word string `json:"word"`
} `json:"props"`
Prov string `json:"prov"`
Receipt bool `json:"receipt"`
SoldQuantity int `json:"soldQuantity"` //商品的销量
Status int `json:"status"` //商品的状态 0,1正常,-1:用户删除,-2:用户下架,-3 小二下架,-4 小二删除,-5 从未上架,-9 CC
Title string `json:"title"` //商品的类目标题
} `json:"item"`
Seller struct { //商品的卖家信息
ShopName string `json:"shopName"` //店铺名称
SellerId string `json:"sellerId"`
} `json:"seller"`
SkuBase struct {
Props []struct {
Name string `json:"name"` //sku的属性名称
Pid string `json:"pid"` //sku的属性id
Values []struct {
Image string `json:"image"`
Name string `json:"name"` //sku的属性内容
Vid string `json:"vid"` //sku的属性内容id
} `json:"values"`
} `json:"props"`
Skus []struct {
PropPath string `json:"propPath"` //sku的属性路径
SkuId string `json:"skuId"`
} `json:"skus"`
} `json:"skuBase"`
SkuCore struct {
Sku2Info map[string]GoodsItem `json:"sku2info"`
} `json:"skuCore"`
}
type GoodsItem struct { type GoodsItem struct {
QuantityVague string `json:"quantityVague"` QuantityVague string `json:"quantityVague"` //模糊化库存,实际库存大于200时展示200,小于200时展示实际的值
OriginalPrice string `json:"originalPrice"` OriginalPrice string `json:"originalPrice"` //特价,报名特价版的价格 单位:分
FinalPrice string `json:"finalPrice"` FinalPrice string `json:"finalPrice"`
TjbMarketPrice string `json:"tjbMarketPrice"` TjbMarketPrice string `json:"tjbMarketPrice"` //市场价
PriceMoney string `json:"priceMoney"` PriceMoney string `json:"priceMoney"` //单品优惠价,参与活动后得价格
} }
//Detail 详情[实时] //Detail 详情
func (goodsItao) Detail(ctx context.Context, GoodsID string) (res *GoodsDetailRes, err error) { func (goods) Detail(ctx context.Context, GoodsID string) (res *GoodsDetailRes, err error) {
method := "com.alibaba.c2m/ltao.detail.jnpiter.getDetail" method := "tt.item.detail.v2"
var request = GoodsDetailReq{
AppKey: gconv.Int(server.AppKey),
ItemId: GoodsID,
SkuId: "",
}
result, err := server.Post(ctx, method, g.Map{ result, err := server.Post(ctx, method, g.Map{
"parameters": g.Map{ "parameters": request,
"itemId": GoodsID,
},
}) })
_ = gjson.New(result).Scan(&res) _ = gjson.New(result).Scan(&res)
return return
} }
type GoodsDynamicRes struct { type GoodsDescRes struct {
Result struct { ErrorMessage string `json:"error_message"`
Data []struct { ErrorCode string `json:"error_code"`
DebugInfoMap struct { Components *GoodsDescItem `json:"components"`
TraceId string `json:"traceId"` }
} `json:"debugInfoMap"`
EnterNewLink string `json:"enterNewLink"` type GoodsDescJson struct {
Sku2Info map[string]GoodsItem `json:"sku2info"` ErrorMessage string `json:"error_message"`
} `json:"data"` ErrorCode string `json:"error_code"`
ItemIds string `json:"itemIds"` Components string `json:"components"`
Time int `json:"time"` }
} `json:"result"` type GoodsDescItem struct {
ComponentData struct {
DetailPic1 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_1"`
DetailPic10 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_10"`
DetailPic11 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_11"`
DetailPic12 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_12"`
DetailPic2 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_2"`
DetailPic3 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_3"`
DetailPic4 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_4"`
DetailPic5 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_5"`
DetailPic6 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_6"`
DetailPic7 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_7"`
DetailPic8 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_8"`
DetailPic9 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_9"`
DetailPicTmallPriceDesc struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
Height string `json:"height"`
Width string `json:"width"`
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_tmallPriceDesc"`
} `json:"componentData"`
Layout []struct {
ID string `json:"ID"`
Key string `json:"key"`
} `json:"layout"`
} }
//Dynamic 详情[动态] //Desc 详情描述
func (goodsItao) Dynamic(ctx context.Context, GoodsID string) (res *GoodsDynamicRes, err error) { func (goods) Desc(ctx context.Context, GoodsID string) (res *GoodsDescRes, err error) {
method := "com.alibaba.c2m/ltao.detail.csp.getDetailDynamic" method := "tt.item.desc"
result, err := server.Post(ctx, method, g.Map{ result, err := server.Get(ctx, method, g.Map{
"parameters": g.Map{ "itemId": GoodsID,
"itemIds": GoodsID,
},
}) })
_ = gjson.New(result).Scan(&res) var data *GoodsDescJson
err = gjson.New(result).Scan(&data)
if err != nil {
return
}
if data.ErrorCode != "" {
err = gjson.New(result).Scan(&res)
return
}
res = new(GoodsDescRes)
_ = gjson.New(data.Components).Scan(&res.Components)
return return
} }
type GoodBatchRes struct { type GoodsCategoryRes struct {
Result struct { ErrorMessage string `json:"error_message"`
Data []struct { ErrorCode string `json:"error_code"`
DebugInfoMap struct { CateNameLists []string `json:"cateNameLists"`
TraceId string `json:"traceId"` Code string `json:"code"`
} `json:"debugInfoMap"` ItemId string `json:"itemId"`
EnterNewLink string `json:"enterNewLink"` ItemName string `json:"itemName"`
Item struct { Message string `json:"message"`
CategoryId []string `json:"categoryId"`
CategoryName []string `json:"categoryName"`
City string `json:"city"`
FastPostFee int `json:"fastPostFee"`
Images []string `json:"images"`
ItemId string `json:"itemId"`
ItemServices []struct {
ActionTitle string `json:"actionTitle,omitempty"`
ActionUrl string `json:"actionUrl,omitempty"`
Desc string `json:"desc"`
Title string `json:"title"`
} `json:"itemServices"`
MainPic string `json:"mainPic"`
OrdinaryPostFee int `json:"ordinaryPostFee"`
Props []struct {
Content string `json:"content"`
Word string `json:"word"`
} `json:"props"`
Prov string `json:"prov"`
Receipt bool `json:"receipt"`
SoldQuantity int `json:"soldQuantity"`
Status int `json:"status"`
Title string `json:"title"`
} `json:"item"`
Seller struct {
ShopName string `json:"shopName"`
} `json:"seller"`
Sku2Info map[string]GoodsItem `json:"sku2info"`
SkuBase struct {
Props []struct {
Name string `json:"name"`
Pid string `json:"pid"`
Values []struct {
Image string `json:"image"`
Name string `json:"name"`
Vid string `json:"vid"`
} `json:"values"`
} `json:"props"`
Skus []struct {
PropPath string `json:"propPath"`
SkuId string `json:"skuId"`
} `json:"skus"`
} `json:"skuBase"`
} `json:"data"`
ItemIds string `json:"itemIds"`
Time int `json:"time"`
} `json:"result"`
} }
//Batch 详情[批量] //Category 商品类目
func (goodsItao) Batch(ctx context.Context, GoodsID string) (res *GoodBatchRes, err error) { func (goods) Category(ctx context.Context, GoodsID string) (res *GoodsCategoryRes, err error) {
method := "com.alibaba.c2m/ltao.detail.csp.getDetail" method := "tt.item.cateInfo"
result, err := server.Post(ctx, method, g.Map{ result, err := server.Get(ctx, method, g.Map{
"parameters": g.Map{ "itemId": GoodsID,
"itemIds": GoodsID,
},
}) })
_ = gjson.New(result).Scan(&res) _ = gjson.New(result).Scan(&res)
return return
......
...@@ -6,47 +6,49 @@ import ( ...@@ -6,47 +6,49 @@ import (
"github.com/gogf/gf/frame/g" "github.com/gogf/gf/frame/g"
) )
type logisticsItao struct { type logistics struct {
} }
var Logistics = logisticsItao{} var Logistics = logistics{}
type LogisticsTraceRes struct { type LogisticsTraceRes struct {
Result struct { Success bool `json:"success"`
Result []struct { ErrMsg string `json:"errMsg"`
DetailList []struct { ErrCode string `json:"errCode"`
Action string `json:"action"` Result []struct {
GmtCreate string `json:"gmtCreate"` CompanyList []struct {
StanderdDesc string `json:"standerdDesc"` BrandCode string `json:"brandCode"`
Status string `json:"status"` CompanyName string `json:"companyName"`
Time string `json:"time"` } `json:"companyList"`
MailNo string `json:"mailNo,omitempty"` DetailList []struct {
TpName string `json:"tpName,omitempty"` Action string `json:"action"`
} `json:"detailList"` GmtCreate string `json:"gmtCreate"`
GoodsList []interface{} `json:"goodsList"` StanderdDesc string `json:"standerdDesc"`
MailNo string `json:"mailNo"` Status string `json:"status"`
Receiver struct { Time string `json:"time"`
Adr string `json:"adr"` MailNo string `json:"mailNo,omitempty"`
CityName string `json:"cityName"` TpName string `json:"tpName,omitempty"`
DistrictName string `json:"districtName"` } `json:"detailList"`
Name string `json:"name"` GoodsList []interface{} `json:"goodsList"`
ProvinceName string `json:"provinceName"` MailNo string `json:"mailNo"`
Telphone string `json:"telphone"` Receiver struct {
} `json:"receiver"` Adr string `json:"adr"`
Status struct { CityName string `json:"cityName"`
StatusCode string `json:"statusCode"` DistrictName string `json:"districtName"`
StatusDesc string `json:"statusDesc"` Name string `json:"name"`
} `json:"status"` ProvinceName string `json:"provinceName"`
} `json:"result"` Telphone string `json:"telphone"`
Success bool `json:"success"` } `json:"receiver"`
ErrMsg string `json:"errMsg"` Status struct {
ErrCode string `json:"errCode"` StatusCode string `json:"statusCode"`
StatusDesc string `json:"statusDesc"`
} `json:"status"`
} `json:"result"` } `json:"result"`
} }
//Trace 物流轨迹 //Trace 物流轨迹
func (logisticsItao) Trace(ctx context.Context, req string) (res *LogisticsTraceRes, err error) { func (logistics) Trace(ctx context.Context, req string) (res *LogisticsTraceRes, err error) {
method := "com.alibaba.c2m/ltao.logistics.queryDetail" method := "tt.logistics.detail"
result, err := server.Post(ctx, method, g.Map{ result, err := server.Post(ctx, method, g.Map{
"request": g.Map{ "request": g.Map{
...@@ -56,3 +58,43 @@ func (logisticsItao) Trace(ctx context.Context, req string) (res *LogisticsTrace ...@@ -56,3 +58,43 @@ func (logisticsItao) Trace(ctx context.Context, req string) (res *LogisticsTrace
_ = gjson.New(result).Scan(&res) _ = gjson.New(result).Scan(&res)
return return
} }
type LogisticsCompanyRes struct {
Result []LogisticsCompanyItem `json:"result"`
Success bool `json:"success"`
}
type LogisticsCompanyItem struct {
Code string `json:"code"`
Name string `json:"name"`
Id int64 `json:"id"`
Type int `json:"type"`
}
type LogisticsCompany struct {
Result map[string][]interface{} `json:"result"`
Success bool `json:"success"`
}
//Company 物流公司
func (logistics) Company(ctx context.Context, req string) (res *LogisticsCompanyRes, err error) {
method := "tt.refund.queryLogisticList"
result, err := server.Post(ctx, method, g.Map{
"request": g.Map{
"bizOrderId": req,
},
})
var data *LogisticsCompany
_ = gjson.New(result).Scan(&data)
res = new(LogisticsCompanyRes)
res.Success = data.Success
for _, item := range data.Result {
for _, val := range item {
var value []LogisticsCompanyItem
_ = gjson.New(val).Scan(&value)
res.Result = append(res.Result, value...)
}
}
return
}
...@@ -2,15 +2,17 @@ package itao ...@@ -2,15 +2,17 @@ package itao
import ( import (
"context" "context"
"fmt"
"github.com/gogf/gf/encoding/gjson" "github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g" "github.com/gogf/gf/frame/g"
"github.com/gogf/gf/text/gstr"
"github.com/gogf/gf/util/gconv" "github.com/gogf/gf/util/gconv"
) )
type orderItao struct { type order struct {
} }
var Order = orderItao{} var Order = order{}
type OrderBeforeReq struct { type OrderBeforeReq struct {
Address OrderAddress `json:"deliveryAddressInfo"` Address OrderAddress `json:"deliveryAddressInfo"`
...@@ -40,72 +42,79 @@ type OrderItem struct { ...@@ -40,72 +42,79 @@ type OrderItem struct {
} }
type OrderBeforeRes struct { type OrderBeforeRes struct {
Result struct { ErrMsg string `json:"errMsg"`
Result struct { ErrCode string `json:"errCode"`
ExtensionResp struct { Success bool `json:"success"`
TradeId string `json:"tradeId"` GwTraceId string `json:"gw_trace_id"`
} `json:"extensionResp"` Result struct {
InvalidOrderGroups []struct { //不可售商品 ExtensionResp struct {
Image string `json:"image"` TradeId string `json:"tradeId"`
OrderLineRenders []struct { } `json:"extensionResp"`
ErrorMessage struct { InvalidOrderGroups []struct { //不可售商品
ErrorCode string `json:"errorCode"` Image string `json:"image"`
ErrorMsg string `json:"errorMsg"` OrderLineRenders []struct {
} `json:"errorMessage"` ErrorMessage struct {
ItemInfo struct { ErrorCode string `json:"errorCode"`
ItemId string `json:"itemId"` ErrorMsg string `json:"errorMsg"`
SkuId string `json:"skuId"` } `json:"errorMessage"`
} `json:"itemInfo"` ItemInfo struct {
ItemPayPrice uint `json:"itemPayPrice"` ItemId string `json:"itemId"`
OrderLineId int64 `json:"orderLineId"` SkuId string `json:"skuId"`
Quantity uint `json:"quantity"` } `json:"itemInfo"`
} `json:"orderLineRenders"` ItemPayPrice uint `json:"itemPayPrice"`
OrderPayPrice int `json:"orderPayPrice"` OrderLineId int64 `json:"orderLineId"`
Quantity uint `json:"quantity"` Quantity uint `json:"quantity"`
SellerToken string `json:"sellerToken"` } `json:"orderLineRenders"`
Title string `json:"title"` OrderPayPrice int `json:"orderPayPrice"`
} `json:"invalidOrderGroups"` Quantity uint `json:"quantity"`
OriginPriceFee uint `json:"originPriceFee"` SellerToken string `json:"sellerToken"`
PriceFee uint `json:"priceFee"` //单位分 Title string `json:"title"`
PromotionResp OrderPromotion `json:"promotionResp"` } `json:"invalidOrderGroups"`
Quantity uint `json:"quantity"` OriginPriceFee uint `json:"originPriceFee"`
RealPayPrice uint `json:"realPayPrice"` PriceFee uint `json:"priceFee"` //单位分
ReceiveMethodInfo struct { PromotionResp OrderPromotion `json:"promotionResp"`
DeliveryAddressId int `json:"deliveryAddressId"` Quantity uint `json:"quantity"`
Options []interface{} `json:"options"` RealPayPrice uint `json:"realPayPrice"`
} `json:"receiveMethodInfo"` ReceiveMethodInfo struct {
ValidOrderGroups []struct { //可售商品 DeliveryAddressId int `json:"deliveryAddressId"`
DeliveryMethodInfo struct { Options []interface{} `json:"options"`
DeliveryMethodOptionList []struct { } `json:"receiveMethodInfo"`
FareCent uint `json:"fareCent"` //运费 单位分 ValidOrderGroups []struct { //可售商品
Id string `json:"id"` DeliveryMethodInfo struct {
ServiceType int `json:"serviceType"` DeliveryMethodOptionList []struct {
} `json:"deliveryMethodOptionList"` FareCent uint `json:"fareCent"` //运费 单位分
SelectedId string `json:"selectedId"` Id string `json:"id"`
} `json:"deliveryMethodInfo"` ServiceType int `json:"serviceType"`
Image string `json:"image"` } `json:"deliveryMethodOptionList"`
OrderLineRenders []struct { SelectedId string `json:"selectedId"`
ErrorMessage struct { } `json:"deliveryMethodInfo"`
ErrorCode string `json:"errorCode"` Image string `json:"image"`
ErrorMsg string `json:"errorMsg"` OrderLineRenders []struct {
} ErrorMessage struct {
ItemInfo struct { ErrorCode string `json:"errorCode"`
ItemId string `json:"itemId"` ErrorMsg string `json:"errorMsg"`
SkuId string `json:"skuId"` }
} `json:"itemInfo"` ItemInfo struct {
ItemPayPrice uint `json:"itemPayPrice"` ItemId int64 `json:"itemId"`
OrderLineId int64 `json:"orderLineId"` Pic string `json:"pic"`
Quantity uint `json:"quantity"` Price string `json:"price"`
} `json:"orderLineRenders"` SkuId string `json:"skuId"`
OrderPayPrice uint `json:"orderPayPrice"` SkuInfoList []struct {
Quantity uint `json:"quantity"` Name string `json:"name"`
SellerToken string `json:"sellerToken"` Value string `json:"value"`
Title string `json:"title"` } `json:"skuInfoList"`
} `json:"validOrderGroups"` Title string `json:"title"`
} `json:"result"` } `json:"itemInfo"`
Success bool `json:"success"` ItemPayPrice uint `json:"itemPayPrice"`
ErrMsg string `json:"errMsg"` OrderLineId int64 `json:"orderLineId"`
ErrCode string `json:"errCode"` Quantity uint `json:"quantity"`
} `json:"orderLineRenders"`
OrderPayPrice int `json:"orderPayPrice"`
PostFee int `json:"postFee"`
Quantity int `json:"quantity"`
SellerToken string `json:"sellerToken"`
Title string `json:"title"`
} `json:"validOrderGroups"`
} `json:"result"` } `json:"result"`
} }
...@@ -138,8 +147,8 @@ type OrderPromotion struct { ...@@ -138,8 +147,8 @@ type OrderPromotion struct {
} }
//Before 前置校验 //Before 前置校验
func (s orderItao) Before(ctx context.Context, req OrderBeforeReq) (res *OrderBeforeRes, err error) { func (s order) Before(ctx context.Context, req OrderBeforeReq) (res *OrderBeforeRes, err error) {
method := "com.alibaba.c2m/ltao.trade.renderOrder" method := "tt.order.render"
result, err := server.Post(ctx, method, g.Map{ result, err := server.Post(ctx, method, g.Map{
"request": req, "request": req,
...@@ -169,32 +178,29 @@ type OrderCreateDto struct { ...@@ -169,32 +178,29 @@ type OrderCreateDto struct {
} }
type OrderCreateRes struct { type OrderCreateRes struct {
CommonRes
Result struct { Result struct {
Result struct { AlipaySuccess bool `json:"alipaySuccess"`
AlipaySuccess bool `json:"alipaySuccess"` EnablingOrdersResult struct {
EnablingOrdersResult struct { Model struct {
Model struct { AlipayTradeIds []string `json:"alipayTradeIds"`
AlipayTradeIds []string `json:"alipayTradeIds"` OrderIds []string `json:"orderIds"`
OrderIds []string `json:"orderIds"` } `json:"model"`
RedirectUrl string `json:"redirectUrl"` } `json:"enablingOrdersResult"`
} `json:"model"` ExtensionResult struct {
} `json:"enablingOrdersResult"` TraceId string `json:"traceId"`
ExtensionResult struct { } `json:"extensionResult"`
TraceId string `json:"traceId"` PartSuccess bool `json:"partSuccess"`
} `json:"extensionResult"`
PartSuccess bool `json:"partSuccess"`
Success bool `json:"success"`
} `json:"result"`
Success bool `json:"success"`
ErrMsg string `json:"errMsg"`
ErrCode string `json:"errCode"`
} `json:"result"` } `json:"result"`
} }
//Create 下单 //Create 下单
func (s orderItao) Create(ctx context.Context, req OrderCreateReq) (res *OrderCreateRes, err error) { func (s order) Create(ctx context.Context, req OrderCreateReq) (res *OrderCreateRes, err error) {
method := "com.alibaba.c2m/ltao.trade.createAndEnableOrder" method := "tt.order.create"
for k, item := range req.List {
req.List[k].OrderSn = s.outId(item.OrderSn)
}
result, err := server.Post(ctx, method, g.Map{ result, err := server.Post(ctx, method, g.Map{
"request": req, "request": req,
}) })
...@@ -204,51 +210,31 @@ func (s orderItao) Create(ctx context.Context, req OrderCreateReq) (res *OrderCr ...@@ -204,51 +210,31 @@ func (s orderItao) Create(ctx context.Context, req OrderCreateReq) (res *OrderCr
return return
} }
func (s order) outId(req string) (res string) {
res = gstr.SubStr(req, 2, -1)
res = gstr.Replace(res, "_15_", "_")
return fmt.Sprintf("%s_%s", server.AppKey, res)
}
type OrderDetailRes struct { type OrderDetailRes struct {
Result struct { Success bool `json:"success"`
Result struct { ErrMsg string `json:"errMsg"`
BizOrderId int64 `json:"bizOrderId"` Result struct {
BuyAmount int `json:"buyAmount"` BizOrderId string `json:"bizOrderId"`
BuyerToken string `json:"buyerToken"` BuyAmount int `json:"buyAmount"`
Detail int `json:"detail"` BuyerToken string `json:"buyerToken"`
DetailOrderList []struct { Detail int `json:"detail"`
BizOrderId string `json:"bizOrderId"` DetailOrderList []struct {
BuyAmount int `json:"buyAmount"` BizOrderId string `json:"bizOrderId"`
BuyerToken string `json:"buyerToken"` BuyAmount int `json:"buyAmount"`
Detail int `json:"detail"` BuyerToken string `json:"buyerToken"`
EndTime string `json:"endTime"` Detail int `json:"detail"`
GmtCreate string `json:"gmtCreate"` GmtCreate string `json:"gmtCreate"`
ItemInfo struct { ItemInfo struct {
ItemId string `json:"itemId"` ItemId int64 `json:"itemId"`
Pic string `json:"pic"`
Price uint `json:"price"`
SkuId string `json:"skuId"`
SkuInfoList []struct {
Name string `json:"name"`
Value string `json:"value"`
} `json:"skuInfoList"`
Title string `json:"title"`
} `json:"itemInfo"`
LogisticsOrderId int64 `json:"logisticsOrderId"`
LogisticsStatus int `json:"logisticsStatus"`
Main int `json:"main"`
ParentId int64 `json:"parentId"`
PayFee uint `json:"payFee"`
PayOrderId int64 `json:"payOrderId"`
PayStatus int `json:"payStatus"`
PayTime string `json:"payTime"`
PostFee uint `json:"postFee"`
RefundStatus int `json:"refundStatus"`
SellerToken string `json:"sellerToken"`
Status int `json:"status"`
} `json:"detailOrderList"`
EndTime string `json:"endTime"`
GmtCreate string `json:"gmtCreate"`
ItemInfo struct {
ItemId string `json:"itemId"`
Pic string `json:"pic"` Pic string `json:"pic"`
Price uint `json:"price"` Price string `json:"price"`
SkuId string `json:"skuId"` SkuId int64 `json:"skuId"`
SkuInfoList []struct { SkuInfoList []struct {
Name string `json:"name"` Name string `json:"name"`
Value string `json:"value"` Value string `json:"value"`
...@@ -266,7 +252,7 @@ type OrderDetailRes struct { ...@@ -266,7 +252,7 @@ type OrderDetailRes struct {
//8 - 还未创建物流订单 //8 - 还未创建物流订单
Main int `json:"main"` Main int `json:"main"`
ParentId int64 `json:"parentId"` ParentId int64 `json:"parentId"`
PayFee uint `json:"payFee"` PayFee int `json:"payFee"`
PayOrderId int64 `json:"payOrderId"` PayOrderId int64 `json:"payOrderId"`
PayStatus int `json:"payStatus"` PayStatus int `json:"payStatus"`
//1 - 未冻结/未付款 -> 等待买家付款 //1 - 未冻结/未付款 -> 等待买家付款
...@@ -277,20 +263,55 @@ type OrderDetailRes struct { ...@@ -277,20 +263,55 @@ type OrderDetailRes struct {
//8 - 交易被关闭 //8 - 交易被关闭
//9 - 不可付款 //9 - 不可付款
PayTime string `json:"payTime"` PayTime string `json:"payTime"`
PostFee uint `json:"postFee"` PostFee int `json:"postFee"`
RefundStatus int `json:"refundStatus"` RefundStatus int `json:"refundStatus"`
SellerToken string `json:"sellerToken"` SellerToken string `json:"sellerToken"`
Status int `json:"status"` Status int `json:"status"`
} `json:"result"` } `json:"detailOrderList"`
Success bool `json:"success"` GmtCreate string `json:"gmtCreate"`
ErrMsg string `json:"errMsg"` ItemInfo struct {
ErrCode string `json:"errCode"` ItemId int64 `json:"itemId"`
Pic string `json:"pic"`
Price string `json:"price"`
SkuId int64 `json:"skuId"`
SkuInfoList []struct {
Name string `json:"name"`
Value string `json:"value"`
} `json:"skuInfoList"`
Title string `json:"title"`
} `json:"itemInfo"`
LogisticsOrderId int64 `json:"logisticsOrderId"`
LogisticsStatus int `json:"logisticsStatus"`
//1 - 未发货 -> 等待卖家发货
//2 - 已发货 -> 等待买家确认收货
//3 - 已收货 -> 交易成功
//4 - 已经退货 -> 交易失败
//5 - 部分收货 -> 交易成功
//6 - 部分发货中
//8 - 还未创建物流订单
Main int `json:"main"`
ParentId int64 `json:"parentId"`
PayFee int `json:"payFee"`
PayOrderId int64 `json:"payOrderId"`
PayStatus int `json:"payStatus"`
//1 - 未冻结/未付款 -> 等待买家付款
//2 - 已冻结/已付款 -> 等待卖家发货
//4 - 已退款 -> 交易关闭
//6 - 已转交易 -> 交易成功
//7 - 没有创建外部交易
//8 - 交易被关闭
//9 - 不可付款
PayTime string `json:"payTime"`
PostFee int `json:"postFee"`
RefundStatus int `json:"refundStatus"`
SellerToken string `json:"sellerToken"`
Status int `json:"status"`
} `json:"result"` } `json:"result"`
} }
//Detail 详情 //Detail 详情
func (s orderItao) Detail(ctx context.Context, req interface{}) (res *OrderDetailRes, err error) { func (s order) Detail(ctx context.Context, req interface{}) (res *OrderDetailRes, err error) {
method := "com.alibaba.c2m/ltao.trade.queryOrder" method := "tt.order.detail"
result, err := server.Post(ctx, method, g.Map{ result, err := server.Post(ctx, method, g.Map{
"request": g.Map{ "request": g.Map{
...@@ -304,72 +325,104 @@ func (s orderItao) Detail(ctx context.Context, req interface{}) (res *OrderDetai ...@@ -304,72 +325,104 @@ func (s orderItao) Detail(ctx context.Context, req interface{}) (res *OrderDetai
} }
type OrderReflectRes struct { type OrderReflectRes struct {
Result struct { Success bool `json:"success"`
Result struct { ErrMsg string `json:"errMsg"`
BizOrderId string `json:"bizOrderId"` ErrCode string `json:"errCode"`
BuyAmount uint `json:"buyAmount"` Result struct {
BuyerToken string `json:"buyerToken"` BizOrderId string `json:"bizOrderId"`
Detail int `json:"detail"` BuyAmount uint `json:"buyAmount"`
DetailOrderList []struct { BuyerToken string `json:"buyerToken"`
BizOrderId string `json:"bizOrderId"` Detail int `json:"detail"`
BuyAmount uint `json:"buyAmount"` DetailOrderList []struct {
BuyerToken string `json:"buyerToken"` BizOrderId string `json:"bizOrderId"`
Detail int `json:"detail"` BuyAmount uint `json:"buyAmount"`
GmtCreate string `json:"gmtCreate"` BuyerToken string `json:"buyerToken"`
ItemInfo struct { Detail int `json:"detail"`
ItemId string `json:"itemId"` GmtCreate string `json:"gmtCreate"`
Pic string `json:"pic"` ItemInfo struct {
Price uint `json:"price"` ItemId string `json:"itemId"`
SkuId string `json:"skuId"` Pic string `json:"pic"`
SkuInfoList []interface{} `json:"skuInfoList"` Price uint `json:"price"`
Title string `json:"title"` SkuId string `json:"skuId"`
} `json:"itemInfo"` SkuInfoList []struct {
LogisticsOrderId int64 `json:"logisticsOrderId"` Name string `json:"name"`
LogisticsStatus int `json:"logisticsStatus"` Value string `json:"value"`
Main int `json:"main"` } `json:"skuInfoList"`
ParentId int64 `json:"parentId"` Title string `json:"title"`
PayFee uint `json:"payFee"`
PayOrderId int64 `json:"payOrderId"`
PayStatus int `json:"payStatus"`
PostFee uint `json:"postFee"`
RefundStatus int `json:"refundStatus"`
SellerToken string `json:"sellerToken"`
Status int `json:"status"`
} `json:"detailOrderList"`
GmtCreate string `json:"gmtCreate"`
ItemInfo struct {
ItemId string `json:"itemId"`
Pic string `json:"pic"`
Price uint `json:"price"`
SkuId string `json:"skuId"`
SkuInfoList []interface{} `json:"skuInfoList"`
Title string `json:"title"`
} `json:"itemInfo"` } `json:"itemInfo"`
LogisticsOrderId int64 `json:"logisticsOrderId"` LogisticsOrderId int64 `json:"logisticsOrderId"`
LogisticsStatus int `json:"logisticsStatus"` LogisticsStatus int `json:"logisticsStatus"`
Main int `json:"main"` //1 - 未发货 -> 等待卖家发货
ParentId string `json:"parentId"` //2 - 已发货 -> 等待买家确认收货
PayFee uint `json:"payFee"` //3 - 已收货 -> 交易成功
PayOrderId string `json:"payOrderId"` //4 - 已经退货 -> 交易失败
PayStatus int `json:"payStatus"` //5 - 部分收货 -> 交易成功
PostFee uint `json:"postFee"` //6 - 部分发货中
RefundStatus int `json:"refundStatus"` //8 - 还未创建物流订单
SellerToken string `json:"sellerToken"` Main int `json:"main"`
Status int `json:"status"` ParentId int64 `json:"parentId"`
} `json:"result"` PayFee uint `json:"payFee"`
Success bool `json:"success"` PayOrderId int64 `json:"payOrderId"`
ErrMsg string `json:"errMsg"` PayStatus int `json:"payStatus"`
ErrCode string `json:"errCode"` //1 - 未冻结/未付款 -> 等待买家付款
//2 - 已冻结/已付款 -> 等待卖家发货
//4 - 已退款 -> 交易关闭
//6 - 已转交易 -> 交易成功
//7 - 没有创建外部交易
//8 - 交易被关闭
//9 - 不可付款
PostFee uint `json:"postFee"`
RefundStatus int `json:"refundStatus"`
SellerToken string `json:"sellerToken"`
Status int `json:"status"`
} `json:"detailOrderList"`
GmtCreate string `json:"gmtCreate"`
ItemInfo struct {
ItemId string `json:"itemId"`
Pic string `json:"pic"`
Price uint `json:"price"`
SkuId string `json:"skuId"`
SkuInfoList []struct {
Name string `json:"name"`
Value string `json:"value"`
} `json:"skuInfoList"`
Title string `json:"title"`
} `json:"itemInfo"`
LogisticsOrderId int64 `json:"logisticsOrderId"`
LogisticsStatus int `json:"logisticsStatus"`
//1 - 未发货 -> 等待卖家发货
//2 - 已发货 -> 等待买家确认收货
//3 - 已收货 -> 交易成功
//4 - 已经退货 -> 交易失败
//5 - 部分收货 -> 交易成功
//6 - 部分发货中
//8 - 还未创建物流订单
Main int `json:"main"`
ParentId string `json:"parentId"`
PayFee uint `json:"payFee"`
PayOrderId string `json:"payOrderId"`
PayStatus int `json:"payStatus"`
//1 - 未冻结/未付款 -> 等待买家付款
//2 - 已冻结/已付款 -> 等待卖家发货
//4 - 已退款 -> 交易关闭
//6 - 已转交易 -> 交易成功
//7 - 没有创建外部交易
//8 - 交易被关闭
//9 - 不可付款
PostFee uint `json:"postFee"`
RefundStatus int `json:"refundStatus"`
SellerToken string `json:"sellerToken"`
Status int `json:"status"`
} `json:"result"` } `json:"result"`
} }
//Reflect 详情[反查] //Reflect 详情[反查]
func (s orderItao) Reflect(ctx context.Context, req string) (res *OrderReflectRes, err error) { func (s order) Reflect(ctx context.Context, req string) (res *OrderReflectRes, err error) {
method := "com.alibaba.c2m/ltao.trade.queryOrderByOutId" method := "tt.order.detail.outid"
result, err := server.Post(ctx, method, g.Map{ result, err := server.Post(ctx, method, g.Map{
"request": g.Map{ "request": g.Map{
"outOrderId": req, "outOrderId": s.outId(req),
}, },
}) })
_ = gjson.NewWithOptions(result, gjson.Options{ _ = gjson.NewWithOptions(result, gjson.Options{
...@@ -380,18 +433,21 @@ func (s orderItao) Reflect(ctx context.Context, req string) (res *OrderReflectRe ...@@ -380,18 +433,21 @@ func (s orderItao) Reflect(ctx context.Context, req string) (res *OrderReflectRe
type OrderPayRes struct { type OrderPayRes struct {
Result struct { Result struct {
ErrCode string `json:"errCode"` Result struct {
ErrMsg string `json:"errMsg"` Result string `json:"result"`
Success bool `json:"success"` Success bool `json:"success"`
ErrCode string `json:"errCode"`
ErrMsg string `json:"errMsg"`
} `json:"result"`
} `json:"result"` } `json:"result"`
} }
func (s orderItao) Pay(ctx context.Context, req string) (res *OrderPayRes, err error) { func (s order) Pay(ctx context.Context, req string) (res *OrderPayRes, err error) {
method := "com.alibaba.c2m/ltao.pay.agreementPay" method := "tt.agreementpay.dopay"
result, err := server.Post(ctx, method, g.Map{ result, err := server.Post(ctx, method, g.Map{
"request": g.Map{ "request": g.Map{
"bizOrderId": req, "bizOrderId": gconv.Int64(req),
}, },
}) })
_ = gjson.NewWithOptions(result, gjson.Options{ _ = gjson.NewWithOptions(result, gjson.Options{
......
package itao
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type pay struct {
}
var Pay = pay{}
type PayAuthRes struct {
}
func (s pay) Auth(ctx context.Context) (res *PayAuthRes, err error) {
method := "tt.agreementpay.genersignurl"
result, err := server.Post(ctx, method, g.Map{
"request": g.Map{},
})
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
return
}
package itao
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type refund struct {
}
var Refund = refund{}
type RefundPic struct {
MessagePic string `json:"messagePic"`
}
type RefundBeforeRes struct {
CommonRes
Result struct {
BizClaimTypeVOList []struct {
BizClaimType string `json:"bizClaimType"` //refund 仅退款 return_and_refund 退货退款
RefundTypeTitle string `json:"refundTypeTitle"`
} `json:"bizClaimTypeVOList"`
} `json:"result"`
}
//Before 退款类型
func (s refund) Before(ctx context.Context, req string) (res *RefundBeforeRes, err error) {
method := "tt.refund.refundApplyType"
result, err := server.Post(ctx, method, g.Map{
"request": g.Map{
"bizOrderId": req,
},
})
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
return
}
type RefundReasonReq struct {
BizOrderId string `json:"bizOrderId"`
BizClaimType string `json:"bizClaimType"`
GoodsStatus string `json:"goodsStatus,omitempty"`
}
type RefundReasonRes struct {
CommonRes
Result struct {
MaxRefundFee int `json:"maxRefundFee"`
MinRefundFee int `json:"minRefundFee"`
MustProof bool `json:"mustProof"`
RefundTextWrapperVOList []struct {
Name string `json:"name"`
ReasonGroup int `json:"reasonGroup"`
TextId int `json:"textId"`
} `json:"refundTextWrapperVOList"`
} `json:"result"`
}
//Reason 原因
func (s refund) Reason(ctx context.Context, req RefundReasonReq) (res *RefundReasonRes, err error) {
method := "tt.refund.refundApplyInit"
result, err := server.Post(ctx, method, g.Map{
"request": req,
})
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
return
}
type RefundCreateReq struct {
BizOrderId string `json:"bizOrderId"` //子订单号
BizClaimType string `json:"bizClaimType"` //refund 仅退款 return_and_refund 退货退款
GoodsStatus string `json:"goodsStatus,omitempty"` //"1":未收到货 "2":未已收到货 未发货情况下,千万不要传
RefundFee string `json:"refundFee"` //退款金额,单位是分
ApplyRefundTextId string `json:"applyRefundTextId"` //原因ID
LeaveMessagePics []RefundPic `json:"leaveMessagePics,omitempty"`
}
type RefundCreateRess struct {
CommonRes
Result struct {
DisputeId string `json:"disputeId"`
} `json:"result"`
}
//Create 申请
func (s refund) Create(ctx context.Context, req RefundCreateReq, image ...string) (res *RefundCreateRess, err error) {
method := "tt.refund.refundSubmit"
if len(image) > 0 {
for _, item := range image {
req.LeaveMessagePics = append(req.LeaveMessagePics, RefundPic{MessagePic: item})
}
}
result, err := server.Post(ctx, method, g.Map{
"request": req,
})
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
return
}
//Cancle 取消售后
//`bizOrderId` 子订单号
//`disputeId` 售后单号
func (s refund) Cancel(ctx context.Context, bizOrderId, disputeId string) (res *CommonRes, err error) {
method := "tt.refund.refundRevoke"
result, err := server.Post(ctx, method, g.Map{
"request": g.Map{
"bizOrderId": bizOrderId,
"disputeId": disputeId,
},
})
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
return
}
type RefundSubmitReq struct {
DisputeId string `json:"disputeId"`
BizOrderId string `json:"bizOrderId"`
CompanyCode string `json:"logisticsCompanyCode"`
CompanyId string `json:"logisticsCompanyId"`
CompanyName string `json:"logisticsCompanyName"`
LogisticsNo string `json:"logisticsNo"`
MobileNum string `json:"mobileNum"`
LeaveMessagePics []RefundPic `json:"leaveMessagePics"`
}
type RefundSubmitRes struct {
CommonRes
Result struct {
DisputeStatus string `json:"disputeStatus"`
//REFUND_WAIT_SELLER_AGREE:"买家已经申请退款,等待卖家同意";
//REFUND_WAIT_BUYER_RETURN_GOODS:"卖家已经同意退款,等待买家退货";
//REFUND_WAIT_SELLER_CONFIRM_GOODS:"买家已经退货,等待卖家确认收货";
//REFUND_CLOSED:"退款关闭";
//REFUND_SUCCESS:"退款成功";
//REFUND_SELLER_REFUSE_BUYER:"卖家拒绝退款";
//REFUND_WAIT_BUYER_CONFIRM_REDO_SEND_GOODS:"等待买家确认重新邮寄的货物";
//REFUND_WAIT_SELLER_CONFIRM_RETURN_ADDRESS:"等待卖家确认退货地址"
} `json:"result"`
}
//Submit 提交物流信息
func (s refund) Submit(ctx context.Context, req RefundSubmitReq, image ...string) (res *CommonRes, err error) {
method := "tt.refund.submitLogisticInfo.v1"
if len(image) > 0 {
for _, item := range image {
req.LeaveMessagePics = append(req.LeaveMessagePics, RefundPic{MessagePic: item})
}
}
result, err := server.Post(ctx, method, g.Map{
"request": req,
})
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
return
}
type RefundDetailRes struct {
CommonRes
Result struct {
DisputeId int64 `json:"disputeId"` //退款编号
DisputeStatus string `json:"disputeStatus"`
//退款状态
//REFUND_WAIT_SELLER_AGREE:"买家已经申请退款,等待卖家同意";
//REFUND_WAIT_BUYER_RETURN_GOODS:"卖家已经同意退款,等待买家退货";
//REFUND_WAIT_SELLER_CONFIRM_GOODS:"买家已经退货,等待卖家确认收货";
//REFUND_CLOSED:"退款关闭";
//REFUND_SUCCESS:"退款成功";
//REFUND_SELLER_REFUSE_BUYER:"卖家拒绝退款";
//REFUND_WAIT_BUYER_CONFIRM_REDO_SEND_GOODS:"等待买家确认重新邮寄的货物";
//REFUND_WAIT_SELLER_CONFIRM_RETURN_ADDRESS:"等待卖家确认退货地址"
DisputeTimeOut struct {
Duration int `json:"duration"`
GmtCreate int64 `json:"gmtCreate"`
Running bool `json:"running"`
TimeoutActionType string `json:"timeoutActionType"`
} `json:"disputeTimeOut"`
ReasonName string `json:"reasonName"` //退款原因名称
RefundFee int `json:"refundFee"` //退款金额,单位分
ShippingAddressWrapperDTO struct {
AddressDetail string `json:"addressDetail"`
AreaName string `json:"areaName"`
CityName string `json:"cityName"`
ConsigneeFullName string `json:"consigneeFullName"`
DivisionCode string `json:"divisionCode"`
Mobile string `json:"mobile"`
PostCode string `json:"postCode"`
ProvinceName string `json:"provinceName"`
TownName string `json:"townName"`
} `json:"shippingAddressWrapperDTO"`
} `json:"result"`
}
//Detail 详情
func (s refund) Detail(ctx context.Context, bizOrderId, disputeId string) (res *RefundDetailRes, err error) {
method := "tt.refund.queryRefundDetail"
result, err := server.Post(ctx, method, g.Map{
"request": g.Map{
"bizOrderId": bizOrderId,
"disputeId": disputeId,
},
})
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
return
}
package itao
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/util/gconv"
"net/url"
"time"
)
type upload struct {
}
var Upload = upload{}
type UploadImageReq struct {
FileName string `json:"fileName"`
FileContent string `json:"fileContent"`
ImageData string `json:"imageData"`
}
type UploadImageRes struct {
Code string `json:"code"`
Message string `json:"message"`
FileUrl string `json:"fileUrl"`
}
func (s upload) Image(ctx context.Context, req UploadImageReq) (res *UploadImageRes, err error) {
method := "tt.upload.image"
if req.FileContent == "" {
req.FileContent = "base64"
}
var request = g.Map{}
request["access_token"], err = AccessToken(ctx)
if err != nil {
return
}
result, err := s.post(ctx, method, request, gconv.Map(req))
_ = gjson.New(result).Scan(&res)
return
}
func (upload) post(ctx context.Context, method string, params, req g.Map) (str string, err error) {
Start := gtime.TimestampMilli()
err = sign(method, params)
if err != nil {
return
}
Url := Host + method + "/" + server.AppKey
Values := url.Values{}
for k, v := range params {
Values.Add(k, gconv.String(v))
}
resp, err := g.Client().ContentJson().Timeout(time.Second*5).Post(Url+"?"+Values.Encode(), req)
defer func() {
_ = resp.Close()
paramStr := gjson.New(params).MustToJsonString()
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", Url)
if err != nil {
g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%vms】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】响应【%v】响应时间【%vms】", paramStr, str, gtime.TimestampMilli()-Start)
}
}()
str = resp.ReadAllString()
return
}
...@@ -46,10 +46,10 @@ func (c *Config) Post(ctx context.Context, api string, bodyMap g.Map) (result st ...@@ -46,10 +46,10 @@ func (c *Config) Post(ctx context.Context, api string, bodyMap g.Map) (result st
defer func() { defer func() {
ctx = context.WithValue(ctx, "URI", api) ctx = context.WithValue(ctx, "URI", api)
if err != nil { if err != nil {
g.Log().Ctx(ctx).Cat("error").Async(true). g.Log().Ctx(ctx).Cat(pkgName).Cat("error").
Infof("参数【%v】错误【%v】响应时间:【%v ms】", gjson.New(bodyMap).MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start) Infof("参数【%v】错误【%v】响应时间:【%v ms】", gjson.New(bodyMap).MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else { } else {
g.Log().Ctx(ctx).Cat(pkgName).Async(true). g.Log().Ctx(ctx).Cat(pkgName).
Infof("参数【%v】响应【%v】响应时间:【%v ms】", gjson.New(bodyMap).MustToJsonString(), result, gtime.TimestampMilli()-Start) Infof("参数【%v】响应【%v】响应时间:【%v ms】", gjson.New(bodyMap).MustToJsonString(), result, gtime.TimestampMilli()-Start)
} }
}() }()
......
...@@ -110,7 +110,7 @@ func post(ctx context.Context, method string, params map[string]string) (str str ...@@ -110,7 +110,7 @@ func post(ctx context.Context, method string, params map[string]string) (str str
ctx = context.WithValue(ctx, "Method", "POST") ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", apiUrl+params["Action"]) ctx = context.WithValue(ctx, "URI", apiUrl+params["Action"])
if err != nil { if err != nil {
g.Log().Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(PkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else { } else {
g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr, str, gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr, str, gtime.TimestampMilli()-Start)
} }
......
...@@ -95,7 +95,7 @@ func post(ctx context.Context, method string, req interface{}) (res string, err ...@@ -95,7 +95,7 @@ func post(ctx context.Context, method string, req interface{}) (res string, err
ctx = context.WithValue(ctx, "Method", "POST") ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", method) ctx = context.WithValue(ctx, "URI", method)
if err != nil { if err != nil {
g.Log().Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else { } else {
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr, res, gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr, res, gtime.TimestampMilli()-Start)
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论