提交 6a4135a2 authored 作者: zhanglibo's avatar zhanglibo

淘特

上级 2fa89b3f
...@@ -8,9 +8,10 @@ import ( ...@@ -8,9 +8,10 @@ import (
"github.com/gogf/gf/encoding/gjson" "github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/errors/gerror" "github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/frame/g" "github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gctx"
"github.com/gogf/gf/os/gtime" "github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/os/gtimer"
"github.com/gogf/gf/util/gconv" "github.com/gogf/gf/util/gconv"
"github.com/gogf/gf/util/gutil"
"net/url" "net/url"
"sort" "sort"
"strings" "strings"
...@@ -31,13 +32,17 @@ const Host = "https://open.huoju6.com/openapi/param2/1/com.huoju6.open/" ...@@ -31,13 +32,17 @@ const Host = "https://open.huoju6.com/openapi/param2/1/com.huoju6.open/"
func New(req *Config) { func New(req *Config) {
server = req server = req
gtimer.Add(time.Hour, func() {
var ctx = gctx.New()
_ = server.accessToken(ctx)
})
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 generate(req string) (res string) { func generate(req string) (res string) {
...@@ -73,7 +78,7 @@ func sign(method string, req g.Map) (err error) { ...@@ -73,7 +78,7 @@ func sign(method string, req g.Map) (err error) {
} }
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 = s.AccessToken(ctx) params["access_token"], err = s.GetAccessToken(ctx)
if err != nil { if err != nil {
return return
} }
...@@ -111,7 +116,7 @@ func Post(ctx context.Context, method string, params g.Map) (str string, err err ...@@ -111,7 +116,7 @@ func Post(ctx context.Context, method string, params g.Map) (str string, err err
} }
func (s *Config) Get(ctx context.Context, method string, params g.Map) (str string, err error) { func (s *Config) Get(ctx context.Context, method string, params g.Map) (str string, err error) {
params["access_token"], err = s.AccessToken(ctx) params["access_token"], err = s.GetAccessToken(ctx)
if err != nil { if err != nil {
return return
} }
...@@ -152,7 +157,7 @@ func Get(ctx context.Context, method string, params g.Map) (str string, err erro ...@@ -152,7 +157,7 @@ func Get(ctx context.Context, method string, params g.Map) (str string, err erro
} }
func (s *Config) AccessToken(ctx context.Context) (res string, err error) { func (s *Config) GetAccessToken(ctx context.Context) (res string, err error) {
var conn = g.Redis().Conn() var conn = g.Redis().Conn()
defer func() { defer func() {
_ = conn.Close() _ = conn.Close()
...@@ -163,28 +168,41 @@ func (s *Config) AccessToken(ctx context.Context) (res string, err error) { ...@@ -163,28 +168,41 @@ func (s *Config) AccessToken(ctx context.Context) (res string, err error) {
err = gerror.New("获取token 失败") err = gerror.New("获取token 失败")
return return
} }
var token *AuthTokenRes var result *AuthTokenRes
_ = gjson.New(cache).Scan(&token) _ = gjson.New(cache).Scan(&result)
if token == nil { if result == nil || result.AccessToken == "" || result.AccessTokenExpireTime < gtime.TimestampMilli() {
err = gerror.New("获取token 失败") err = gerror.New("获取token 失败")
return return
} }
if token.AccessTokenExpireTime < gtime.Now().TimestampMilli() { res = result.AccessToken
if token.RefreshTokenExpireTime < gtime.Now().TimestampMilli() { return
}
//accessToken 刷新
func (s *Config) accessToken(ctx context.Context) (err error) {
var conn = g.Redis().Conn()
defer func() {
_ = conn.Close()
}()
_, _ = conn.DoVar("SELECT", 10)
cache, _ := conn.DoVar("HGETALL", CacheKey)
if cache.IsEmpty() {
err = gerror.New("获取token 失败") err = gerror.New("获取token 失败")
return return
} }
token, err = Auth.Token(ctx, token.RefreshToken, 2) var result *AuthTokenRes
_ = gjson.New(cache).Scan(&result)
if result.AccessTokenExpireTime > gtime.Now().Add(time.Hour).TimestampMilli() {
return
}
result, err = Auth.Token(ctx, result.RefreshToken, 2)
if err != nil { if err != nil {
return return
} }
if token.Code != "success" { if result.Code != "success" {
err = gerror.New("获取token 失败") err = gerror.New("获取token 失败")
return return
} }
_, _ = conn.Do("HMSET", append(g.Slice{CacheKey}, gutil.StructToSlice(token)...)...) _, _ = conn.Do("HMSET", CacheKey, "accessToken", result.AccessToken, "accessTokenExpireTime", result.AccessTokenExpireTime)
}
res = token.AccessToken
return return
} }
...@@ -40,7 +40,7 @@ type AuthQrCodeRes struct { ...@@ -40,7 +40,7 @@ type AuthQrCodeRes struct {
func (s auth) QrCode(ctx context.Context) (res *AuthQrCodeRes, err error) { func (s auth) QrCode(ctx context.Context) (res *AuthQrCodeRes, err error) {
method := "tt.authority.generateQrCode" method := "tt.authority.generateQrCode"
result, err := server.Get(ctx, method, g.Map{ result, err := Get(ctx, method, g.Map{
"bId": server.AppKey, "bId": server.AppKey,
}) })
_ = gjson.New(result).Scan(&res) _ = gjson.New(result).Scan(&res)
...@@ -75,7 +75,7 @@ func (s auth) Token(ctx context.Context, code string, Type int) (res *AuthTokenR ...@@ -75,7 +75,7 @@ func (s auth) Token(ctx context.Context, code string, Type int) (res *AuthTokenR
request["grantType"] = "refreshToken" request["grantType"] = "refreshToken"
} }
result, err := server.Get(ctx, method, request) result, err := Get(ctx, method, request)
_ = gjson.New(result).Scan(&res) _ = gjson.New(result).Scan(&res)
return return
} }
......
...@@ -17,8 +17,8 @@ type GoodsListReq struct { ...@@ -17,8 +17,8 @@ type GoodsListReq struct {
Sort string `json:"sort,omitempty"` //排序参数 价格降序:sort=price:des 价格升序:sort=price:asc 综合排序:sort=popular:des 销量降序:sort=sales:des Sort string `json:"sort,omitempty"` //排序参数 价格降序:sort=price:des 价格升序:sort=price:asc 综合排序:sort=popular:des 销量降序:sort=sales:des
Price string `json:"price,omitempty"` Price string `json:"price,omitempty"`
Cate string `json:"cate,omitempty"` Cate string `json:"cate,omitempty"`
S int `json:"s,omitempty"` S int `json:"s"`
N int `json:"n,omitempty"` N int `json:"n"`
Feature string `json:"feature,omitempty"` Feature string `json:"feature,omitempty"`
} }
......
...@@ -6,10 +6,10 @@ import ( ...@@ -6,10 +6,10 @@ 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 { Result struct {
...@@ -45,7 +45,7 @@ type LogisticsTraceRes struct { ...@@ -45,7 +45,7 @@ type LogisticsTraceRes struct {
} }
//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 := "tt.logistics.detail" method := "tt.logistics.detail"
result, err := server.Post(ctx, method, g.Map{ result, err := server.Post(ctx, method, g.Map{
...@@ -56,3 +56,16 @@ func (logisticsItao) Trace(ctx context.Context, req string) (res *LogisticsTrace ...@@ -56,3 +56,16 @@ func (logisticsItao) Trace(ctx context.Context, req string) (res *LogisticsTrace
_ = gjson.New(result).Scan(&res) _ = gjson.New(result).Scan(&res)
return return
} }
//Company 物流公司
func (logistics) Company(ctx context.Context, req string) (res *LogisticsTraceRes, err error) {
method := "tt.refund.queryLogisticList"
result, err := server.Post(ctx, method, g.Map{
"request": g.Map{
"bizOrderId": req,
},
})
_ = gjson.New(result).Scan(&res)
return
}
...@@ -42,7 +42,10 @@ type OrderItem struct { ...@@ -42,7 +42,10 @@ type OrderItem struct {
} }
type OrderBeforeRes struct { type OrderBeforeRes struct {
Result struct { ErrMsg string `json:"errMsg"`
ErrCode string `json:"errCode"`
Success bool `json:"success"`
GwTraceId string `json:"gw_trace_id"`
Result struct { Result struct {
ExtensionResp struct { ExtensionResp struct {
TradeId string `json:"tradeId"` TradeId string `json:"tradeId"`
...@@ -92,23 +95,27 @@ type OrderBeforeRes struct { ...@@ -92,23 +95,27 @@ type OrderBeforeRes struct {
ErrorMsg string `json:"errorMsg"` ErrorMsg string `json:"errorMsg"`
} }
ItemInfo struct { ItemInfo struct {
ItemId string `json:"itemId"` ItemId int64 `json:"itemId"`
SkuId string `json:"skuId"` 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"` } `json:"itemInfo"`
ItemPayPrice uint `json:"itemPayPrice"` ItemPayPrice uint `json:"itemPayPrice"`
OrderLineId int64 `json:"orderLineId"` OrderLineId int `json:"orderLineId"`
Quantity uint `json:"quantity"` Quantity uint `json:"quantity"`
} `json:"orderLineRenders"` } `json:"orderLineRenders"`
OrderPayPrice uint `json:"orderPayPrice"` OrderPayPrice int `json:"orderPayPrice"`
Quantity uint `json:"quantity"` PostFee int `json:"postFee"`
Quantity int `json:"quantity"`
SellerToken string `json:"sellerToken"` SellerToken string `json:"sellerToken"`
Title string `json:"title"` Title string `json:"title"`
} `json:"validOrderGroups"` } `json:"validOrderGroups"`
} `json:"result"` } `json:"result"`
Success bool `json:"success"`
ErrMsg string `json:"errMsg"`
ErrCode string `json:"errCode"`
} `json:"result"`
} }
type OrderPromotion struct { type OrderPromotion struct {
...@@ -433,15 +440,5 @@ type OrderPayRes struct { ...@@ -433,15 +440,5 @@ type OrderPayRes struct {
} }
func (s orderItao) Pay(ctx context.Context, req string) (res *OrderPayRes, err error) { func (s orderItao) Pay(ctx context.Context, req string) (res *OrderPayRes, err error) {
method := "com.alibaba.c2m/ltao.pay.agreementPay"
result, err := server.Post(ctx, method, g.Map{
"request": g.Map{
"bizOrderId": req,
},
})
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
return return
} }
package itao package itao
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type refund struct { type refund struct {
} }
var Refund = refund{} var Refund = refund{}
type RefundPic struct {
MessagePic string `json:"messagePic"`
}
type RefundBeforeRes struct {
Success bool `json:"success"`
ErrMsg string `json:"errMsg"`
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"`
}
type RefundReasonRes struct {
Success bool `json:"success"`
ErrMsg string `json:"errMsg"`
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"`
}
//Create 申请
func (s refund) Create(ctx context.Context, req RefundCreateReq, image ...string) (res *RefundBeforeRes, 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": g.Map{
"bizOrderId": req,
},
})
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
return
}
//Cancle 取消售后
//`bizOrderId` 子订单号
//`disputeId` 售后单号
func (s refund) Cancle(ctx context.Context, bizOrderId, disputeId string) (res *CommonRes, err error) {
method := "tt.refund.refundSubmit"
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 {
Success bool `json:"success"`
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.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
}
type RefundDetailRes struct {
Success bool `json:"success"`
ErrMsg string `json:"errMsg"`
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
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论