Skip to content

Commit f1b0cc3

Browse files
committed
udpate
1 parent 6bb1a46 commit f1b0cc3

7 files changed

+78
-33
lines changed

alipay/ant.go

+29
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,32 @@ func (a *Client) AntMerchantShopClose(ctx context.Context, bm gopay.BodyMap) (al
133133
aliRsp.SignData = signData
134134
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
135135
}
136+
137+
// ant.merchant.expand.indirect.image.upload(图片上传)
138+
// bm参数中 image_content 可不传,file为必传参数
139+
// 文档地址:https://opendocs.alipay.com/open/04fgwt
140+
func (a *Client) AntMerchantExpandIndirectImageUpload(ctx context.Context, bm gopay.BodyMap, file *gopay.File) (aliRsp *AntMerchantExpandIndirectImageUploadRsp, err error) {
141+
if file == nil {
142+
return nil, fmt.Errorf("file is nil")
143+
}
144+
err = bm.CheckEmptyError("image_type")
145+
if err != nil {
146+
return nil, err
147+
}
148+
bm.Set("image_content", file)
149+
var bs []byte
150+
if bs, err = a.FileUploadRequest(ctx, bm, file, "ant.merchant.expand.indirect.image.upload"); err != nil {
151+
return nil, err
152+
}
153+
aliRsp = new(AntMerchantExpandIndirectImageUploadRsp)
154+
if err = json.Unmarshal(bs, aliRsp); err != nil {
155+
return nil, err
156+
}
157+
if aliRsp.Response != nil && aliRsp.Response.Code != "10000" {
158+
info := aliRsp.Response
159+
return aliRsp, fmt.Errorf(`{"code":"%s","msg":"%s","sub_code":"%s","sub_msg":"%s"}`, info.Code, info.Msg, info.SubCode, info.SubMsg)
160+
}
161+
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
162+
aliRsp.SignData = signData
163+
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
164+
}

