Skip to content

Commit

Permalink
udpate
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoogle-ink committed Jun 1, 2024
1 parent 6bb1a46 commit f1b0cc3
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 33 deletions.
29 changes: 29 additions & 0 deletions alipay/ant.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,32 @@ func (a *Client) AntMerchantShopClose(ctx context.Context, bm gopay.BodyMap) (al
aliRsp.SignData = signData
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
}

// ant.merchant.expand.indirect.image.upload(图片上传)
// bm参数中 image_content 可不传,file为必传参数
// 文档地址:https://opendocs.alipay.com/open/04fgwt
func (a *Client) AntMerchantExpandIndirectImageUpload(ctx context.Context, bm gopay.BodyMap, file *gopay.File) (aliRsp *AntMerchantExpandIndirectImageUploadRsp, err error) {
if file == nil {
return nil, fmt.Errorf("file is nil")
}
err = bm.CheckEmptyError("image_type")
if err != nil {
return nil, err
}
bm.Set("image_content", file)
var bs []byte
if bs, err = a.FileUploadRequest(ctx, bm, file, "ant.merchant.expand.indirect.image.upload"); err != nil {
return nil, err
}
aliRsp = new(AntMerchantExpandIndirectImageUploadRsp)
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, err
}
if aliRsp.Response != nil && aliRsp.Response.Code != "10000" {
info := aliRsp.Response
return aliRsp, fmt.Errorf(`{"code":"%s","msg":"%s","sub_code":"%s","sub_msg":"%s"}`, info.Code, info.Msg, info.SubCode, info.SubMsg)
}
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
aliRsp.SignData = signData
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
}
6 changes: 5 additions & 1 deletion alipay/goods_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ import (
// alipay.merchant.item.file.upload(商品文件上传接口)
// 文档地址:https://opendocs.alipay.com/apis/api_4/alipay.merchant.item.file.upload
func (a *Client) MerchantItemFileUpload(ctx context.Context, file *gopay.File) (aliRsp *MerchantItemFileUploadRsp, err error) {
if file == nil {
return nil, fmt.Errorf("file is nil")
}
bm := make(gopay.BodyMap)
bm.Set("scene", "SYNC_ORDER") //素材固定值
bm.Set("file_content", file) //素材固定值

var bs []byte
if bs, err = a.FileRequest(ctx, bm, file, "alipay.merchant.item.file.upload"); err != nil {
if bs, err = a.FileUploadRequest(ctx, bm, file, "alipay.merchant.item.file.upload"); err != nil {
return nil, err
}
aliRsp = new(MerchantItemFileUploadRsp)
Expand Down
10 changes: 9 additions & 1 deletion alipay/marketing_voucher.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ import (
)

// alipay.marketing.material.image.upload(营销图片资源上传接口)
// bm参数中 file_content 可不传,file为必传参数
// 文档地址:https://opendocs.alipay.com/open/389b24b6_alipay.marketing.material.image.upload
func (a *Client) MarketingMaterialImageUpload(ctx context.Context, bm gopay.BodyMap, file *gopay.File) (aliRsp *MarketingMaterialImageUploadRsp, err error) {
if file == nil {
return nil, fmt.Errorf("file is nil")
}
if err = bm.CheckEmptyError("file_key"); err != nil {
return nil, err
}
bm.Set("file_content", file)
var bs []byte
if bs, err = a.FileRequest(ctx, bm, file, "alipay.marketing.material.image.upload"); err != nil {
if bs, err = a.FileUploadRequest(ctx, bm, file, "alipay.marketing.material.image.upload"); err != nil {
return nil, err
}
aliRsp = new(MarketingMaterialImageUploadRsp)
Expand Down
12 changes: 12 additions & 0 deletions alipay/model_ant.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ type AntMerchantShopCloseRsp struct {
Sign string `json:"sign"`
}

type AntMerchantExpandIndirectImageUploadRsp struct {
Response *AntMerchantExpandIndirectImageUpload `json:"ant_merchant_expand_indirect_image_upload_response"`
AlipayCertSn string `json:"alipay_cert_sn,omitempty"`
SignData string `json:"-"`
Sign string `json:"sign"`
}

// =========================================================分割=========================================================

type AntMerchantShopModify struct {
Expand Down Expand Up @@ -130,3 +137,8 @@ type AntMerchantShopQuery struct {
type AntMerchantShopClose struct {
ErrorResponse
}

type AntMerchantExpandIndirectImageUpload struct {
ErrorResponse
ImageId string `json:"image_id"`
}
50 changes: 21 additions & 29 deletions alipay/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,20 @@ func (a *Client) doAliPay(ctx context.Context, bm gopay.BodyMap, method string,
)
if bm != nil {
_, has := appAuthTokenInBizContent[method]
if has {
if !has {
aat := bm.GetString("app_auth_token")
bm.Remove("app_auth_token")
if bodyBs, err = json.Marshal(bm); err != nil {
return nil, fmt.Errorf("json.Marshal:%w", err)
}
bizContent = string(bodyBs)
bm.Remove("app_auth_token")
bm.Set("app_auth_token", aat)
} else {
aat := bm.GetString("app_auth_token")
bm.Remove("app_auth_token")
if bodyBs, err = json.Marshal(bm); err != nil {
return nil, fmt.Errorf("json.Marshal:%w", err)
}
bizContent = string(bodyBs)
bm.Set("app_auth_token", aat)
bm.Remove("app_auth_token")
}
}
// 处理公共参数
Expand Down Expand Up @@ -196,20 +196,20 @@ func (a *Client) DoAliPay(ctx context.Context, bm gopay.BodyMap, method string,
)
if bm != nil {
_, has := appAuthTokenInBizContent[method]
if has {
if !has {
aat := bm.GetString("app_auth_token")
bm.Remove("app_auth_token")
if bodyBs, err = json.Marshal(bm); err != nil {
return nil, fmt.Errorf("json.Marshal:%w", err)
}
bizContent = string(bodyBs)
bm.Remove("app_auth_token")
bm.Set("app_auth_token", aat)
} else {
aat := bm.GetString("app_auth_token")
bm.Remove("app_auth_token")
if bodyBs, err = json.Marshal(bm); err != nil {
return nil, fmt.Errorf("json.Marshal:%w", err)
}
bizContent = string(bodyBs)
bm.Set("app_auth_token", aat)
bm.Remove("app_auth_token")
}
}
// 处理公共参数
Expand Down Expand Up @@ -252,20 +252,20 @@ func (a *Client) PageExecute(ctx context.Context, bm gopay.BodyMap, method strin
)
if bm != nil {
_, has := appAuthTokenInBizContent[method]
if has {
if !has {
aat := bm.GetString("app_auth_token")
bm.Remove("app_auth_token")
if bodyBs, err = json.Marshal(bm); err != nil {
return "", fmt.Errorf("json.Marshal:%w", err)
}
bizContent = string(bodyBs)
bm.Remove("app_auth_token")
bm.Set("app_auth_token", aat)
} else {
aat := bm.GetString("app_auth_token")
bm.Remove("app_auth_token")
if bodyBs, err = json.Marshal(bm); err != nil {
return "", fmt.Errorf("json.Marshal:%w", err)
}
bizContent = string(bodyBs)
bm.Set("app_auth_token", aat)
bm.Remove("app_auth_token")
}
}
// 处理公共参数
Expand All @@ -281,19 +281,13 @@ func (a *Client) PageExecute(ctx context.Context, bm gopay.BodyMap, method strin
}

// 文件上传
func (a *Client) FileRequest(ctx context.Context, bm gopay.BodyMap, file *gopay.File, method string) (bs []byte, err error) {
func (a *Client) FileUploadRequest(ctx context.Context, bm gopay.BodyMap, file *gopay.File, method string) (bs []byte, err error) {
var (
bodyStr string
bodyBs []byte
aat string
aat string
)
if bm != nil {
aat = bm.GetString("app_auth_token")
bm.Remove("app_auth_token")
if bodyBs, err = json.Marshal(bm); err != nil {
return nil, fmt.Errorf("json.Marshal:%w", err)
}
bodyStr = string(bodyBs)
}
pubBody := make(gopay.BodyMap)
pubBody.Set("app_id", a.AppId).
Expand All @@ -302,7 +296,6 @@ func (a *Client) FileRequest(ctx context.Context, bm gopay.BodyMap, file *gopay.
Set("charset", a.Charset).
Set("sign_type", a.SignType).
Set("version", "1.0").
Set("scene", "SYNC_ORDER").
Set("timestamp", time.Now().Format(xtime.TimeLayout))

if a.AppCertSN != gopay.NULL {
Expand All @@ -320,15 +313,15 @@ func (a *Client) FileRequest(ctx context.Context, bm gopay.BodyMap, file *gopay.
if a.NotifyUrl != gopay.NULL {
pubBody.Set("notify_url", a.NotifyUrl)
}
// default use app_auth_token
if a.AppAuthToken != gopay.NULL {
pubBody.Set("app_auth_token", a.AppAuthToken)
}
// if user set app_auth_token in body_map, use this
if aat != gopay.NULL {
pubBody.Set("app_auth_token", aat)
}
if bodyStr != gopay.NULL {
pubBody.Set("biz_content", bodyStr)
}
// sign
sign, err := a.getRsaSign(pubBody, pubBody.GetString("sign_type"))
if err != nil {
return nil, fmt.Errorf("GetRsaSign Error: %w", err)
Expand All @@ -340,8 +333,7 @@ func (a *Client) FileRequest(ctx context.Context, bm gopay.BodyMap, file *gopay.
}
param := pubBody.EncodeURLParams()
url := baseUrlUtf8 + "&" + param
bm.Reset()
bm.SetFormFile("file_content", file)

res, bs, err := a.hc.Req(xhttp.TypeMultipartFormData).Post(url).
SendMultipartBodyMap(bm).EndBytes(ctx)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion doc/alipay.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ xlog.Infof("%+v", phone)
* 店铺分页查询接口:TODO:https://opendocs.alipay.com/open/04fgwq
* 店铺查询接口:`client.AntMerchantShopQuery()`
* 蚂蚁店铺关闭接口:`client.AntMerchantShopClose()`
* 图片上传接口:TODO:https://opendocs.alipay.com/open/04fgwt
* 图片上传接口:`client.AntMerchantExpandIndirectImageUpload()`
* 商户mcc信息查询接口:TODO:https://opendocs.alipay.com/open/04fgwu
* 店铺增加收单账号接口:TODO:https://opendocs.alipay.com/open/54b69b89_ant.merchant.expand.shop.receiptaccount.save
* 商家券 2.0
Expand Down
2 changes: 1 addition & 1 deletion release_note.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
(12) 支付宝:新增 client.MarketingActivityDeliveryQuery(),查询推广计划接口。
(13) 支付宝:新增 client.MarketingActivityDeliveryStop(),停止推广计划接口。
(14) 支付宝:新增 client.MarketingMaterialImageUpload(),营销图片资源上传接口。
(15) 支付宝:新增 client.AntMerchantExpandIndirectImageUpload(),图片上传接口。


(15) 支付宝:新增 client.ZolozAuthenticationCustomerSmilepayQuery(),刷脸支付初始化接口。
(16) 支付宝:新增 client.ZolozAuthenticationCustomerSmilepayQuery(),刷脸支付初始化接口。
(17) 支付宝:新增 client.ZolozAuthenticationCustomerSmilepayQuery(),刷脸支付初始化接口。
(18) 支付宝:新增 client.ZolozAuthenticationCustomerSmilepayQuery(),刷脸支付初始化接口。
Expand Down

0 comments on commit f1b0cc3

Please sign in to comment.