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

有赞

上级 39fd6e02
package yz package yz
import ( import (
"bytes"
"context" "context"
"github.com/gogf/gf/encoding/gjson" "github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g" "github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gtime" "github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/util/gconv" "github.com/gogf/gf/util/gconv"
"time"
"fmt"
"bytes"
"net/http"
"log"
"io" "io"
"os"
"io/ioutil" "io/ioutil"
"mime/multipart" "mime/multipart"
"net/http"
"os"
"time"
) )
type Config struct { type Config struct {
...@@ -42,19 +40,19 @@ var server *client ...@@ -42,19 +40,19 @@ var server *client
const CacheKey = "yz:token" const CacheKey = "yz:token"
const pkgName = "yz" const pkgName = "yz"
const authorizeType = "silent" const authorizeType = "silent"
func New(config *Config) { func New(config *Config) {
_ = gconv.Scan(config, &server) _ = gconv.Scan(config, &server)
return return
} }
//post 请求 // post 请求
func (s *client) post(ctx context.Context, method string, params g.Map) (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()
Request := g.Client() Request := g.Client()
Request.SetHeader("Content-Type", "application/json") Request.SetHeader("Content-Type", "application/json")
url := method + "?access_token=" + server.AccessToken url := method + "?access_token=" + server.AccessToken
resp, err := Request.Timeout(time.Second*5).Post(url, params) resp, err := Request.Timeout(time.Second*5).Post(url, params)
fmt.Println(url)
defer func() { defer func() {
_ = resp.Close() _ = resp.Close()
paramStr := gjson.New(params).MustToJsonString() paramStr := gjson.New(params).MustToJsonString()
...@@ -72,77 +70,61 @@ func (s *client) post(ctx context.Context, method string, params g.Map) (str str ...@@ -72,77 +70,61 @@ func (s *client) post(ctx context.Context, method string, params g.Map) (str str
str = resp.ReadAllString() str = resp.ReadAllString()
return return
} }
//post 请求
// post 请求
func (s *client) postImg(ctx context.Context, method string, params string) (str string, err error) { func (s *client) postImg(ctx context.Context, method string, params string) (str string, err error) {
g.Dump(89876)
Start := gtime.TimestampMilli() Start := gtime.TimestampMilli()
url := method + "?access_token=" + server.AccessToken url := method + "?access_token=" + server.AccessToken
client := http.Client{} client := http.Client{}
bodyBuf := &bytes.Buffer{} bodyBuf := &bytes.Buffer{}
bodyWrite := multipart.NewWriter(bodyBuf) bodyWrite := multipart.NewWriter(bodyBuf)
g.Dump(898761)
file, err := os.Open(params) file, err := os.Open(params)
g.Dump(8987612)
defer file.Close() defer file.Close()
if err != nil { if err != nil {
g.Dump(66666) return
log.Println("err")
} }
// file 为key
g.Dump(89876123)
fileWrite, err := bodyWrite.CreateFormFile("image", params) fileWrite, err := bodyWrite.CreateFormFile("image", params)
_, err = io.Copy(fileWrite, file) _, err = io.Copy(fileWrite, file)
g.Dump(898761234)
if err != nil { if err != nil {
g.Dump(777777) return
log.Println("err")
} }
bodyWrite.Close() //要关闭,会将w.w.boundary刷写到w.writer中 bodyWrite.Close() //要关闭,会将w.w.boundary刷写到w.writer中
// 创建请求 // 创建请求
g.Dump(8987612345)
contentType := bodyWrite.FormDataContentType() contentType := bodyWrite.FormDataContentType()
req, err := http.NewRequest(http.MethodPost, url, bodyBuf) req, err := http.NewRequest(http.MethodPost, url, bodyBuf)
if err != nil { if err != nil {
g.Dump(888888) return
log.Println("err")
} }
// 设置头 // 设置头
g.Dump(8987612346)
req.Header.Set("Content-Type", contentType) req.Header.Set("Content-Type", contentType)
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
g.Dump(99999) return
log.Println("err")
} }
g.Dump(8987612347)
defer func() { defer func() {
_ = resp.Body.Close() _ = resp.Body.Close()
paramStr := gjson.New(params).MustToJsonString() paramStr := gjson.New(params).MustToJsonString()
ctx = context.WithValue(ctx, "Method", "POST") ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", url) ctx = context.WithValue(ctx, "URI", url)
if err != nil { if err != nil {
g.Dump(123456)
g.Log().Ctx(ctx).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v ms】", paramStr, err.Error(), gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v ms】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else { } else {
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v ms】", paramStr, str, gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v ms】", paramStr, str, gtime.TimestampMilli()-Start)
} }
}() }()
g.Dump(89876123478)
b, err := ioutil.ReadAll(resp.Body) b, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
g.Dump(999999888) return
log.Println("err")
} }
g.Dump(8987612347889)
str = string(b) str = string(b)
return return
} }
// requestApi 请求 // requestApi 请求
func (s *client) requestApi(ctx context.Context, method string, businessParams g.Map) (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)
...@@ -153,6 +135,7 @@ func (s *client) requestApi(ctx context.Context, method string, businessParams g ...@@ -153,6 +135,7 @@ func (s *client) requestApi(ctx context.Context, method string, businessParams g
str, err = s.post(ctx, urlMethod, params) str, err = s.post(ctx, urlMethod, params)
return return
} }
// requestApi 请求 // requestApi 请求
func (s *client) requestApiImg(ctx context.Context, method string, businessParams string) (str string, err error) { func (s *client) requestApiImg(ctx context.Context, method string, businessParams string) (str string, err error) {
_, err = s.createPostRequest(ctx, nil) _, err = s.createPostRequest(ctx, nil)
......
package yz
type MsgOrder struct {
Msg struct {
DeliveryOrder []struct {
PkId string `json:"pk_id"`
ExpressState string `json:"express_state"`
Oids []struct {
Oid string `json:"oid"`
} `json:"oids"`
ExpressType string `json:"express_type"`
} `json:"delivery_order"`
OrderPromotion struct {
Item []struct {
Promotions struct {
PromotionType string `json:"promotion_type"`
PromotionTitle string `json:"promotion_title"`
PromotionTypeName string `json:"promotion_type_name"`
PromotionTypeId string `json:"promotion_type_id"`
Decrease string `json:"decrease"`
} `json:"promotions"`
IsPresent string `json:"is_present"`
ItemId string `json:"item_id"`
SkuId string `json:"sku_id"`
Oid string `json:"oid"`
} `json:"item"`
OrderDiscountFee string `json:"order_discount_fee"`
AdjustFee string `json:"adjust_fee"`
ItemDiscountFee string `json:"item_discount_fee"`
Order []struct {
PromotionType string `json:"promotion_type"`
SubPromotionType string `json:"sub_promotion_type"`
CouponId string `json:"coupon_id"`
PromotionTitle string `json:"promotion_title"`
PromotionCondition string `json:"promotion_condition"`
PromotionTypeName string `json:"promotion_type_name"`
PromotionContent string `json:"promotion_content"`
PromotionId string `json:"promotion_id"`
PromotionTypeId string `json:"promotion_type_id"`
DiscountFee string `json:"discount_fee"`
} `json:"order"`
} `json:"order_promotion"`
RefundOrder []struct {
RefundType string `json:"refund_type"`
RefundFee string `json:"refund_fee"`
RefundId string `json:"refund_id"`
RefundState string `json:"refund_state"`
Oids string `json:"oids"`
} `json:"refund_order"`
FullOrderInfo struct {
ChildInfo struct {
GiftNo string `json:"gift_no"`
GiftSign string `json:"gift_sign"`
} `json:"child_info"`
InvoiceInfo struct {
UserName string `json:"user_name"`
TaxpayerId string `json:"taxpayer_id"`
RaiseType string `json:"raise_type"`
InvoiceDetailType string `json:"invoice_detail_type"`
} `json:"invoice_info"`
RemarkInfo struct {
Star string `json:"star"`
BuyerMessage string `json:"buyer_message"`
TradeMemo string `json:"trade_memo"`
} `json:"remark_info"`
AddressInfo struct {
SelfFetchInfo string `json:"self_fetch_info"`
DeliveryAddress string `json:"delivery_address"`
DeliveryStartTime string `json:"delivery_start_time"`
DeliveryEndTime string `json:"delivery_end_time"`
DeliveryPostalCode string `json:"delivery_postal_code"`
ReceiverName string `json:"receiver_name"`
DeliveryProvince string `json:"delivery_province"`
DeliveryCity string `json:"delivery_city"`
AddressExtra string `json:"address_extra"`
DeliveryDistrict string `json:"delivery_district"`
ReceiverTel string `json:"receiver_tel"`
} `json:"address_info"`
PayInfo struct {
OuterTransactions string `json:"outer_transactions"`
PostFee string `json:"post_fee"`
TotalFee string `json:"total_fee"`
Payment string `json:"payment"`
Transaction string `json:"transaction"`
} `json:"pay_info"`
BuyerInfo struct {
OuterUserId string `json:"outer_user_id"`
BuyerPhone string `json:"buyer_phone"`
YzOpenId string `json:"yz_open_id"`
FansType string `json:"fans_type"`
BuyerId string `json:"buyer_id"`
FansId string `json:"fans_id"`
FansNickname string `json:"fans_nickname"`
} `json:"buyer_info"`
Orders []struct {
TaxTotal string `json:"tax_total"`
IsCrossBorder string `json:"is_cross_border"`
FenxiaoDiscount string `json:"fenxiao_discount"`
OuterItemId string `json:"outer_item_id"`
ItemType string `json:"item_type"`
DiscountPrice string `json:"discount_price"`
Num string `json:"num"`
Freight string `json:"freight"`
Discount string `json:"discount"`
FenxiaoDiscountPrice string `json:"fenxiao_discount_price"`
Oid string `json:"oid"`
GoodsSnapshot string `json:"goods_snapshot"`
Title string `json:"title"`
FenxiaoPayment string `json:"fenxiao_payment"`
ItemMessage string `json:"item_message"`
ItemNo string `json:"item_no"`
BuyerMessages string `json:"buyer_messages"`
IsPresent string `json:"is_present"`
CrossBorderTradeMode string `json:"cross_border_trade_mode"`
FenxiaoFreight string `json:"fenxiao_freight"`
Price string `json:"price"`
SubOrderNo string `json:"sub_order_no"`
TotalFee string `json:"total_fee"`
FenxiaoPrice string `json:"fenxiao_price"`
Alias string `json:"alias"`
Payment string `json:"payment"`
ItemBarcode string `json:"item_barcode"`
OuterSkuId string `json:"outer_sku_id"`
GoodsUrl string `json:"goods_url"`
CustomsCode string `json:"customs_code"`
ItemId string `json:"item_id"`
PicPath string `json:"pic_path"`
SkuPropertiesName string `json:"sku_properties_name"`
SkuId string `json:"sku_id"`
PointsPrice string `json:"points_price"`
SkuNo string `json:"sku_no"`
FenxiaoTaxTotal string `json:"fenxiao_tax_total"`
SkuBarcode string `json:"sku_barcode"`
} `json:"orders"`
SourceInfo struct {
IsOfflineOrder string `json:"is_offline_order"`
BookKey string `json:"book_key"`
Source struct {
Platform string `json:"platform"`
WxEntrance string `json:"wx_entrance"`
} `json:"source"`
} `json:"source_info"`
OrderInfo struct {
ConsignTime string `json:"consign_time"`
OrderExtra struct {
IsFromCart string `json:"is_from_cart"`
CashierId string `json:"cashier_id"`
FxKdtId string `json:"fx_kdt_id"`
IdCardName string `json:"id_card_name"`
FxInnerTransactionNo string `json:"fx_inner_transaction_no"`
InvoiceTitle string `json:"invoice_title"`
IsSubOrder string `json:"is_sub_order"`
CashierName string `json:"cashier_name"`
IsPointsOrder string `json:"is_points_order"`
SettleTime string `json:"settle_time"`
FxOuterTransactionNo string `json:"fx_outer_transaction_no"`
Daogou string `json:"daogou"`
MerchantCustomizedSpecialOrder string `json:"merchant_customized_special_order"`
ExtraPrices string `json:"extra_prices"`
IsParentOrder string `json:"is_parent_order"`
IdCardNumber string `json:"id_card_number"`
FxOrderNo string `json:"fx_order_no"`
DeptId string `json:"dept_id"`
ParentOrderNo string `json:"parent_order_no"`
PurchaseOrderNo string `json:"purchase_order_no"`
CreateDeviceId string `json:"create_device_id"`
} `json:"order_extra"`
Created string `json:"created"`
OfflineId string `json:"offline_id"`
StatusStr string `json:"status_str"`
ExpiredTime string `json:"expired_time"`
SuccessTime string `json:"success_time"`
Type string `json:"type"`
Tid string `json:"tid"`
ConfirmTime string `json:"confirm_time"`
PayTime string `json:"pay_time"`
UpdateTime string `json:"update_time"`
IsRetailOrder string `json:"is_retail_order"`
PayType string `json:"pay_type"`
TeamType string `json:"team_type"`
RefundState string `json:"refund_state"`
CloseType string `json:"close_type"`
Status string `json:"status"`
ExpressType string `json:"express_type"`
OrderTags struct {
IsVirtual string `json:"is_virtual"`
IsPurchaseOrder string `json:"is_purchase_order"`
IsMember string `json:"is_member"`
IsPreorder string `json:"is_preorder"`
IsOfflineOrder string `json:"is_offline_order"`
IsMultiStore string `json:"is_multi_store"`
IsSettle string `json:"is_settle"`
IsPayed string `json:"is_payed"`
IsSecuredTransactions string `json:"is_secured_transactions"`
IsPostageFree string `json:"is_postage_free"`
IsFenxiaoOrder string `json:"is_fenxiao_order"`
IsFeedback string `json:"is_feedback"`
IsRefund string `json:"is_refund"`
} `json:"order_tags"`
} `json:"order_info"`
} `json:"full_order_info"`
} `json:"msg"`
KdtName string `json:"kdt_name"`
Type string `json:"type"`
Version string `json:"version"`
KdtId string `json:"kdt_id"`
Id string `json:"id"`
MsgId string `json:"msg_id"`
HeadKdtId string `json:"head_kdt_id"`
AppId string `json:"app_id"`
RootKdtId string `json:"root_kdt_id"`
Status string `json:"status"`
}
package yz
import (
"context"
"encoding/json"
"github.com/gogf/gf/frame/g"
)
type orderLogic struct {
}
var Order = orderLogic{}
type OrderDetailRes struct {
TraceId string `json:"trace_id"`
Code int `json:"code"`
Data struct {
DeliveryOrder []interface{} `json:"delivery_order"`
OrderPromotion struct {
Item []interface{} `json:"item"`
AdjustFee string `json:"adjust_fee"`
OrderPaidPromotion []interface{} `json:"order_paid_promotion"`
Order []interface{} `json:"order"`
} `json:"order_promotion"`
CustomItemInfos []interface{} `json:"custom_item_infos"`
RefundOrder []interface{} `json:"refund_order"`
FullOrderInfo struct {
ChildInfo struct {
ChildOrders []interface{} `json:"child_orders"`
} `json:"child_info"`
RemarkInfo struct {
BuyerMessage string `json:"buyer_message"`
} `json:"remark_info"`
AddressInfo struct {
SelfFetchInfo string `json:"self_fetch_info"`
DeliveryAddress string `json:"delivery_address"`
DeliveryPostalCode string `json:"delivery_postal_code"`
ReceiverName string `json:"receiver_name"`
DeliveryProvince string `json:"delivery_province"`
DeliveryCity string `json:"delivery_city"`
DeliveryDistrict string `json:"delivery_district"`
AddressExtra string `json:"address_extra"`
ReceiverTel string `json:"receiver_tel"`
} `json:"address_info"`
PayInfo struct {
OuterTransactions []string `json:"outer_transactions"`
DeductionRealPay int `json:"deduction_real_pay"`
RealPayment string `json:"real_payment"`
PostFee string `json:"post_fee"`
DeductionPay int `json:"deduction_pay"`
PhasePayments []interface{} `json:"phase_payments"`
TotalFee string `json:"total_fee"`
Payment string `json:"payment"`
Transaction []string `json:"transaction"`
} `json:"pay_info"`
BuyerInfo struct {
OuterUserId string `json:"outer_user_id"`
BuyerPhone string `json:"buyer_phone"`
YzOpenId string `json:"yz_open_id"`
FansType int `json:"fans_type"`
FansNickname string `json:"fans_nickname"`
FansId int `json:"fans_id"`
} `json:"buyer_info"`
Orders []struct {
GoodsCostPrice string `json:"goods_cost_price"`
IsCrossBorder string `json:"is_cross_border"`
OuterItemId string `json:"outer_item_id"`
ItemType int `json:"item_type"`
DiscountPrice string `json:"discount_price"`
GoodsDate string `json:"goods_date"`
WarehouseCode string `json:"warehouse_code"`
Num int `json:"num"`
Oid string `json:"oid"`
GoodsSnapshot string `json:"goods_snapshot"`
Title string `json:"title"`
FenxiaoPayment string `json:"fenxiao_payment"`
ItemNo string `json:"item_no"`
BuyerMessages string `json:"buyer_messages"`
RootSkuId string `json:"root_sku_id"`
IsPresent bool `json:"is_present"`
CrossBorderTradeMode string `json:"cross_border_trade_mode"`
Price string `json:"price"`
SubOrderNo string `json:"sub_order_no"`
TotalFee string `json:"total_fee"`
FenxiaoPrice string `json:"fenxiao_price"`
SalePlan struct {
Penalty struct {
} `json:"penalty"`
CancelRuleTime struct {
} `json:"cancel_rule_time"`
} `json:"sale_plan"`
Alias string `json:"alias"`
Payment string `json:"payment"`
ItemBarcode string `json:"item_barcode"`
IsPreSale string `json:"is_pre_sale"`
OuterSkuId string `json:"outer_sku_id"`
SkuUniqueCode string `json:"sku_unique_code"`
GoodsUrl string `json:"goods_url"`
CustomsCode string `json:"customs_code"`
IsPriceCalendar string `json:"is_price_calendar"`
ItemId int64 `json:"item_id"`
Weight string `json:"weight"`
SkuId int `json:"sku_id"`
SkuPropertiesName string `json:"sku_properties_name"`
PicPath string `json:"pic_path"`
ShopOrgId string `json:"shop_org_id"`
OuterOid string `json:"outer_oid"`
PreSaleType string `json:"pre_sale_type"`
PointsPrice string `json:"points_price"`
SkuNo string `json:"sku_no"`
RootItemId string `json:"root_item_id"`
SkuBarcode string `json:"sku_barcode"`
ItemProps string `json:"item_props"`
} `json:"orders"`
SourceInfo struct {
IsOfflineOrder bool `json:"is_offline_order"`
BookKey string `json:"book_key"`
BizSource string `json:"biz_source"`
Source struct {
Platform string `json:"platform"`
WxEntrance string `json:"wx_entrance"`
} `json:"source"`
} `json:"source_info"`
OrderInfo struct {
ConsignTime string `json:"consign_time"`
OrderExtra struct {
IsFromCart string `json:"is_from_cart"`
BuyerName string `json:"buyer_name"`
ForceConsignmentMode string `json:"force_consignment_mode"`
IsPointsOrder string `json:"is_points_order"`
} `json:"order_extra"`
ExpiredTime string `json:"expired_time"`
Type int `json:"type"`
Tid string `json:"tid"`
NodeKdtId int `json:"node_kdt_id"`
UpdateTime string `json:"update_time"`
PayTypeStr string `json:"pay_type_str"`
PayType int `json:"pay_type"`
TeamType int `json:"team_type"`
ChannelType int `json:"channel_type"`
Created string `json:"created"`
StatusStr string `json:"status_str"`
SuccessTime string `json:"success_time"`
ShopName string `json:"shop_name"`
ConfirmTime string `json:"confirm_time"`
PayTime string `json:"pay_time"`
IsRetailOrder bool `json:"is_retail_order"`
PayTypeDesc string `json:"pay_type_desc"`
RefundState int `json:"refund_state"`
RootKdtId int `json:"root_kdt_id"`
CloseType int `json:"close_type"`
Status string `json:"status"` //主订单状态: WAIT_BUYER_PAY:等待买家付款,定金预售描述:定金待付、等待尾款支付开始、尾款待付, TRADE_PAID:订单已支付 ,该状态仅代表当前订单已支付成功,表示瞬时状态,稍后会自动修改成后面的状态。如果不关心此状态请再次请求详情接口获取下一个状态, WAIT_CONFIRM:待确认,包含待成团、待接单等等。即:买家已付款,等待成团或等待接单, WAIT_SELLER_SEND_GOODS:等待卖家发货,即:买家已付款, WAIT_BUYER_CONFIRM_GOODS 等待买家确认收货,即:卖家已发货, TRADE_SUCCESS:买家已签收以及订单成功, TRADE_CLOSED:交易关闭
ExpressType int `json:"express_type"`
OrderTags struct {
IsMember bool `json:"is_member"`
IsSecuredTransactions bool `json:"is_secured_transactions"`
IsPayed bool `json:"is_payed"`
} `json:"order_tags"`
} `json:"order_info"`
} `json:"full_order_info"`
} `json:"data"`
Success bool `json:"success"`
Message string `json:"message"`
}
func (s orderLogic) Detail(ctx context.Context, req string) (res *OrderDetailRes, err error) {
method := "youzan.trade.get/4.0.2"
result, err := server.requestApi(ctx, method, g.Map{
"tid": req,
})
if err != nil {
return
}
err = json.Unmarshal([]byte(result), &res)
return
}
package yz
import (
"context"
"encoding/json"
"github.com/gogf/gf/frame/g"
)
type secretLogic struct {
}
var Secret = secretLogic{}
type SecretDecryptRes struct {
TraceId string `json:"trace_id"`
Code int `json:"code"`
Data string `json:"data"`
Success bool `json:"success"`
Message string `json:"message"`
}
func (s secretLogic) Decrypt(ctx context.Context, req string) (res *SecretDecryptRes, err error) {
method := "youzan.cloud.secret.decrypt.single/1.0.0"
result, err := server.requestApi(ctx, method, g.Map{
"source": req,
})
if err != nil {
return
}
err = json.Unmarshal([]byte(result), &res)
return
}
type SecretDecryptBatchRes struct {
TraceId string `json:"trace_id"`
Code int `json:"code"`
Data map[string]string `json:"data"`
Success bool `json:"success"`
Message string `json:"message"`
}
func (s secretLogic) DecryptBatch(ctx context.Context, req []string) (res *SecretDecryptBatchRes, err error) {
method := "youzan.cloud.secret.decrypt.batch/1.0.0"
result, err := server.requestApi(ctx, method, g.Map{
"sources": req,
})
if err != nil {
return
}
err = json.Unmarshal([]byte(result), &res)
return
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论