Skip to content

Commit

Permalink
Merge branch 'go-pay:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
rickycoder authored May 14, 2024
2 parents 618c099 + 13a1eb5 commit f3a476c
Show file tree
Hide file tree
Showing 14 changed files with 1,558 additions and 87 deletions.
212 changes: 212 additions & 0 deletions alipay/marketing_activity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
package alipay

import (
"context"
"encoding/json"
"fmt"

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

// alipay.marketing.activity.batchquery(条件查询活动列表)
// 文档地址:https://opendocs.alipay.com/open/04fgw9
func (a *Client) MarketingActivityBatchQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *MarketingActivityBatchQueryRsp, err error) {
err = bm.CheckEmptyError("page_num", "page_size", "merchant_access_mode")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(ctx, bm, "alipay.marketing.activity.batchquery"); err != nil {
return nil, err
}
aliRsp = new(MarketingActivityBatchQueryRsp)
if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
return aliRsp, err
}
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
aliRsp.SignData = signData
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
}

// alipay.marketing.activity.consult(活动领取咨询接口)
// 文档地址:https://opendocs.alipay.com/open/04fgwa
func (a *Client) MarketingActivityConsult(ctx context.Context, bm gopay.BodyMap) (aliRsp *MarketingActivityConsultRsp, err error) {
err = bm.CheckEmptyError("consult_activity_info_list", "merchant_access_mode")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(ctx, bm, "alipay.marketing.activity.consult"); err != nil {
return nil, err
}
aliRsp = new(MarketingActivityConsultRsp)
if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
return aliRsp, err
}
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
aliRsp.SignData = signData
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
}

// alipay.marketing.activity.query(查询活动详情)
// 文档地址:https://opendocs.alipay.com/open/04fgwb
func (a *Client) MarketingActivityQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *MarketingActivityQueryRsp, err error) {
err = bm.CheckEmptyError("activity_id", "merchant_access_mode")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(ctx, bm, "alipay.marketing.activity.query"); err != nil {
return nil, err
}
aliRsp = new(MarketingActivityQueryRsp)
if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
return aliRsp, err
}
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
aliRsp.SignData = signData
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
}

// alipay.marketing.activity.merchant.batchquery(查询活动可用商户)
// 文档地址:https://opendocs.alipay.com/open/04fgwc
func (a *Client) MarketingActivityQueryMerchantBatchQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *MarketingActivityQueryMerchantBatchQueryRsp, err error) {
err = bm.CheckEmptyError("activity_id", "page_num", "page_size")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(ctx, bm, "alipay.marketing.activity.merchant.batchquery"); err != nil {
return nil, err
}
aliRsp = new(MarketingActivityQueryMerchantBatchQueryRsp)
if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
return aliRsp, err
}
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
aliRsp.SignData = signData
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
}

// alipay.marketing.activity.app.batchquery(查询活动可用小程序)
// 文档地址:https://opendocs.alipay.com/open/04fgwd
func (a *Client) MarketingActivityQueryAppBatchQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *MarketingActivityQueryAppBatchQueryRsp, err error) {
err = bm.CheckEmptyError("activity_id", "page_num", "page_size", "merchant_access_mode")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(ctx, bm, "alipay.marketing.activity.app.batchquery"); err != nil {
return nil, err
}
aliRsp = new(MarketingActivityQueryAppBatchQueryRsp)
if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
return aliRsp, err
}
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
aliRsp.SignData = signData
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
}

// alipay.marketing.activity.shop.batchquery(查询活动可用门店)
// 文档地址:https://opendocs.alipay.com/open/04fgwe
func (a *Client) MarketingActivityQueryShopBatchQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *MarketingActivityQueryShopBatchQueryRsp, err error) {
err = bm.CheckEmptyError("activity_id", "page_num", "page_size")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(ctx, bm, "alipay.marketing.activity.shop.batchquery"); err != nil {
return nil, err
}
aliRsp = new(MarketingActivityQueryShopBatchQueryRsp)
if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
return aliRsp, err
}
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
aliRsp.SignData = signData
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
}

