Skip to content

Commit

Permalink
udpate
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoogle-ink committed Jun 2, 2024
1 parent f1b0cc3 commit 7454003
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 5 deletions.
2 changes: 1 addition & 1 deletion alipay/ant.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (a *Client) AntMerchantExpandIndirectImageUpload(ctx context.Context, bm go
}
bm.Set("image_content", file)
var bs []byte
if bs, err = a.FileUploadRequest(ctx, bm, file, "ant.merchant.expand.indirect.image.upload"); err != nil {
if bs, err = a.FileUploadRequest(ctx, bm, "ant.merchant.expand.indirect.image.upload"); err != nil {
return nil, err
}
aliRsp = new(AntMerchantExpandIndirectImageUploadRsp)
Expand Down
29 changes: 29 additions & 0 deletions alipay/ant_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package alipay

import (
"io"
"os"
"testing"

"github.com/go-pay/gopay"
Expand Down Expand Up @@ -112,3 +114,30 @@ func TestAntMerchantShopClose(t *testing.T) {
}
xlog.Debug("aliRsp:", *aliRsp)
}

func TestAntMerchantExpandIndirectImageUpload(t *testing.T) {
// 请求参数
logo, err := os.Open("../logo.png")
if err != nil {
xlog.Errorf("os.Open(%s),error:%+v", "../logo.png", err)
return
}
xlog.Warnf("fileName: %s", logo.Name())
allBs, err := io.ReadAll(logo)
if err != nil {
xlog.Errorf("io.ReadAll(%s),error:%+v", logo.Name(), err)
return
}
f := &gopay.File{
Name: "logo",
Content: allBs,
}
bm := make(gopay.BodyMap)
bm.Set("image_type", "png")
aliRsp, err := client.AntMerchantExpandIndirectImageUpload(ctx, bm, f)
if err != nil {
xlog.Errorf("client.AntMerchantExpandIndirectImageUpload(),error:%+v", err)
return
}
xlog.Debug("aliRsp:", *aliRsp)
}
2 changes: 1 addition & 1 deletion alipay/goods_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (a *Client) MerchantItemFileUpload(ctx context.Context, file *gopay.File) (
bm.Set("file_content", file) //素材固定值

var bs []byte
if bs, err = a.FileUploadRequest(ctx, bm, file, "alipay.merchant.item.file.upload"); err != nil {
if bs, err = a.FileUploadRequest(ctx, bm, "alipay.merchant.item.file.upload"); err != nil {
return nil, err
}
aliRsp = new(MerchantItemFileUploadRsp)
Expand Down
35 changes: 35 additions & 0 deletions alipay/goods_api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package alipay

import (
"io"
"os"
"testing"

"github.com/go-pay/gopay"
"github.com/go-pay/xlog"
)

func TestMerchantItemFileUpload(t *testing.T) {
// 请求参数
logo, err := os.Open("../logo.png")
if err != nil {
xlog.Errorf("os.Open(%s),error:%+v", "../logo.png", err)
return
}
xlog.Warnf("fileName: %s", logo.Name())
allBs, err := io.ReadAll(logo)
if err != nil {
xlog.Errorf("io.ReadAll(%s),error:%+v", logo.Name(), err)
return
}
f := &gopay.File{
Name: "logo",
Content: allBs,
}
aliRsp, err := client.MerchantItemFileUpload(ctx, f)
if err != nil {
xlog.Errorf("client.AntMerchantExpandIndirectImageUpload(),error:%+v", err)
return
}
xlog.Debug("aliRsp:", *aliRsp)
}
30 changes: 30 additions & 0 deletions alipay/marketing_api_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package alipay

import (
"io"
"os"
"testing"

"github.com/go-pay/gopay"
Expand Down Expand Up @@ -104,3 +106,31 @@ func TestMarketingCampaignCashDetailQuery(t *testing.T) {
}
xlog.Debug("aliRsp.Response:", aliRsp.Response)
}

func TestMarketingMaterialImageUpload(t *testing.T) {
// 请求参数
logo, err := os.Open("../logo.png")
if err != nil {
xlog.Errorf("os.Open(%s),error:%+v", "../logo.png", err)
return
}
xlog.Warnf("fileName: %s", logo.Name())
allBs, err := io.ReadAll(logo)
if err != nil {
xlog.Errorf("io.ReadAll(%s),error:%+v", logo.Name(), err)
return
}
f := &gopay.File{
Name: "logo",
Content: allBs,
}
bm := make(gopay.BodyMap)
bm.Set("file_key", "PROMO_VOUCHER_IMAGE").
Set("merchant_access_mode", "SELF_MODE")
aliRsp, err := client.MarketingMaterialImageUpload(ctx, bm, f)
if err != nil {
xlog.Errorf("client.AntMerchantExpandIndirectImageUpload(),error:%+v", err)
return
}
xlog.Debug("aliRsp:", *aliRsp)
}
2 changes: 1 addition & 1 deletion alipay/marketing_voucher.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (a *Client) MarketingMaterialImageUpload(ctx context.Context, bm gopay.Body
}
bm.Set("file_content", file)
var bs []byte
if bs, err = a.FileUploadRequest(ctx, bm, file, "alipay.marketing.material.image.upload"); err != nil {
if bs, err = a.FileUploadRequest(ctx, bm, "alipay.marketing.material.image.upload"); err != nil {
return nil, err
}
aliRsp = new(MarketingMaterialImageUploadRsp)
Expand Down
11 changes: 9 additions & 2 deletions alipay/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (a *Client) PageExecute(ctx context.Context, bm gopay.BodyMap, method strin
}

// 文件上传
func (a *Client) FileUploadRequest(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, method string) (bs []byte, err error) {
var (
aat string
)
Expand Down Expand Up @@ -321,12 +321,19 @@ func (a *Client) FileUploadRequest(ctx context.Context, bm gopay.BodyMap, file *
if aat != gopay.NULL {
pubBody.Set("app_auth_token", aat)
}
// 文件也需要签名
for k, v := range bm {
pubBody.Set(k, v)
}
// sign
sign, err := a.getRsaSign(pubBody, pubBody.GetString("sign_type"))
if err != nil {
return nil, fmt.Errorf("GetRsaSign Error: %w", err)
}
//pubBody.Set("file_content", file.Content)
// 文件签名完移除query params
for k, _ := range bm {
pubBody.Remove(k)
}
pubBody.Set("sign", sign)
if a.DebugSwitch == gopay.DebugOn {
xlog.Debugf("Alipay_Request: %s", pubBody.JsonBody())
Expand Down

0 comments on commit 7454003

Please sign in to comment.