提交 c15ac41b authored 作者: zhanglibo's avatar zhanglibo

Merge branch 'ali'

...@@ -3,6 +3,7 @@ module gitlab.jxhh.com/stbz/library.git ...@@ -3,6 +3,7 @@ module gitlab.jxhh.com/stbz/library.git
go 1.16 go 1.16
require ( require (
github.com/aliyun/aliyun-log-go-sdk v0.1.27
github.com/gogf/gf v1.16.6 github.com/gogf/gf v1.16.6
github.com/kjk/betterguid v0.0.0-20170621091430-c442874ba63a github.com/kjk/betterguid v0.0.0-20170621091430-c442874ba63a
github.com/nsqio/go-nsq v1.1.0 github.com/nsqio/go-nsq v1.1.0
......
package ali
import (
"context"
"crypto/hmac"
"crypto/sha1"
"encoding/hex"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/util/gconv"
"gitlab.jxhh.com/stbz/library.git/logs"
"sort"
"strings"
"time"
)
type Config struct {
Wsurl string
ApiUrl string
AppKey string
AppSecret string
AccessToken string
}
type CommonRes struct {
Success bool `json:"success"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
var server *Config
const pkgName = "ali"
const WebSite = "1688"
func New(config *Config) {
server = config
return
}
func (s *Config) CreateSign(signStr string) (sign string) {
//拼接参数
appSecret := []byte(s.AppSecret)
mac := hmac.New(sha1.New, appSecret)
mac.Write([]byte(signStr))
mdStr := hex.EncodeToString(mac.Sum(nil))
sign = strings.ToUpper(mdStr)
return
}
func (s *Config) sign(method string, param g.Map) g.Map {
var keys []string
mewparam := param
for k := range mewparam {
keys = append(keys, k)
}
sort.Strings(keys)
var signStr string
for _, v := range keys {
if v != "_aop_signature" {
signStr += v
signStr += gconv.String(mewparam[v])
}
}
//拼接参数
signStr = "param2/1/" + method + "/" + s.AppKey + signStr
param["_aop_signature"] = s.CreateSign(signStr)
return param
}
func (s *Config) Post(ctx context.Context, method string, params g.Map) (str string, err error) {
Start := gtime.TimestampMilli()
allparams := s.sign(method, params)
Url := s.ApiUrl + method + "/" + s.AppKey
Request := g.Client()
Request.SetHeader("Content-Type", "application/x-www-form-urlencoded")
resp, err := Request.Timeout(time.Second*5).Post(Url, allparams)
defer func() {
_ = resp.Body.Close()
paramStr := gjson.New(params).MustToJsonString()
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", Url)
if err != nil {
logs.Errorf(ctx, pkgName, logs.FormatErr, paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else {
logs.Infof(ctx, pkgName, logs.FormatSuc, paramStr, str, gtime.TimestampMilli()-Start)
}
}()
str = resp.ReadAllString()
return
}
package ali
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type addressAli struct {
}
var Address = addressAli{}
type AddressParseRes struct {
Result struct {
Address string `json:"address"`
AddressCode string `json:"addressCode"`
IsDefault bool `json:"isDefault"`
Latest bool `json:"latest"`
PostCode string `json:"postCode"`
} `json:"result"`
}
type AddressGetRes struct {
Result struct {
Code string `json:"code"`
Name string `json:"name"`
ParentCode string `json:"parentCode"`
Post string `json:"post"`
Children []string `json:"children"`
} `json:"result"`
}
type AddressGetChildRes struct {
Result []struct {
Code string `json:"code"`
Name string `json:"name"`
ParentCode string `json:"parentCode"`
} `json:"result"`
}
//Parse 根据地址解析地区码
func (s *addressAli) Parse(ctx context.Context, req string) (res *AddressParseRes, err error) {
method := "com.alibaba.trade/alibaba.trade.addresscode.parse"
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
"addressInfo": req,
})
_ = gjson.New(result).Scan(&res)
return
}
//Get 获取交易地址代码表详情
func (s *addressAli) Get(ctx context.Context, Code string) (res *AddressGetRes, err error) {
method := "com.alibaba.trade/alibaba.trade.addresscode.get"
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
"areaCode": Code,
"webSite": WebSite,
})
_ = gjson.New(result).Scan(&res)
return
}
//GetChild 获取交易地址的下一级信息
func (s *addressAli) GetChild(ctx context.Context, Code string) (res *AddressGetChildRes, err error) {
method := "com.alibaba.trade/alibaba.trade.addresscode.getchild"
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
"areaCode": Code,
"webSite": WebSite,
})
_ = gjson.New(result).Scan(&res)
return
}
package ali
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/util/gconv"
)
type goodsAli struct {
}
var Goods = goodsAli{}
type GoodsListReq struct {
Biztype string `json:"biztype"` //经营模式 【1:生产加工,2:经销批发,3:招商代理,4:商业服务】
BuyerProtection string `json:"buyerProtection"` //买家保障,多个值用逗号分割;【qtbh:7天包换;swtbh:15天包换】
City string `json:"city"` //所在地区- 市 示例:杭州
DeliveryTimeType string `json:"deliveryTimeType"` //发货时间;【1:24小时发货;2:48小时发货;3:72小时发货】
DescendOrder bool `json:"descendOrder"` //是否倒序;【正序: false;倒序:true】
HolidayTagId string `json:"holidayTagId"` //商品售卖类型筛选;枚举,多个值用分号分割;免费赊账:50000114
KeyWords string `json:"keyWords"` //搜索关键词
Page int `json:"page"` //页码
PageSize int `json:"pageSize"` //页面数量;最大20
AccessToken string `json:"access_token"`
}
type GoodsListRes struct {
Result struct {
*CommonRes
TotalCount int `json:"totalCount"` //总数
Result []struct {
Title string `json:"title"` //商品标题
ImgURL string `json:"imgUrl"` //商品首图
OfferID int64 `json:"offerId"` //商品id
SoldOut int `json:"soldOut"` //销量
Enable bool `json:"enable"` //是否有效
Profit string `json:"profit"` //利润空间; - :表示无 示例 300%-500%
CurrentPrice float64 `json:"currentPrice"` //分销价
OfferTags []string `json:"offerTags"` //标签数组
} `json:"result"`
} `json:"result"`
}
type GoodsInfoReq struct {
GoodsID int64 `json:"offerId"` //1688商品ID,等同于productId
NeedCpsSuggestPrice bool `json:"needCpsSuggestPrice"` //是否需要CPS建议价
NeedIntelligentInfo bool `json:"needIntelligentInfo"` //是否返回算法改写的信息,包括标题、图片和详情图片
AccessToken string `json:"access_token"`
}
type GoodsInfoRes struct {
*CommonRes
BizGroupInfos []struct {
Support bool `json:"support"`
Description string `json:"description"`
Code string `json:"code"`
} `json:"bizGroupInfos"`
ProductInfo struct {
ProductID int64 `json:"productID"`
CategoryID int `json:"categoryID"`
Subject string `json:"subject"`
Description string `json:"description"`
PictureAuth bool `json:"pictureAuth"`
Image struct {
Images []string `json:"images"`
} `json:"image"`
SkuInfos []struct {
Attributes []struct {
AttributeID int `json:"attributeID"`
AttributeValue string `json:"attributeValue"`
SkuImageURL string `json:"skuImageUrl"`
AttributeName string `json:"attributeName"`
} `json:"attributes"`
CargoNumber string `json:"cargoNumber"`
AmountOnSale int `json:"amountOnSale"`
Price float64 `json:"price"`
SkuID int64 `json:"skuId"`
SpecID string `json:"specId"`
ConsignPrice float64 `json:"consignPrice"`
ChannelPrice float64 `json:"channelPrice"`
} `json:"skuInfos"`
SaleInfo struct {
SupportOnlineTrade bool `json:"supportOnlineTrade"`
MixWholeSale bool `json:"mixWholeSale"`
PriceAuth bool `json:"priceAuth"`
PriceRanges []struct {
StartQuantity int `json:"startQuantity"`
Price float64 `json:"price"`
} `json:"priceRanges"`
AmountOnSale float64 `json:"amountOnSale"`
Unit string `json:"unit"`
MinOrderQuantity int `json:"minOrderQuantity"`
QuoteType int `json:"quoteType"`
} `json:"saleInfo"`
ShippingInfo struct {
FreightTemplateID int `json:"freightTemplateID"`
UnitWeight float64 `json:"unitWeight"`
SendGoodsAddressID int `json:"sendGoodsAddressId"`
SendGoodsAddressText string `json:"sendGoodsAddressText"`
FreightTemplate []struct {
AddressCodeText string `json:"addressCodeText"`
FromAreaCode string `json:"fromAreaCode"`
ID int `json:"id"`
ExpressSubTemplate struct {
SubTemplateDTO struct {
ChargeType int `json:"chargeType"`
IsSysTemplate bool `json:"isSysTemplate"`
ServiceType int `json:"serviceType"`
Type int `json:"type"`
} `json:"subTemplateDTO"`
RateList []struct {
IsSysRate bool `json:"isSysRate"`
ToAreaCodeText string `json:"toAreaCodeText"`
RateDTO struct {
FirstUnit int `json:"firstUnit"`
FirstUnitFee int `json:"firstUnitFee"`
NextUnit int `json:"nextUnit"`
NextUnitFee int `json:"nextUnitFee"`
} `json:"rateDTO"`
} `json:"rateList"`
} `json:"expressSubTemplate"`
LogisticsSubTemplate struct {
SubTemplateDTO struct {
ChargeType int `json:"chargeType"`
IsSysTemplate bool `json:"isSysTemplate"`
ServiceType int `json:"serviceType"`
Type int `json:"type"`
} `json:"subTemplateDTO"`
} `json:"logisticsSubTemplate"`
} `json:"freightTemplate"`
ChannelPriceFreePostage bool `json:"channelPriceFreePostage"`
ChannelPriceExcludeAreaCodes []struct {
Code string `json:"code"`
Name string `json:"name"`
} `json:"channelPriceExcludeAreaCodes"`
} `json:"shippingInfo"`
QualityLevel int `json:"qualityLevel"`
SupplierLoginID string `json:"supplierLoginId"`
CategoryName string `json:"categoryName"`
ReferencePrice string `json:"referencePrice"`
Attributes []struct {
AttributeID int `json:"attributeID"`
AttributeName string `json:"attributeName"`
Value string `json:"value"`
IsCustom bool `json:"isCustom"`
} `json:"attributes"`
Status string `json:"status"`
} `json:"productInfo"`
}
type GoodsFollowRes struct {
Code int `json:"code"`
Message int `json:"message"`
}
type GoodsGroupReq struct {
PageNo int64 `json:"pageNo"`
PageSize int64 `json:"pageSize"`
AccessToken string `json:"access_token"`
}
type GoodsGroupRes struct {
Result struct {
Result []struct {
CreateTime string `json:"createTime"`
FeedCount int `json:"feedCount"`
ID int `json:"id"`
Title string `json:"title"`
} `json:"result"`
*CommonRes
} `json:"result"`
}
type GoodsCategoryReq struct {
CategoryID int64 `json:"categoryID"`
AccessToken string `json:"access_token"`
}
type GoodsCategoryRes struct {
*CommonRes
CategoryInfo []struct {
CategoryID int `json:"categoryID"`
Name string `json:"name"`
IsLeaf bool `json:"isLeaf"`
ParentIDs []int `json:"parentIDs"`
MinOrderQuantity int `json:"minOrderQuantity"`
FeatureInfos []struct {
Key string `json:"key"`
Value string `json:"value"`
Status int `json:"status"`
Hierarchy bool `json:"hierarchy"`
} `json:"featureInfos"`
CategoryType string `json:"categoryType"`
IsSupportProcessing bool `json:"isSupportProcessing"`
} `json:"categoryInfo"`
}
//List 查询商品列表
func (goodsAli) List(ctx context.Context, req *GoodsListReq) (res *GoodsListRes, err error) {
method := "com.alibaba.p4p/alibaba.cps.op.searchCybOffers"
req.AccessToken = server.AccessToken
result, err := server.Post(ctx, method, gconv.Map(req))
_ = gjson.New(result).Scan(&res)
return
}
func (goodsAli) Info(ctx context.Context, req *GoodsInfoReq) (res *GoodsInfoRes, err error) {
method := "com.alibaba.product/alibaba.cpsMedia.productInfo"
req.AccessToken = server.AccessToken
result, err := server.Post(ctx, method, gconv.Map(req))
_ = gjson.New(result).Scan(&res)
return
}
//Follow 关注商品
func (goodsAli) Follow(ctx context.Context, GoodsID string) (res *GoodsFollowRes, err error) {
method := "com.alibaba.product/alibaba.product.follow"
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
"productId": GoodsID,
})
_ = gjson.New(result).Scan(&res)
return
}
//UnFollow 解除关注商品
func (goodsAli) UnFollow(ctx context.Context, GoodsID string) (res *GoodsFollowRes, err error) {
method := "com.alibaba.product/alibaba.product.unfollow.crossborder"
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
"productId": GoodsID,
})
_ = gjson.New(result).Scan(&res)
return
}
//Group 获取我的选品库列表
func (goodsAli) Group(ctx context.Context, req *GoodsGroupReq) (res *GoodsGroupRes, err error) {
method := "com.alibaba.p4p/alibaba.cps.op.listCybUserGroup"
req.AccessToken = server.AccessToken
result, err := server.Post(ctx, method, gconv.Map(req))
_ = gjson.New(result).Scan(&res)
return
}
func (goodsAli) Category(ctx context.Context, CategoryID interface{}) (res *GoodsCategoryRes, err error) {
method := "com.alibaba.product/alibaba.category.get"
var req = &GoodsCategoryReq{
CategoryID: gconv.Int64(CategoryID),
AccessToken: server.AccessToken,
}
result, err := server.Post(ctx, method, gconv.Map(req))
_ = gjson.New(result).Scan(&res)
return
}
差异被折叠。
差异被折叠。
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"github.com/gogf/gf/os/gtime" "github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/util/gconv" "github.com/gogf/gf/util/gconv"
"gitlab.jxhh.com/stbz/library.git/logs" "gitlab.jxhh.com/stbz/library.git/logs"
"net/url"
"strings" "strings"
"time" "time"
) )
...@@ -50,16 +49,11 @@ func New(config *Config) { ...@@ -50,16 +49,11 @@ func New(config *Config) {
} }
//post 请求 //post 请求
func (s *client) post(ctx context.Context, method string, params g.MapStrStr) (str string, err error) { func (s *client) post(ctx context.Context, method string, params g.Map) (str string, err error) {
Start := gtime.TimestampMilli() Start := gtime.TimestampMilli()
postValues := url.Values{}
for k, v := range params {
postValues.Add(k, v)
}
postString := postValues.Encode()
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(method, postString) resp, err := Request.Timeout(time.Second*5).Post(method, params)
defer func() { defer func() {
_ = resp.Body.Close() _ = resp.Body.Close()
paramStr := gjson.New(params).MustToJsonString() paramStr := gjson.New(params).MustToJsonString()
...@@ -85,7 +79,7 @@ func (s *client) getSign(timeStamp string) string { ...@@ -85,7 +79,7 @@ func (s *client) getSign(timeStamp string) string {
} }
// requestApi 请求 // requestApi 请求
func (s *client) requestApi(ctx context.Context, method string, businessParams g.MapStrStr) (str string, err error) { func (s *client) requestApi(ctx context.Context, method string, businessParams g.Map) (str string, err error) {
params, err := s.createPostRequest(ctx, businessParams) params, err := s.createPostRequest(ctx, businessParams)
if err != nil { if err != nil {
return return
...@@ -95,12 +89,12 @@ func (s *client) requestApi(ctx context.Context, method string, businessParams g ...@@ -95,12 +89,12 @@ func (s *client) requestApi(ctx context.Context, method string, businessParams g
return return
} }
func (s *client) createPostRequest(ctx context.Context, businessParams g.MapStrStr) (res g.MapStrStr, err error) { func (s *client) createPostRequest(ctx context.Context, businessParams g.Map) (res g.Map, err error) {
err = s.getAccessToken(ctx) err = s.getAccessToken(ctx)
if err != nil { if err != nil {
return return
} }
res = g.MapStrStr{ res = g.Map{
"token": s.AccessToken, "token": s.AccessToken,
} }
if businessParams != nil { if businessParams != nil {
......
...@@ -3,6 +3,7 @@ package jingdong ...@@ -3,6 +3,7 @@ package jingdong
import ( 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/util/gconv" "github.com/gogf/gf/util/gconv"
) )
...@@ -35,7 +36,7 @@ type GetTownRes struct { ...@@ -35,7 +36,7 @@ type GetTownRes struct {
//Parse 地址详情转换京东地址编码 //Parse 地址详情转换京东地址编码
func (addressJD) Parse(ctx context.Context, address string) (res *ParseRes, err error) { func (addressJD) Parse(ctx context.Context, address string) (res *ParseRes, err error) {
method := "area/getJDAddressFromAddress" method := "area/getJDAddressFromAddress"
param := map[string]string{ param := g.Map{
"address": address, "address": address,
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
...@@ -50,7 +51,7 @@ func (addressJD) Parse(ctx context.Context, address string) (res *ParseRes, err ...@@ -50,7 +51,7 @@ func (addressJD) Parse(ctx context.Context, address string) (res *ParseRes, err
// CheckArea 验证地址有效性 // CheckArea 验证地址有效性
func (addressJD) CheckArea(ctx context.Context, provinceId, cityId, countyId, townId interface{}) (res *CommonRes, err error) { func (addressJD) CheckArea(ctx context.Context, provinceId, cityId, countyId, townId interface{}) (res *CommonRes, err error) {
method := "area/checkArea" method := "area/checkArea"
param := map[string]string{ param := g.Map{
"provinceId": gconv.String(provinceId), "provinceId": gconv.String(provinceId),
"cityId": gconv.String(cityId), "cityId": gconv.String(cityId),
"countyId": gconv.String(countyId), "countyId": gconv.String(countyId),
...@@ -68,7 +69,7 @@ func (addressJD) CheckArea(ctx context.Context, provinceId, cityId, countyId, to ...@@ -68,7 +69,7 @@ func (addressJD) CheckArea(ctx context.Context, provinceId, cityId, countyId, to
// GetTown 查询四级地址 // GetTown 查询四级地址
func (addressJD) GetTown(ctx context.Context, id interface{}) (res *GetTownRes, err error) { func (addressJD) GetTown(ctx context.Context, id interface{}) (res *GetTownRes, err error) {
method := "area/getTown" method := "area/getTown"
param := map[string]string{ param := g.Map{
"id": gconv.String(id), "id": gconv.String(id),
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
......
...@@ -2,6 +2,7 @@ package jingdong ...@@ -2,6 +2,7 @@ package jingdong
import ( import (
"context" "context"
"encoding/json"
"github.com/gogf/gf/container/garray" "github.com/gogf/gf/container/garray"
"github.com/gogf/gf/encoding/gjson" "github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g" "github.com/gogf/gf/frame/g"
...@@ -31,6 +32,10 @@ type CheckOnSaleRes struct { ...@@ -31,6 +32,10 @@ type CheckOnSaleRes struct {
State int `json:"state"` //1:上架,0:下架 State int `json:"state"` //1:上架,0:下架
} `json:"result"` } `json:"result"`
} }
type GetStockMidRes struct {
*CommonRes
Result string `json:"result"`
}
type GetStockRes struct { type GetStockRes struct {
*CommonRes *CommonRes
...@@ -48,6 +53,11 @@ type GetStockRes struct { ...@@ -48,6 +53,11 @@ type GetStockRes struct {
} `json:"result"` } `json:"result"`
} }
type CheckAreaMidRes struct {
*CommonRes
Result string `json:"result"`
}
type CheckAreaLimitRes struct { type CheckAreaLimitRes struct {
*CommonRes *CommonRes
Result []struct { Result []struct {
...@@ -102,6 +112,7 @@ type GetCategoryRes struct { ...@@ -102,6 +112,7 @@ type GetCategoryRes struct {
} `json:"categorys"` } `json:"categorys"`
} `json:"result"` } `json:"result"`
} }
type GetSkuImageRes struct { type GetSkuImageRes struct {
*CommonRes //异常代码(0010:返回数据为空;1001:参数为空;1003:参数值不正确/sku数量过多,目前最大支持100个商品) *CommonRes //异常代码(0010:返回数据为空;1001:参数为空;1003:参数值不正确/sku数量过多,目前最大支持100个商品)
Result map[string][]struct { Result map[string][]struct {
...@@ -110,6 +121,7 @@ type GetSkuImageRes struct { ...@@ -110,6 +121,7 @@ type GetSkuImageRes struct {
Path string `json:"path"` //图片路径 Path string `json:"path"` //图片路径
} `json:"result"` } `json:"result"`
} }
type GetSimilarSkuRes struct { type GetSimilarSkuRes struct {
*CommonRes *CommonRes
Result []struct { Result []struct {
...@@ -128,7 +140,7 @@ type GetSimilarSkuRes struct { ...@@ -128,7 +140,7 @@ type GetSimilarSkuRes struct {
// CheckSale 商品可售验证接口 // CheckSale 商品可售验证接口
func (goodsJD) CheckSale(ctx context.Context, req *garray.Array) (res *CheckSaleRes, err error) { func (goodsJD) CheckSale(ctx context.Context, req *garray.Array) (res *CheckSaleRes, err error) {
method := "product/check" method := "product/check"
param := map[string]string{ param := g.Map{
"skuIds": req.Join(","), "skuIds": req.Join(","),
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
...@@ -143,7 +155,7 @@ func (goodsJD) CheckSale(ctx context.Context, req *garray.Array) (res *CheckSale ...@@ -143,7 +155,7 @@ func (goodsJD) CheckSale(ctx context.Context, req *garray.Array) (res *CheckSale
// CheckOnSale 查询商品上下架状态 // CheckOnSale 查询商品上下架状态
func (goodsJD) CheckOnSale(ctx context.Context, req *garray.Array) (res *CheckOnSaleRes, err error) { func (goodsJD) CheckOnSale(ctx context.Context, req *garray.Array) (res *CheckOnSaleRes, err error) {
method := "product/skuState" method := "product/skuState"
param := map[string]string{ param := g.Map{
"sku": req.Join(","), "sku": req.Join(","),
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
...@@ -155,24 +167,34 @@ func (goodsJD) CheckOnSale(ctx context.Context, req *garray.Array) (res *CheckOn ...@@ -155,24 +167,34 @@ func (goodsJD) CheckOnSale(ctx context.Context, req *garray.Array) (res *CheckOn
} }
//GetStock 查询商品库存 //GetStock 查询商品库存
func (goodsJD) GetStock(ctx context.Context, req *garray.Array, area string) (res *GetStockRes, err error) { func (goodsJD) GetStock(ctx context.Context, req []*SkuNums, area string) (res *GetStockRes, err error) {
method := "stock/getNewStockById" method := "stock/getNewStockById"
param := map[string]string{ param := g.Map{
"skuNums": req.Join(","), "skuNums": gjson.New(req).MustToJsonString(),
"area": area, "area": area,
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
if err != nil { if err != nil {
return return
} }
err = gjson.New(result).Scan(&res) var middle *GetStockMidRes
err = gjson.New(result).Scan(&middle)
if err != nil {
return
}
err = gjson.New(middle.CommonRes).Scan(&res)
if err != nil {
return
}
err = gjson.New(middle.Result).Scan(&res.Result)
return return
} }
// CheckAreaLimit 查询商品区域购买限制 // CheckAreaLimit 查询商品区域购买限制
func (goodsJD) CheckAreaLimit(ctx context.Context, skuIds *garray.Array, provinceID, cityID, countyID, townID interface{}) (res *CheckAreaLimitRes, err error) { func (goodsJD) CheckAreaLimit(ctx context.Context, skuIds *garray.Array, provinceID, cityID, countyID, townID interface{}) (res *CheckAreaLimitRes, err error) {
method := "product/checkAreaLimit" method := "product/checkAreaLimit"
param := map[string]string{ param := g.Map{
"skuIds": skuIds.Join(","), "skuIds": skuIds.Join(","),
"province": gconv.String(provinceID), "province": gconv.String(provinceID),
"city": gconv.String(cityID), "city": gconv.String(cityID),
...@@ -183,15 +205,23 @@ func (goodsJD) CheckAreaLimit(ctx context.Context, skuIds *garray.Array, provinc ...@@ -183,15 +205,23 @@ func (goodsJD) CheckAreaLimit(ctx context.Context, skuIds *garray.Array, provinc
if err != nil { if err != nil {
return return
} }
var middle *CheckAreaMidRes
err = gjson.New(result).Scan(&res) err = gjson.New(result).Scan(&middle)
if err != nil {
return
}
err = gjson.New(middle.CommonRes).Scan(&res)
if err != nil {
return
}
err = gjson.New(middle.Result).Scan(&res.Result)
return return
} }
//GetProductsPrice 查询商品价格 //GetProductsPrice 查询商品价格
func (goodsJD) GetProductsPrice(ctx context.Context, skus *garray.Array) (res *GetProductsPriceRes, err error) { func (goodsJD) GetProductsPrice(ctx context.Context, skus *garray.Array) (res *GetProductsPriceRes, err error) {
method := "price/getSellPrice" method := "price/getSellPrice"
param := map[string]string{ param := g.Map{
"sku": skus.Join(","), "sku": skus.Join(","),
"queryExts": "marketPrice", "queryExts": "marketPrice",
} }
...@@ -206,7 +236,7 @@ func (goodsJD) GetProductsPrice(ctx context.Context, skus *garray.Array) (res *G ...@@ -206,7 +236,7 @@ func (goodsJD) GetProductsPrice(ctx context.Context, skus *garray.Array) (res *G
//GetDetail 查询商品详情 //GetDetail 查询商品详情
func (goodsJD) GetDetail(ctx context.Context, skus *garray.Array) (res *GetDetailRes, err error) { func (goodsJD) GetDetail(ctx context.Context, skus *garray.Array) (res *GetDetailRes, err error) {
method := "product/getDetail" method := "product/getDetail"
param := map[string]string{ param := g.Map{
"sku": skus.Join(","), "sku": skus.Join(","),
"queryExts": "spuId,pName,isFactoryShip,isSelf,LowestBuy,wxintroduction", "queryExts": "spuId,pName,isFactoryShip,isSelf,LowestBuy,wxintroduction",
} }
...@@ -221,7 +251,7 @@ func (goodsJD) GetDetail(ctx context.Context, skus *garray.Array) (res *GetDetai ...@@ -221,7 +251,7 @@ func (goodsJD) GetDetail(ctx context.Context, skus *garray.Array) (res *GetDetai
//GetCategory 查询分类列表 //GetCategory 查询分类列表
func (goodsJD) GetCategory(ctx context.Context, pageNo, pageSize interface{}) (res *GetCategoryRes, err error) { func (goodsJD) GetCategory(ctx context.Context, pageNo, pageSize interface{}) (res *GetCategoryRes, err error) {
method := "product/getCategorys" method := "product/getCategorys"
param := g.MapStrStr{ param := g.Map{
"pageNo": gconv.String(pageNo), "pageNo": gconv.String(pageNo),
"pageSize": gconv.String(pageSize), "pageSize": gconv.String(pageSize),
} }
...@@ -236,22 +266,22 @@ func (goodsJD) GetCategory(ctx context.Context, pageNo, pageSize interface{}) (r ...@@ -236,22 +266,22 @@ func (goodsJD) GetCategory(ctx context.Context, pageNo, pageSize interface{}) (r
//GetSkuImage 查询商品图片 //GetSkuImage 查询商品图片
func (goodsJD) GetSkuImage(ctx context.Context, skus *garray.Array) (res *GetSkuImageRes, err error) { func (goodsJD) GetSkuImage(ctx context.Context, skus *garray.Array) (res *GetSkuImageRes, err error) {
method := "product/skuImage" method := "product/skuImage"
param := map[string]string{ param := g.Map{
"sku": skus.Join(","), "sku": skus.Join(","),
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
if err != nil { if err != nil {
return return
} }
err = gjson.New(result).Scan(&res) err = json.Unmarshal([]byte(result), &res)
return return
} }
//GetSimilarSku 查询同类商品 //GetSimilarSku 查询同类商品
func (goodsJD) GetSimilarSku(ctx context.Context, skus *garray.Array) (res *GetSimilarSkuRes, err error) { func (goodsJD) GetSimilarSku(ctx context.Context, skus interface{}) (res *GetSimilarSkuRes, err error) {
method := "product/getSimilarSku" method := "product/getSimilarSku"
param := map[string]string{ param := g.Map{
"sku": skus.Join(","), "skuId": skus,
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
if err != nil { if err != nil {
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"context" "context"
"github.com/gogf/gf/container/garray" "github.com/gogf/gf/container/garray"
"github.com/gogf/gf/encoding/gjson" "github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
) )
type msgJD struct { type msgJD struct {
...@@ -54,7 +55,7 @@ type DelPushMessages struct { ...@@ -54,7 +55,7 @@ type DelPushMessages struct {
//102:专票资质审核进度消息 {"completeDate":"2019-01-09 00:19:14","pushDate":"2019-01-09 00:19:16","pins":"测试","reason":"财务审批通过","status":2,"unitName":"广州市翎唯营销策划有限公司","submitDate":"2018-09-25 15:56:47","taxpayerId":"914401055697802911","vatId":462260} //102:专票资质审核进度消息 {"completeDate":"2019-01-09 00:19:14","pushDate":"2019-01-09 00:19:16","pins":"测试","reason":"财务审批通过","status":2,"unitName":"广州市翎唯营销策划有限公司","submitDate":"2018-09-25 15:56:47","taxpayerId":"914401055697802911","vatId":462260}
func (msgJD) GetPushMessages(ctx context.Context, id *garray.Array) (res *GetPushMessages, err error) { func (msgJD) GetPushMessages(ctx context.Context, id *garray.Array) (res *GetPushMessages, err error) {
method := "message/get" method := "message/get"
param := map[string]string{ param := g.Map{
"type": id.Join(","), "type": id.Join(","),
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
...@@ -68,7 +69,7 @@ func (msgJD) GetPushMessages(ctx context.Context, id *garray.Array) (res *GetPus ...@@ -68,7 +69,7 @@ func (msgJD) GetPushMessages(ctx context.Context, id *garray.Array) (res *GetPus
//DeletePushMessage 删除消息 //DeletePushMessage 删除消息
func (msgJD) DeletePushMessage(ctx context.Context, id *garray.Array) (res *DelPushMessages, err error) { func (msgJD) DeletePushMessage(ctx context.Context, id *garray.Array) (res *DelPushMessages, err error) {
method := "message/del" method := "message/del"
param := map[string]string{ param := g.Map{
"id": id.Join(","), "id": id.Join(","),
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
......
...@@ -133,7 +133,7 @@ type SkuNums struct { ...@@ -133,7 +133,7 @@ type SkuNums struct {
// GetDelivery 物流信息 // GetDelivery 物流信息
func (*orderJD) GetDelivery(ctx context.Context, OrderID string) (res *GetDeliveryRes, err error) { func (*orderJD) GetDelivery(ctx context.Context, OrderID string) (res *GetDeliveryRes, err error) {
method := "order/orderTrack" method := "order/orderTrack"
param := g.MapStrStr{ param := g.Map{
"jdOrderId": OrderID, "jdOrderId": OrderID,
"waybillCode": "1", "waybillCode": "1",
} }
...@@ -148,7 +148,7 @@ func (*orderJD) GetDelivery(ctx context.Context, OrderID string) (res *GetDelive ...@@ -148,7 +148,7 @@ func (*orderJD) GetDelivery(ctx context.Context, OrderID string) (res *GetDelive
// PlaceOrder 下单 // PlaceOrder 下单
func (orderJD) PlaceOrder(ctx context.Context, req *PlaceOrderReq) (res *PlaceOrderRes, err error) { func (orderJD) PlaceOrder(ctx context.Context, req *PlaceOrderReq) (res *PlaceOrderRes, err error) {
method := "order/submitOrder" method := "order/submitOrder"
var param = g.MapStrStr{ var param = g.Map{
"thirdOrder": req.OrderSn, "thirdOrder": req.OrderSn,
"sku": gjson.New(req.SkuNums).MustToJsonString(), "sku": gjson.New(req.SkuNums).MustToJsonString(),
"orderPriceSnap": gjson.New(req.PriceSnap).MustToJsonString(), "orderPriceSnap": gjson.New(req.PriceSnap).MustToJsonString(),
...@@ -182,7 +182,7 @@ func (orderJD) PlaceOrder(ctx context.Context, req *PlaceOrderReq) (res *PlaceOr ...@@ -182,7 +182,7 @@ func (orderJD) PlaceOrder(ctx context.Context, req *PlaceOrderReq) (res *PlaceOr
// ReflectOrder 反查订单 // ReflectOrder 反查订单
func (orderJD) ReflectOrder(ctx context.Context, thirdOrder string) (res *ReflectOrderRes, err error) { func (orderJD) ReflectOrder(ctx context.Context, thirdOrder string) (res *ReflectOrderRes, err error) {
method := "order/selectJdOrderIdByThirdOrder" method := "order/selectJdOrderIdByThirdOrder"
param := g.MapStrStr{ param := g.Map{
"thirdOrder": thirdOrder, "thirdOrder": thirdOrder,
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
...@@ -196,7 +196,7 @@ func (orderJD) ReflectOrder(ctx context.Context, thirdOrder string) (res *Reflec ...@@ -196,7 +196,7 @@ func (orderJD) ReflectOrder(ctx context.Context, thirdOrder string) (res *Reflec
// GetOrderInfo 订单详情 // GetOrderInfo 订单详情
func (orderJD) GetOrderInfo(ctx context.Context, OrderID string) (res *GetOrderRes, err error) { func (orderJD) GetOrderInfo(ctx context.Context, OrderID string) (res *GetOrderRes, err error) {
method := "order/selectJdOrder" method := "order/selectJdOrder"
param := g.MapStrStr{ param := g.Map{
"jdOrderId": OrderID, "jdOrderId": OrderID,
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
...@@ -210,7 +210,7 @@ func (orderJD) GetOrderInfo(ctx context.Context, OrderID string) (res *GetOrderR ...@@ -210,7 +210,7 @@ func (orderJD) GetOrderInfo(ctx context.Context, OrderID string) (res *GetOrderR
// GetFreight 查询运费 // GetFreight 查询运费
func (orderJD) GetFreight(ctx context.Context, sku []*SkuNums, province, city, county, town string) (res *GetFreightRes, err error) { func (orderJD) GetFreight(ctx context.Context, sku []*SkuNums, province, city, county, town string) (res *GetFreightRes, err error) {
method := "order/getFreight" method := "order/getFreight"
param := g.MapStrStr{ param := g.Map{
"sku": gjson.New(sku).MustToJsonString(), "sku": gjson.New(sku).MustToJsonString(),
"province": province, "province": province,
"city": city, "city": city,
...@@ -229,7 +229,7 @@ func (orderJD) GetFreight(ctx context.Context, sku []*SkuNums, province, city, c ...@@ -229,7 +229,7 @@ func (orderJD) GetFreight(ctx context.Context, sku []*SkuNums, province, city, c
// ConfirmReceived 确认收货 // ConfirmReceived 确认收货
func (orderJD) ConfirmReceived(ctx context.Context, OrderID string) (res *CommonRes, err error) { func (orderJD) ConfirmReceived(ctx context.Context, OrderID string) (res *CommonRes, err error) {
method := "order/confirmReceived" method := "order/confirmReceived"
param := g.MapStrStr{ param := g.Map{
"jdOrderId": OrderID, "jdOrderId": OrderID,
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
......
...@@ -136,14 +136,22 @@ type CodeItem struct { ...@@ -136,14 +136,22 @@ type CodeItem struct {
type GetReturnTypeRes struct { type GetReturnTypeRes struct {
*CommonRes *CommonRes
Result []*CodeItem `json:"result"`//服务类型码:上门取件(4)、客户发货(40)、客户送货(7) 服务类型名称:上门取件、客户发货、客户送货 Result []*CodeItem `json:"result"` //服务类型码:上门取件(4)、客户发货(40)、客户送货(7) 服务类型名称:上门取件、客户发货、客户送货
}
type UpdateSendSkuReq struct {
AfsServiceId string `json:"afsServiceId"`
DeliverDate string `json:"deliverDate"`
ExpressCode string `json:"expressCode"`
ExpressCompany string `json:"expressCompany"`
FreightMoney int `json:"freightMoney"`
} }
// UpdateSendSku 根据填写单号 // UpdateSendSku 根据填写单号
func (refundJD) UpdateSendSku(ctx context.Context, postData string) (res *CommonRes, err error) { func (refundJD) UpdateSendSku(ctx context.Context, req *UpdateSendSkuReq) (res *CommonRes, err error) {
method := "afterSale/updateSendSku" method := "afterSale/updateSendSku"
param := g.MapStrStr{ param := g.Map{
"param": postData, "param": gjson.New(req).MustToJsonString(),
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
if err != nil { if err != nil {
...@@ -156,7 +164,7 @@ func (refundJD) UpdateSendSku(ctx context.Context, postData string) (res *Common ...@@ -156,7 +164,7 @@ func (refundJD) UpdateSendSku(ctx context.Context, postData string) (res *Common
//AuditCancel 取消服务单 //AuditCancel 取消服务单
func (refundJD) AuditCancel(ctx context.Context, postData string) (res *CommonRes, err error) { func (refundJD) AuditCancel(ctx context.Context, postData string) (res *CommonRes, err error) {
method := "afterSale/auditCancel" method := "afterSale/auditCancel"
param := g.MapStrStr{ param := g.Map{
"param": postData, "param": postData,
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
...@@ -174,7 +182,7 @@ func (refundJD) RefundCancel(ctx context.Context, id interface{}) (res *RefundCa ...@@ -174,7 +182,7 @@ func (refundJD) RefundCancel(ctx context.Context, id interface{}) (res *RefundCa
"serviceIdList": gconv.Ints(id), "serviceIdList": gconv.Ints(id),
"approveNotes": "取消售后", "approveNotes": "取消售后",
} }
param := g.MapStrStr{ param := g.Map{
"param": gjson.New(req).MustToJsonString(), "param": gjson.New(req).MustToJsonString(),
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
...@@ -188,7 +196,7 @@ func (refundJD) RefundCancel(ctx context.Context, id interface{}) (res *RefundCa ...@@ -188,7 +196,7 @@ func (refundJD) RefundCancel(ctx context.Context, id interface{}) (res *RefundCa
// Apply 申请售后服务(退货、换货、维修) // Apply 申请售后服务(退货、换货、维修)
func (refundJD) Apply(ctx context.Context, req *ApplyReq) (res *CommonRes, err error) { func (refundJD) Apply(ctx context.Context, req *ApplyReq) (res *CommonRes, err error) {
method := "afterSale/createAfsApply" method := "afterSale/createAfsApply"
param := g.MapStrStr{ param := g.Map{
"param": gjson.New(req).MustToJsonString(), "param": gjson.New(req).MustToJsonString(),
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
...@@ -200,11 +208,11 @@ func (refundJD) Apply(ctx context.Context, req *ApplyReq) (res *CommonRes, err e ...@@ -200,11 +208,11 @@ func (refundJD) Apply(ctx context.Context, req *ApplyReq) (res *CommonRes, err e
} }
// GetServiceList 查询服务单根据客户账号和订单号分页查询服务单概要信息 // GetServiceList 查询服务单根据客户账号和订单号分页查询服务单概要信息
func (refundJD) GetServiceList(ctx context.Context, req string) (res *GetServiceListRes, err error) { func (refundJD) GetServiceList(ctx context.Context, OrderSn string) (res *GetServiceListRes, err error) {
method := "afterSale/getServiceListPage" method := "afterSale/getServiceListPage"
param := g.MapStrStr{ param := g.Map{
"param": gjson.New(&GetServiceListReq{ "param": gjson.New(&GetServiceListReq{
JdOrderID: req, JdOrderID: OrderSn,
PageIndex: 1, PageIndex: 1,
PageSize: 100, PageSize: 100,
}).MustToJsonString(), }).MustToJsonString(),
...@@ -222,7 +230,7 @@ func (refundJD) GetServiceDetail(ctx context.Context, req string) (res *GetServi ...@@ -222,7 +230,7 @@ func (refundJD) GetServiceDetail(ctx context.Context, req string) (res *GetServi
method := "afterSale/getServiceDetailInfo" method := "afterSale/getServiceDetailInfo"
var reqJson = gjson.New("") var reqJson = gjson.New("")
_ = reqJson.Set("afsServiceId", req) _ = reqJson.Set("afsServiceId", req)
param := g.MapStrStr{ param := g.Map{
"param": reqJson.MustToJsonString(), "param": reqJson.MustToJsonString(),
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
...@@ -236,7 +244,7 @@ func (refundJD) GetServiceDetail(ctx context.Context, req string) (res *GetServi ...@@ -236,7 +244,7 @@ func (refundJD) GetServiceDetail(ctx context.Context, req string) (res *GetServi
// CheckIsSupport 查询订单商品是否允许售后 // CheckIsSupport 查询订单商品是否允许售后
func (refundJD) CheckIsSupport(ctx context.Context, req *RefundCommonReq) (res *CheckIsSupportRes, err error) { func (refundJD) CheckIsSupport(ctx context.Context, req *RefundCommonReq) (res *CheckIsSupportRes, err error) {
method := "afterSale/getAvailableNumberComp" method := "afterSale/getAvailableNumberComp"
param := g.MapStrStr{ param := g.Map{
"param": gjson.New(req).MustToJsonString(), "param": gjson.New(req).MustToJsonString(),
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
...@@ -250,7 +258,7 @@ func (refundJD) CheckIsSupport(ctx context.Context, req *RefundCommonReq) (res * ...@@ -250,7 +258,7 @@ func (refundJD) CheckIsSupport(ctx context.Context, req *RefundCommonReq) (res *
// GetSupportType 查询订单商品售后类型 // GetSupportType 查询订单商品售后类型
func (refundJD) GetSupportType(ctx context.Context, req *RefundCommonReq) (res *GetSupportTypeRes, err error) { func (refundJD) GetSupportType(ctx context.Context, req *RefundCommonReq) (res *GetSupportTypeRes, err error) {
method := "afterSale/getCustomerExpectComp" method := "afterSale/getCustomerExpectComp"
param := g.MapStrStr{ param := g.Map{
"param": gjson.New(req).MustToJsonString(), "param": gjson.New(req).MustToJsonString(),
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
...@@ -265,7 +273,7 @@ func (refundJD) GetSupportType(ctx context.Context, req *RefundCommonReq) (res * ...@@ -265,7 +273,7 @@ func (refundJD) GetSupportType(ctx context.Context, req *RefundCommonReq) (res *
// GetReturnType 查询支持的商品返回京东方式 // GetReturnType 查询支持的商品返回京东方式
func (refundJD) GetReturnType(ctx context.Context, req *RefundCommonReq) (res *GetReturnTypeRes, err error) { func (refundJD) GetReturnType(ctx context.Context, req *RefundCommonReq) (res *GetReturnTypeRes, err error) {
method := "afterSale/getWareReturnJdComp" method := "afterSale/getWareReturnJdComp"
param := g.MapStrStr{ param := g.Map{
"param": gjson.New(req).MustToJsonString(), "param": gjson.New(req).MustToJsonString(),
} }
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
......
...@@ -44,7 +44,7 @@ func (s *client) getAccessToken(ctx context.Context) (err error) { ...@@ -44,7 +44,7 @@ func (s *client) getAccessToken(ctx context.Context) (err error) {
} }
timeStamp := gtime.Now().String() timeStamp := gtime.Now().String()
sign := s.getSign(timeStamp) sign := s.getSign(timeStamp)
var params = g.MapStrStr{ var params = g.Map{
"grant_type": "access_token", "grant_type": "access_token",
"client_id": s.AppKey, "client_id": s.AppKey,
"timestamp": timeStamp, "timestamp": timeStamp,
...@@ -80,7 +80,7 @@ func (s *client) refreshToken(ctx context.Context, req *accessToken) (err error) ...@@ -80,7 +80,7 @@ func (s *client) refreshToken(ctx context.Context, req *accessToken) (err error)
_, err = g.Redis().DoVar("DEL", CacheKey) _, err = g.Redis().DoVar("DEL", CacheKey)
return s.getAccessToken(ctx) return s.getAccessToken(ctx)
} }
var params = g.MapStrStr{ var params = g.Map{
"refresh_token": req.RefreshToken, "refresh_token": req.RefreshToken,
"client_id": s.AppKey, "client_id": s.AppKey,
"client_secret": s.AppSecret, "client_secret": s.AppSecret,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论