提交 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
}
package ali
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type orderAli struct {
}
var Order = orderAli{}
type CreateOrderReq struct {
AddressParam AddressParam
CargoParam []CargoParam
OuterOrderInfo OuterOrderInfo
}
type AddressParam struct {
FullName string `json:"fullName"`
Mobile string `json:"mobile"`
Phone string `json:"phone"`
PostCode string `json:"postCode"`
CityText string `json:"cityText"`
ProvinceText string `json:"provinceText"`
AreaText string `json:"areaText"`
TownText string `json:"townText"`
Address string `json:"address"`
}
type CargoParam struct {
SpecId string `json:"specId"`
OfferId int64 `json:"offerId"`
Quantity int `json:"quantity"`
}
type OuterOrderInfo struct {
MediaOrderId string `json:"mediaOrderId"`
Phone string `json:"phone"`
Offers []Offer `json:"offers"`
}
type Offer struct {
SpecId string `json:"specId"`
Id int64 `json:"id"`
Num int `json:"num"`
Price int64 `json:"price"`
}
type CreateOrderRes struct {
*CommonRes
Result struct {
TotalSuccessAmount int64 `json:"totalSuccessAmount"` //下单成功的订单总金额,单位:分
OrderId string `json:"orderId"` //下单成功后的订单id
PostFee int64 `json:"postFee"` //原始运费,单位:分。注意:下单后卖家可能调整,因此该值可能不等于最终支付运费
} `json:"result,omitempty"`
}
type OrderDetailRes struct {
*CommonRes
Result struct {
BaseInfo struct {
PayTime string `json:"payTime"`
Discount int `json:"discount"`
AlipayTradeID string `json:"alipayTradeId"`
SumProductPayment float64 `json:"sumProductPayment"`
FlowTemplateCode string `json:"flowTemplateCode"`
SellerOrder bool `json:"sellerOrder"`
BuyerLoginID string `json:"buyerLoginId"`
ModifyTime string `json:"modifyTime"`
ID int64 `json:"id"`
BuyerContact struct {
Phone string `json:"phone"`
ImInPlatform string `json:"imInPlatform"`
Name string `json:"name"`
CompanyName string `json:"companyName"`
} `json:"buyerContact"`
SellerLoginID string `json:"sellerLoginId"`
BuyerID string `json:"buyerID"`
CloseOperateType string `json:"closeOperateType"`
TotalAmount float64 `json:"totalAmount"`
SellerID string `json:"sellerID"`
ShippingFee int `json:"shippingFee"`
Refund int `json:"refund"`
Status string `json:"status"`
RefundPayment int `json:"refundPayment"`
SellerContact struct {
Phone string `json:"phone"`
Email string `json:"email"`
ImInPlatform string `json:"imInPlatform"`
Name string `json:"name"`
Mobile string `json:"mobile"`
CompanyName string `json:"companyName"`
} `json:"sellerContact"`
CouponFee int `json:"couponFee"`
ReceiverInfo struct {
ToFullName string `json:"toFullName"`
ToDivisionCode string `json:"toDivisionCode"`
ToMobile string `json:"toMobile"`
ToPhone string `json:"toPhone"`
ToPost string `json:"toPost"`
ToArea string `json:"toArea"`
} `json:"receiverInfo"`
TradeType string `json:"tradeType"`
IDOfStr string `json:"idOfStr"`
StepPayAll bool `json:"stepPayAll"`
CreateTime string `json:"createTime"`
BusinessType string `json:"businessType"`
OverSeaOrder bool `json:"overSeaOrder"`
TradeTypeDesc string `json:"tradeTypeDesc"`
PayChannelList []string `json:"payChannelList"`
TradeTypeCode string `json:"tradeTypeCode"`
PayTimeout int `json:"payTimeout"`
PayTimeoutType int `json:"payTimeoutType"`
} `json:"baseInfo"`
OrderBizInfo struct {
OdsCyd bool `json:"odsCyd"`
CreditOrder bool `json:"creditOrder"`
} `json:"orderBizInfo"`
TradeTerms []struct {
Phase int64 `json:"phase"`
PayWayDesc string `json:"payWayDesc"`
ExpressPay bool `json:"expressPay"`
PayTime string `json:"payTime"`
PayStatusDesc string `json:"payStatusDesc"`
PayWay string `json:"payWay"`
CardPay bool `json:"cardPay"`
PayStatus string `json:"payStatus"`
PhasAmount float64 `json:"phasAmount"`
} `json:"tradeTerms"`
ProductItems []struct {
ItemAmount float64 `json:"itemAmount"`
Name string `json:"name"`
Price float64 `json:"price"`
ProductID int64 `json:"productID"`
ProductImgURL []string `json:"productImgUrl"`
ProductSnapshotURL string `json:"productSnapshotUrl"`
Quantity int `json:"quantity"`
Refund int `json:"refund"`
SkuID int64 `json:"skuID"`
Status string `json:"status"`
SubItemID int64 `json:"subItemID"`
Type string `json:"type"`
Unit string `json:"unit"`
GuaranteesTerms []struct {
AssuranceInfo string `json:"assuranceInfo"`
AssuranceType string `json:"assuranceType"`
QualityAssuranceType string `json:"qualityAssuranceType"`
} `json:"guaranteesTerms"`
ProductCargoNumber string `json:"productCargoNumber"`
SkuInfos []struct {
Name string `json:"name"`
Value string `json:"value"`
} `json:"skuInfos"`
EntryDiscount int `json:"entryDiscount"`
SpecID string `json:"specId"`
QuantityFactor int `json:"quantityFactor"`
StatusStr string `json:"statusStr"`
LogisticsStatus int `json:"logisticsStatus"`
GmtCreate string `json:"gmtCreate"`
GmtModified string `json:"gmtModified"`
GmtPayExpireTime string `json:"gmtPayExpireTime"`
SubItemIDString string `json:"subItemIDString"`
} `json:"productItems"`
NativeLogistics struct {
Address string `json:"address"`
Area string `json:"area"`
AreaCode string `json:"areaCode"`
City string `json:"city"`
ContactPerson string `json:"contactPerson"`
Mobile string `json:"mobile"`
Province string `json:"province"`
Telephone string `json:"telephone"`
Zip string `json:"zip"`
} `json:"nativeLogistics"`
GuaranteesTerms struct {
AssuranceInfo string `json:"assuranceInfo"`
AssuranceType string `json:"assuranceType"`
QualityAssuranceType string `json:"qualityAssuranceType"`
} `json:"guaranteesTerms"`
OrderRateInfo struct {
BuyerRateStatus int `json:"buyerRateStatus"`
SellerRateStatus int `json:"sellerRateStatus"`
} `json:"orderRateInfo"`
ExtAttributes []interface{} `json:"extAttributes"`
} `json:"result"`
}
type ProductItems struct {
Status string `json:"status"` //子订单状态
SubItemID int64 `json:"subItemID"` //子订单号,或商品明细条目ID
SubItemIDString string `json:"subItemIDString"` //子订单号,或商品明细条目ID
SkuID int64 `json:"skuID"` //skuID
ProductID int64 `json:"productID"` //产品ID(非在线产品为空)
Quantity int64 `json:"quantity"` //以unit为单位的数量
ItemAmount float64 `json:"itemAmount"` //实付金额,单位为元
Refund float64 `json:"refund"` //退款金额,单位为元
LogisticsStatus int `json:"logisticsStatus"` //1 未发货 2 已发货 3 已收货 4 已经退货 5 部分发货 8 还未创建物流订单
RefundIdForAs string `json:"refundIdForAs"` //售后退款单号
NativeLogistics struct {
LogisticsItems struct {
LogisticsCompanyId int64 `json:"logisticsCompanyId"` //物流公司Id
LogisticsCompanyNo int64 `json:"logisticsCompanyNo"` //物流公司编号
LogisticsCompanyName string `json:"logisticsCompanyName"` //物流公司名称
LogisticsBillNo string `json:"logisticsBillNo"` //物流公司运单号
Carriage float64 `json:"carriage"` //运费(单位为元)
DeliveredTime string `json:"deliveredTime"` //发货时间
} `json:"logisticsItems"` //运单明细
} `json:"nativeLogistics"` //国内物流
}
type BeforeCreateRes struct {
*CommonRes
OrderPreviewResuslt []BeforeCreateItem `json:"orderPreviewResuslt"`
}
type BeforeCreateItem struct {
SumPayment int64 `json:"sumPayment"` //订单总费用, 单位为分
SumPaymentNoCarriage int64 `json:"sumPaymentNoCarriage"` //不包含运费的货品总费用, 单位为分.
AdditionalFee int64 `json:"additionalFee"` //附加费,单位,分
SumCarriage int64 `json:"sumCarriage"` //总运费信息, 单位为分.
ShopPromotionList []struct { //可用店铺级别优惠列表
PromotionId int64 `json:"promotionId"` //优惠券ID
} `json:"shopPromotionList"` //规格信息
Message string `json:"message"` //返回信息
CargoList []struct {
FinalUnitPrice float64 `json:"finalUnitPrice"` //最终单价
SpecId string `json:"specId"` //规格ID,offer内唯一
OfferId string `json:"offerId"` //规格ID,offer内唯一
} `json:"cargoList"` //规格信息
}
type DeliverRes struct {
*CommonRes
LogisticsTrace []struct {
LogisticsBillNo string `json:"logisticsBillNo"` //物流单号,运单号
LogisticsId string `json:"logisticsId"` //物流信息ID
OrderId int64 `json:"orderId"` //订单编号
LogisticsCompanyName string `json:"LogisticsCompanyName"` //物流公司编码
LogisticsSteps []struct {
AcceptTime string `json:"acceptTime"` //物流跟踪单该步骤的时间
Remark string `json:"remark"` //备注,如:“在浙江浦江县公司进行下级地点扫描,即将发往:广东深圳公司”
} `json:"logisticsSteps"` //物流跟踪步骤
} `json:"logisticsTrace"` //跟踪单详情
}
type GetLogisticCompanyRes struct {
*CommonRes
Result []CompanyInfo `json:"result"` //result
}
type CompanyInfo struct {
Id int64 `json:"id"`
CompanyName string `json:"companyName"` //物流公司名称
CompanyNo string `json:"companyNo"` // 物流公司编号
}
//CreateOrder 下单
func (s *orderAli) CreateOrder(ctx context.Context, req *CreateOrderReq) (res *CreateOrderRes, err error) {
method := "com.alibaba.trade/alibaba.trade.createOrder4CybMedia"
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
"addressParam": gjson.New(req.AddressParam).MustToJsonString(),
"cargoParamList": gjson.New(req.CargoParam).MustToJsonString(),
"outerOrderInfo": gjson.New(req.OuterOrderInfo).MustToJsonString(),
})
_ = gjson.New(result).Scan(&res)
return
}
//OrderDetail 订单详情
func (s *orderAli) OrderDetail(ctx context.Context, orderSn string) (res *OrderDetailRes, err error) {
method := "com.alibaba.trade/alibaba.trade.get.buyerView"
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
"webSite": WebSite,
"orderId": orderSn,
})
_ = gjson.New(result).Scan(&res)
return
}
//Pay 支付
func (s *orderAli) Pay(ctx context.Context, orderSn string) (res *CommonRes, err error) {
method := "com.alibaba.trade/alibaba.trade.pay.protocolPay"
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
"orderId": orderSn,
})
_ = gjson.New(result).Scan(&res)
return
}
//BeforeCreate 验证订单商品
func (s *orderAli) BeforeCreate(ctx context.Context, req *CreateOrderReq) (res *BeforeCreateRes, err error) {
method := "com.alibaba.trade/alibaba.createOrder.preview4CybMedia"
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
"addressParam": gjson.New(req.AddressParam).MustToJsonString(),
"cargoParamList": gjson.New(req.CargoParam).MustToJsonString(),
})
_ = gjson.New(result).Scan(&res)
return
}
//Deliver 获取物流信息
func (s *orderAli) Deliver(ctx context.Context, orderSn string) (res *DeliverRes, err error) {
method := "com.alibaba.logistics/alibaba.trade.getLogisticsTraceInfo.buyerView"
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
"orderId": orderSn,
"webSite": WebSite,
})
_ = gjson.New(result).Scan(&res)
return
}
//GetLogisticCompany 物流公司
func (s *orderAli) GetLogisticCompany(ctx context.Context) (res *GetLogisticCompanyRes, err error) {
method := "com.alibaba.logistics/alibaba.logistics.OpQueryLogisticCompanyList"
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
})
_ = gjson.New(result).Scan(&res)
return
}
package ali
import (
"context"
"encoding/base64"
"github.com/gogf/gf/container/garray"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/util/gconv"
)
type refundAli struct {
}
var Refund = refundAli{}
type RefundApplyReq struct {
OrderId int64 `json:"orderId"` //主订单
OrderEntryIds []int64 `json:"orderEntryIds"` //子订单
DisputeRequest string `json:"disputeRequest"` //退款/退款退货。只有已收到货,才可以选择退款退货[退款:"refund"; 退款退货:"returnRefund"]
ApplyPayment int64 `json:"applyPayment"` //退款金额(单位:分)
ApplyCarriage int64 `json:"applyCarriage"` //退运费金额(单位:分)
ApplyReasonId int64 `json:"applyReasonId"` //退款原因id
Description int64 `json:"description"` //退款申请理由,2-150字
GoodsStatus int64 `json:"goodsStatus"` //货物状态[售中等待卖家发货:"refundWaitSellerSend"; 售中等待买家收货:"refundWaitBuyerReceive"; 售中已收货(未确认完成交易):"refundBuyerReceived" 售后未收货:"aftersaleBuyerNotReceived"; 售后已收到货:"aftersaleBuyerReceived"]
Vouchers []string `json:"vouchers"` //凭证图片URLs。1-5张,必须使用API uploadRefundVoucher返回的“图片域名/相对路径”
OrderEntryCountList []*RefundApplyItem `json:"orderEntryCountList"` //子订单退款数量。仅在售中买家已收货(退款退货)时,可指定退货数量;默认,全部退货。
AccessToken string `json:"access_token"`
}
type RefundApplyItem struct {
Id int64 `json:"id"` //子订单id
Count int64 `json:"count"` //子订单购买商品数量
}
type RefundApplyRes struct {
Result struct {
Result struct {
RefundId string `json:"refundId"` // 创建成功,退款id
} `json:"result"`
Success bool `json:"success"` //是否成功
Code string `json:"code"` //错误信息
Message string `json:"message"` //错误码
} `json:"result"`
}
type RefundReasonReq struct {
OrderId string `json:"orderId"` //主订单id
OrderEntryIds []int64 `json:"orderEntryIds"` //子订单id
GoodsStatus string `json:"goodsStatus"` //货物状态 售中等待买家发货:”refundWaitSellerSend"; 售中等待买家收货:"refundWaitBuyerReceive"; 售中已收货(未确认完成交易):"refundBuyerReceived" 售后未收货:"aftersaleBuyerNotReceived"; 售后已收到货:"aftersaleBuyerReceived"
AccessToken string `json:"access_token"`
}
type RefundReasonRes struct {
Result struct {
*CommonRes
Result struct {
Reasons []struct {
ID int `json:"id"` //原因id
Name string `json:"name"` //原因
NeedVoucher bool `json:"needVoucher"` //凭证是否必须上传
NoRefundCarriage bool `json:"noRefundCarriage"` //是否支持退运费
Tip string `json:"tip,omitempty"` //提示
} `json:"reasons"`
} `json:"result"`
} `json:"result"`
}
type RefundUploadRes struct {
Result struct {
*CommonRes
Result struct {
ImageDomain string `json:"imageDomain"`
ImageRelativeURL string `json:"imageRelativeUrl"`
} `json:"result"`
} `json:"result"`
}
type RefundInfoReq struct {
RefundId string `json:"refundId"`
NeedTimeOutInfo bool `json:"needTimeOutInfo"`
NeedOrderRefundOperation bool `json:"needOrderRefundOperation"`
AccessToken string `json:"access_token"`
}
type RefundInfoRes struct {
Result struct {
OpOrderRefundModelDetail struct {
AlipayPaymentID string `json:"alipayPaymentId"`
ApplyCarriage int `json:"applyCarriage"`
ApplyPayment int `json:"applyPayment"`
ApplyReason string `json:"applyReason"`
ApplyReasonID int `json:"applyReasonId"`
ApplySubReasonID int `json:"applySubReasonId"`
BuyerMemberID string `json:"buyerMemberId"`
BuyerSendGoods bool `json:"buyerSendGoods"`
BuyerUserID int `json:"buyerUserId"`
CanRefundPayment int `json:"canRefundPayment"`
CrmModifyRefund bool `json:"crmModifyRefund"`
DisputeRequest int `json:"disputeRequest"`
DisputeType int `json:"disputeType"`
ExtInfo struct {
Enfunddetail string `json:"enfunddetail"`
BizCode string `json:"bizCode"`
LastOrder string `json:"lastOrder"`
Tod string `json:"tod"`
NewRefund string `json:"newRefund"`
BFsc string `json:"b_fsc"`
OpRole string `json:"opRole"`
B2BBuyerMID string `json:"b2b_buyer_mId"`
ApplyReasonText string `json:"apply_reason_text"`
ApplyInitRefundFee string `json:"apply_init_refund_fee"`
ItemBuyAmount string `json:"itemBuyAmount"`
UserCredit string `json:"userCredit"`
SdkCode string `json:"sdkCode"`
InterceptItemListResult string `json:"interceptItemListResult"`
InterceptStatus string `json:"interceptStatus"`
SellerBatch string `json:"seller_batch"`
CljZeroSecondRefund string `json:"clj_zero_second_refund"`
Tos string `json:"tos"`
BsSync string `json:"bs_sync"`
OlTf string `json:"ol_tf"`
BPf string `json:"b_pf"`
Sgr string `json:"sgr"`
PartRefund string `json:"part_refund"`
Bgmtc string `json:"bgmtc"`
PayMode string `json:"payMode"`
AppName string `json:"appName"`
WorkflowName string `json:"workflowName"`
Ttid string `json:"ttid"`
SellerAudit string `json:"seller_audit"`
Rp3 string `json:"rp3"`
B2BBt string `json:"b2b_bt"`
B2BExchange string `json:"b2b_exchange"`
ItemPrice string `json:"itemPrice"`
IsVirtual string `json:"isVirtual"`
EXmrf string `json:"EXmrf"`
B2BSellerMID string `json:"b2b_seller_mId"`
} `json:"extInfo"`
FrozenFund int `json:"frozenFund"`
GmtApply string `json:"gmtApply"`
GmtCreate string `json:"gmtCreate"`
GmtModified string `json:"gmtModified"`
GmtTimeOut string `json:"gmtTimeOut"`
GoodsReceived bool `json:"goodsReceived"`
GoodsStatus int `json:"goodsStatus"`
ID int64 `json:"id"`
NewRefundReturn bool `json:"newRefundReturn"`
OnlyRefund bool `json:"onlyRefund"`
OrderEntryIDList []int64 `json:"orderEntryIdList"`
OrderID int64 `json:"orderId"`
ProductName string `json:"productName"`
RefundCarriage int `json:"refundCarriage"`
RefundGoods bool `json:"refundGoods"`
RefundID string `json:"refundId"`
RefundPayment int `json:"refundPayment"`
RejectReasonID int `json:"rejectReasonId"`
RejectTimes int `json:"rejectTimes"`
SellerDelayDisburse bool `json:"sellerDelayDisburse"`
SellerMemberID string `json:"sellerMemberId"`
SellerUserID int64 `json:"sellerUserId"`
Status string `json:"status"`
SupportNewSteppay bool `json:"supportNewSteppay"`
TimeOutFreeze bool `json:"timeOutFreeze"`
TradeTypeStr string `json:"tradeTypeStr"`
RefundOperationList []interface{} `json:"refundOperationList"`
BuyerLoginID string `json:"buyerLoginId"`
SellerLoginID string `json:"sellerLoginId"`
} `json:"opOrderRefundModelDetail"`
} `json:"result"`
}
type RefundSubmitReq struct {
RefundId string `json:"refundId"` //退款单号,TQ开头
CompanyNo string `json:"logisticsCompanyNo"` //物流公司编码,调用alibaba.logistics.OpQueryLogisticCompanyList.offline接口查询
ExpressSn string `json:"freightBill"` //物流公司运单号,请准确填写,否则卖家有权拒绝退款
Description string `json:"description"` //发货说明,内容在2-200个字之间
Vouchers []string `json:"vouchers"` //凭证图片URLs,必须使用API alibaba.trade.uploadRefundVoucher返回的“图片域名/相对路径”,最多可上传 10 张图片 ;单张大小不超过1M;支持jpg、gif、jpeg、png、和bmp格式。 请上传凭证,以便以后续赔所需(不上传将无法理赔)
AccessToken string `json:"access_token"`
}
type RefundSubmitRes struct {
Result struct {
*CommonRes
} `json:"result"`
}
//Apply 创建退款退货申请
func (refundAli) Apply(ctx context.Context, req *RefundApplyReq) (res *RefundApplyRes, err error) {
method := "com.alibaba.trade/alibaba.trade.createRefund"
req.AccessToken = server.AccessToken
result, err := server.Post(ctx, method, gconv.Map(req))
_ = gjson.New(result).Scan(&res)
return
}
//Reason 获取退换货原因
func (*refundAli) Reason(ctx context.Context, req *RefundReasonReq) (res *RefundReasonRes, err error) {
method := "com.alibaba.trade/alibaba.trade.getRefundReasonList"
req.AccessToken = server.AccessToken
result, err := server.Post(ctx, method, gconv.Map(req))
_ = gjson.New(result).Scan(&res)
return
}
// Upload 上传退款退货凭证
func (*refundAli) Upload(ctx context.Context, ImgBase64 string) (res *RefundUploadRes, err error) {
method := "com.alibaba.trade/alibaba.trade.uploadRefundVoucher"
dist, _ := base64.StdEncoding.DecodeString(ImgBase64)
var imgArr = garray.New()
for i := range dist {
imgArr.Append(dist[i])
}
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
"imageData": "[" + imgArr.Join(",") + "]",
})
_ = gjson.New(result).Scan(&res)
return
}
//Info 查询退款单详情-根据退款单ID
func (*refundAli) Info(ctx context.Context, refundId string) (res *RefundInfoRes, err error) {
method := "com.alibaba.trade/alibaba.trade.refund.OpQueryOrderRefund"
var req = &RefundInfoReq{
RefundId: refundId,
NeedOrderRefundOperation: true,
AccessToken: server.AccessToken,
}
result, err := server.Post(ctx, method, gconv.Map(req))
_ = gjson.New(result).Scan(&res)
return
}
//Submit 提交退款货信息
func (*refundAli) Submit(ctx context.Context, req *RefundSubmitReq) (res *RefundSubmitRes, err error) {
method := "com.alibaba.trade/alibaba.trade.refund.returnGoods"
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,11 +121,12 @@ type GetSkuImageRes struct { ...@@ -110,11 +121,12 @@ 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 {
Dim int `json:"dim"` //维度 Dim int `json:"dim"` //维度
SaleName string `json:"saleName"` //销售名称 SaleName string `json:"saleName"` //销售名称
SaleAttrList []struct { //商品销售标签 销售属性下可能只有一个标签,此种场景可以选择显示销售名称和标签,也可以不显示 SaleAttrList []struct { //商品销售标签 销售属性下可能只有一个标签,此种场景可以选择显示销售名称和标签,也可以不显示
ImagePath string `json:"imagePath"` //标签图片地址 ImagePath string `json:"imagePath"` //标签图片地址
SaleValue string `json:"saleValue"` //标签名称 SaleValue string `json:"saleValue"` //标签名称
...@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论