// alipay.marketing.activity.goods.batchquery(查询活动适用商品)
// 文档地址:https://opendocs.alipay.com/open/04fgwf
func (a *Client) MarketingActivityQueryGoodsBatchQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *MarketingActivityQueryGoodsBatchQueryRsp, err error) {
err = bm.CheckEmptyError("activity_id", "page_num", "page_size")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(ctx, bm, "alipay.marketing.activity.goods.batchquery"); err != nil {
return nil, err
}
aliRsp = new(MarketingActivityQueryGoodsBatchQueryRsp)
if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
return aliRsp, err
}
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
aliRsp.SignData = signData
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
}

// alipay.marketing.activity.user.batchqueryvoucher(条件查询用户券)
// 文档地址:https://opendocs.alipay.com/open/04fgwg
func (a *Client) MarketingActivityQueryUserBatchQueryVoucher(ctx context.Context, bm gopay.BodyMap) (aliRsp *MarketingActivityQueryUserBatchQueryVoucherRsp, err error) {
err = bm.CheckEmptyError("merchant_access_mode", "page_num", "page_size")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(ctx, bm, "alipay.marketing.activity.user.batchqueryvoucher"); err != nil {
return nil, err
}
aliRsp = new(MarketingActivityQueryUserBatchQueryVoucherRsp)
if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
return aliRsp, err
}
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
aliRsp.SignData = signData
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
}

// alipay.marketing.activity.user.queryvoucher(查询用户券详情)
// 文档地址:https://opendocs.alipay.com/open/04fgwh
func (a *Client) MarketingActivityQueryUserQueryVoucher(ctx context.Context, bm gopay.BodyMap) (aliRsp *MarketingActivityQueryUserQueryVoucherRsp, err error) {
var bs []byte
if bs, err = a.doAliPay(ctx, bm, "alipay.marketing.activity.user.queryvoucher"); err != nil {
return nil, err
}
aliRsp = new(MarketingActivityQueryUserQueryVoucherRsp)
if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
return aliRsp, err
}
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
aliRsp.SignData = signData
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
}
43 changes: 23 additions & 20 deletions alipay/marketing_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,29 @@ func (a *Client) MarketingCampaignCashDetailQuery(ctx context.Context, bm gopay.
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
}

// alipay.marketing.campaign.order.voucher.consult(订单优惠前置咨询)
// 文档地址:https://opendocs.alipay.com/open/04fgwi
func (a *Client) MarketingCampaignOrderVoucherConsult(ctx context.Context, bm gopay.BodyMap) (aliRsp *MarketingCampaignOrderVoucherConsultRsp, err error) {
err = bm.CheckEmptyError("scene_code", "order_amount")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(ctx, bm, "alipay.marketing.campaign.order.voucher.consult"); err != nil {
return nil, err
}
aliRsp = new(MarketingCampaignOrderVoucherConsultRsp)
if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
return aliRsp, err
}
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
aliRsp.SignData = signData
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
}

// alipay.marketing.activity.delivery.changed(推广计划状态变更消息)
// 文档地址:https://opendocs.alipay.com/open/85544608_alipay.marketing.activity.delivery.changed
func (a *Client) MarketingActivityDeliveryChanged(ctx context.Context, bm gopay.BodyMap) (success bool, err error) {
Expand Down Expand Up @@ -232,23 +255,3 @@ func (a *Client) MarketingActivityDeliveryCreate(ctx context.Context, bm gopay.B
aliRsp.SignData = signData
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
}

// alipay.marketing.material.image.upload(营销图片资源上传接口)
// 文档地址: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) {
var bs []byte
if bs, err = a.FileRequest(ctx, bm, file, "alipay.marketing.material.image.upload"); err != nil {
return nil, err
}
aliRsp = new(MarketingMaterialImageUploadRsp)
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)
}
Loading

0 comments on commit f3a476c

Please sign in to comment.