alipay/goods_api.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ import (
1111
// alipay.merchant.item.file.upload(商品文件上传接口)
1212
// 文档地址:https://opendocs.alipay.com/apis/api_4/alipay.merchant.item.file.upload
1313
func (a *Client) MerchantItemFileUpload(ctx context.Context, file *gopay.File) (aliRsp *MerchantItemFileUploadRsp, err error) {
14+
if file == nil {
15+
return nil, fmt.Errorf("file is nil")
16+
}
1417
bm := make(gopay.BodyMap)
1518
bm.Set("scene", "SYNC_ORDER") //素材固定值
19+
bm.Set("file_content", file) //素材固定值
1620

1721
var bs []byte
18-
if bs, err = a.FileRequest(ctx, bm, file, "alipay.merchant.item.file.upload"); err != nil {
22+
if bs, err = a.FileUploadRequest(ctx, bm, file, "alipay.merchant.item.file.upload"); err != nil {
1923
return nil, err
2024
}
2125
aliRsp = new(MerchantItemFileUploadRsp)

alipay/marketing_voucher.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@ import (
99
)
1010

1111
// alipay.marketing.material.image.upload(营销图片资源上传接口)
12+
// bm参数中 file_content 可不传,file为必传参数
1213
// 文档地址:https://opendocs.alipay.com/open/389b24b6_alipay.marketing.material.image.upload
1314
func (a *Client) MarketingMaterialImageUpload(ctx context.Context, bm gopay.BodyMap, file *gopay.File) (aliRsp *MarketingMaterialImageUploadRsp, err error) {
15+
if file == nil {
16+
return nil, fmt.Errorf("file is nil")
17+
}
18+
if err = bm.CheckEmptyError("file_key"); err != nil {
19+
return nil, err
20+
}
21+
bm.Set("file_content", file)
1422
var bs []byte
15-
if bs, err = a.FileRequest(ctx, bm, file, "alipay.marketing.material.image.upload"); err != nil {
23+
if bs, err = a.FileUploadRequest(ctx, bm, file, "alipay.marketing.material.image.upload"); err != nil {
1624
return nil, err
1725
}
1826
aliRsp = new(MarketingMaterialImageUploadRsp)

alipay/model_ant.go

+12
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ type AntMerchantShopCloseRsp struct {
4242
Sign string `json:"sign"`
4343
}
4444

45+
type AntMerchantExpandIndirectImageUploadRsp struct {
46+
Response *AntMerchantExpandIndirectImageUpload `json:"ant_merchant_expand_indirect_image_upload_response"`
47+
AlipayCertSn string `json:"alipay_cert_sn,omitempty"`
48+
SignData string `json:"-"`
49+
Sign string `json:"sign"`
50+
}
51+
4552
// =========================================================分割=========================================================
4653

4754
type AntMerchantShopModify struct {
@@ -130,3 +137,8 @@ type AntMerchantShopQuery struct {
130137
type AntMerchantShopClose struct {
131138
ErrorResponse
132139
}
140+
141+
type AntMerchantExpandIndirectImageUpload struct {
142+
ErrorResponse
143+
ImageId string `json:"image_id"`
144+
}

alipay/request.go

+21-29
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,20 @@ func (a *Client) doAliPay(ctx context.Context, bm gopay.BodyMap, method string,
140140
)
141141
if bm != nil {
142142
_, has := appAuthTokenInBizContent[method]
143-
if has {
143+
if !has {
144+
aat := bm.GetString("app_auth_token")
145+
bm.Remove("app_auth_token")
144146
if bodyBs, err = json.Marshal(bm); err != nil {
145147
return nil, fmt.Errorf("json.Marshal:%w", err)
146148
}
147149
bizContent = string(bodyBs)
148-
bm.Remove("app_auth_token")
150+
bm.Set("app_auth_token", aat)
149151
} else {
150-
aat := bm.GetString("app_auth_token")
151-
bm.Remove("app_auth_token")
152152
if bodyBs, err = json.Marshal(bm); err != nil {
153153
return nil, fmt.Errorf("json.Marshal:%w", err)
154154
}
155155
bizContent = string(bodyBs)
156-
bm.Set("app_auth_token", aat)
156+
bm.Remove("app_auth_token")
157157
}
158158
}
159159
// 处理公共参数
@@ -196,20 +196,20 @@ func (a *Client) DoAliPay(ctx context.Context, bm gopay.BodyMap, method string,
196196
)
197197
if bm != nil {
198198
_, has := appAuthTokenInBizContent[method]
199-
if has {
199+
if !has {
200+
aat := bm.GetString("app_auth_token")
201+
bm.Remove("app_auth_token")
200202
if bodyBs, err = json.Marshal(bm); err != nil {
201203
return nil, fmt.Errorf("json.Marshal:%w", err)
202204
}
203205
bizContent = string(bodyBs)
204-
bm.Remove("app_auth_token")
206+
bm.Set("app_auth_token", aat)
205207
} else {
206-
aat := bm.GetString("app_auth_token")
207-
bm.Remove("app_auth_token")
208208
if bodyBs, err = json.Marshal(bm); err != nil {
209209
return nil, fmt.Errorf("json.Marshal:%w", err)
210210
}
211211
bizContent = string(bodyBs)
212-
bm.Set("app_auth_token", aat)
212+
bm.Remove("app_auth_token")
213213
}
214214
}
215215
// 处理公共参数
@@ -252,20 +252,20 @@ func (a *Client) PageExecute(ctx context.Context, bm gopay.BodyMap, method strin
252252
)
253253
if bm != nil {
254254
_, has := appAuthTokenInBizContent[method]
255-
if has {
255+
if !has {
256+
aat := bm.GetString("app_auth_token")
257+
bm.Remove("app_auth_token")
256258
if bodyBs, err = json.Marshal(bm); err != nil {
257259
return "", fmt.Errorf("json.Marshal:%w", err)
258260
}
259261
bizContent = string(bodyBs)
260-
bm.Remove("app_auth_token")
262+
bm.Set("app_auth_token", aat)
261263
} else {
262-
aat := bm.GetString("app_auth_token")
263-
bm.Remove("app_auth_token")
264264
if bodyBs, err = json.Marshal(bm); err != nil {
265265
return "", fmt.Errorf("json.Marshal:%w", err)
266266
}
267267
bizContent = string(bodyBs)
268-
bm.Set("app_auth_token", aat)
268+
bm.Remove("app_auth_token")
269269
}
270270
}
271271
// 处理公共参数
@@ -281,19 +281,13 @@ func (a *Client) PageExecute(ctx context.Context, bm gopay.BodyMap, method strin
281281
}
282282

283283
// 文件上传
284-
func (a *Client) FileRequest(ctx context.Context, bm gopay.BodyMap, file *gopay.File, method string) (bs []byte, err error) {
284+
func (a *Client) FileUploadRequest(ctx context.Context, bm gopay.BodyMap, file *gopay.File, method string) (bs []byte, err error) {
285285
var (
286-
bodyStr string
287-
bodyBs []byte
288-
aat string
286+
aat string
289287
)
290288
if bm != nil {
291289
aat = bm.GetString("app_auth_token")
292290
bm.Remove("app_auth_token")
293-
if bodyBs, err = json.Marshal(bm); err != nil {
294-
return nil, fmt.Errorf("json.Marshal:%w", err)
295-
}
296-
bodyStr = string(bodyBs)
297291
}
298292
pubBody := make(gopay.BodyMap)
299293
pubBody.Set("app_id", a.AppId).
@@ -302,7 +296,6 @@ func (a *Client) FileRequest(ctx context.Context, bm gopay.BodyMap, file *gopay.
302296
Set("charset", a.Charset).
303297
Set("sign_type", a.SignType).
304298
Set("version", "1.0").
305-
Set("scene", "SYNC_ORDER").
306299
Set("timestamp", time.Now().Format(xtime.TimeLayout))
307300

308301
if a.AppCertSN != gopay.NULL {
@@ -320,15 +313,15 @@ func (a *Client) FileRequest(ctx context.Context, bm gopay.BodyMap, file *gopay.
320313
if a.NotifyUrl != gopay.NULL {
321314
pubBody.Set("notify_url", a.NotifyUrl)
322315
}
316+
// default use app_auth_token
323317
if a.AppAuthToken != gopay.NULL {
324318
pubBody.Set("app_auth_token", a.AppAuthToken)
325319
}
320+
// if user set app_auth_token in body_map, use this
326321
if aat != gopay.NULL {
327322
pubBody.Set("app_auth_token", aat)
328323
}
329-
if bodyStr != gopay.NULL {
330-
pubBody.Set("biz_content", bodyStr)
331-
}
324+
// sign
332325
sign, err := a.getRsaSign(pubBody, pubBody.GetString("sign_type"))
333326
if err != nil {
334327
return nil, fmt.Errorf("GetRsaSign Error: %w", err)
@@ -340,8 +333,7 @@ func (a *Client) FileRequest(ctx context.Context, bm gopay.BodyMap, file *gopay.
340333
}
341334
param := pubBody.EncodeURLParams()
342335
url := baseUrlUtf8 + "&" + param
343-
bm.Reset()
344-
bm.SetFormFile("file_content", file)
336+
345337
res, bs, err := a.hc.Req(xhttp.TypeMultipartFormData).Post(url).
346338
SendMultipartBodyMap(bm).EndBytes(ctx)
347339
if err != nil {

doc/alipay.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ xlog.Infof("%+v", phone)
312312
* 店铺分页查询接口:TODO:https://opendocs.alipay.com/open/04fgwq
313313
* 店铺查询接口:`client.AntMerchantShopQuery()`
314314
* 蚂蚁店铺关闭接口:`client.AntMerchantShopClose()`
315-
* 图片上传接口:TODO:https://opendocs.alipay.com/open/04fgwt
315+
* 图片上传接口:`client.AntMerchantExpandIndirectImageUpload()`
316316
* 商户mcc信息查询接口:TODO:https://opendocs.alipay.com/open/04fgwu
317317
* 店铺增加收单账号接口:TODO:https://opendocs.alipay.com/open/54b69b89_ant.merchant.expand.shop.receiptaccount.save
318318
* 商家券 2.0

release_note.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
(12) 支付宝:新增 client.MarketingActivityDeliveryQuery(),查询推广计划接口。
1515
(13) 支付宝:新增 client.MarketingActivityDeliveryStop(),停止推广计划接口。
1616
(14) 支付宝:新增 client.MarketingMaterialImageUpload(),营销图片资源上传接口。
17+
(15) 支付宝:新增 client.AntMerchantExpandIndirectImageUpload(),图片上传接口。
1718

1819

19-
(15) 支付宝:新增 client.ZolozAuthenticationCustomerSmilepayQuery(),刷脸支付初始化接口。
2020
(16) 支付宝:新增 client.ZolozAuthenticationCustomerSmilepayQuery(),刷脸支付初始化接口。
2121
(17) 支付宝:新增 client.ZolozAuthenticationCustomerSmilepayQuery(),刷脸支付初始化接口。
2222
(18) 支付宝:新增 client.ZolozAuthenticationCustomerSmilepayQuery(),刷脸支付初始化接口。

0 commit comments

Comments
 (0)