Skip to content

Commit

Permalink
Merge branch 'main' into feature/xhttp_update
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoogle-ink committed Oct 1, 2023
2 parents ca20b64 + 3b8ee6e commit d91e20e
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 5 deletions.
23 changes: 20 additions & 3 deletions alipay/data_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import (
"github.com/go-pay/gopay"
)

// Deprecated
// 支付宝已不再支持
// alipay.data.bill.balance.query(支付宝商家账户当前余额查询)
// 文档地址:https://opendocs.alipay.com/apis/api_15/alipay.data.bill.balance.query
// 文档地址:https://opendocs.alipay.com/open/2acb3c34_alipay.data.bill.balance.query
func (a *Client) DataBillBalanceQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *DataBillBalanceQueryResponse, err error) {
var bs []byte
if bs, err = a.doAliPay(ctx, bm, "alipay.data.bill.balance.query"); err != nil {
Expand All @@ -29,6 +27,25 @@ func (a *Client) DataBillBalanceQuery(ctx context.Context, bm gopay.BodyMap) (al
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
}

// alipay.data.bill.accountlog.query(支付宝商家账户账务明细查询)
// 文档地址:https://opendocs.alipay.com/open/dae3ac99_alipay.data.bill.accountlog.query
func (a *Client) DataBillAccountLogQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *DataBillAccountLogQueryResponse, err error) {
var bs []byte
if bs, err = a.doAliPay(ctx, bm, "alipay.data.bill.accountlog.query"); err != nil {
return nil, err
}
aliRsp = new(DataBillAccountLogQueryResponse)
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.data.dataservice.bill.downloadurl.query(查询对账单下载地址)
// 文档地址:https://opendocs.alipay.com/open/02e7gr
func (a *Client) DataBillDownloadUrlQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *DataBillDownloadUrlQueryResponse, err error) {
Expand Down
37 changes: 37 additions & 0 deletions alipay/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,43 @@ type DataBillBalanceQuery struct {
TotalAmount string `json:"total_amount,omitempty"`
AvailableAmount string `json:"available_amount,omitempty"`
FreezeAmount string `json:"freeze_amount,omitempty"`
SettleAmount string `json:"settle_amount,omitempty"`
}

// ===================================================
type DataBillAccountLogQueryResponse struct {
Response *DataBillAccountLogQuery `json:"alipay_data_bill_accountlog_query_response"`
AlipayCertSn string `json:"alipay_cert_sn,omitempty"`
SignData string `json:"-"`
Sign string `json:"sign"`
}

type DataBillAccountLogQuery struct {
ErrorResponse
PageNo string `json:"page_no,omitempty"`
PageSize string `json:"page_size,omitempty"`
TotalSize string `json:"total_size,omitempty"`
DetailList []AccountLogItemResult `json:"detail_list,omitempty"`
}

type AccountLogItemResult struct {
TransDt string `json:"trans_dt,omitempty"`
AccountLogId string `json:"account_log_id,omitempty"`
AlipayOrderNo string `json:"alipay_order_no,omitempty"`
MerchantOrderNo string `json:"merchant_order_no,omitempty"`
TransAmount string `json:"trans_amount,omitempty"`
Balance string `json:"balance,omitempty"`
Type string `json:"type,omitempty"`
OtherAccount string `json:"other_account,omitempty"`
TransMemo string `json:"trans_memo,omitempty"`
Direction string `json:"direction,omitempty"`
BillSource string `json:"bill_source,omitempty"`
BizNos string `json:"biz_nos,omitempty"`
BizOrigNo string `json:"biz_orig_no,omitempty"`
BizDesc string `json:"biz_desc,omitempty"`
MerchantOutRefundNo string `json:"merchant_out_refund_no,omitempty"`
ComplementInfo string `json:"complement_info,omitempty"`
StoreName string `json:"store_name,omitempty"`
}

// ===================================================
Expand Down
2 changes: 1 addition & 1 deletion apple/notification_v2_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type NotificationV2Payload struct {
NotificationType string `json:"notificationType"`
Subtype string `json:"subtype"`
NotificationUUID string `json:"notificationUUID"`
NotificationVersion string `json:"notificationVersion"`
Version string `json:"version"`
Data *Data `json:"data"`
}

Expand Down
2 changes: 1 addition & 1 deletion apple/notification_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestDecodeSignedPayload(t *testing.T) {
xlog.Debugf("payload.NotificationType: %s", payload.NotificationType)
xlog.Debugf("payload.Subtype: %s", payload.Subtype)
xlog.Debugf("payload.NotificationUUID: %s", payload.NotificationUUID)
xlog.Debugf("payload.NotificationVersion: %s", payload.NotificationVersion)
xlog.Debugf("payload.Version: %s", payload.Version)
xlog.Debugf("payload.Data: %+v", payload.Data)
bs1, _ := json.Marshal(payload)
xlog.Color(xlog.RedBright).Info(string(bs1))
Expand Down
1 change: 1 addition & 0 deletions apple/transaction_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type TransactionsItem struct {
SignedDate int64 `json:"signedDate"`
OfferType int `json:"offerType"`
Environment string `json:"environment"`
AppAccountToken string `json:"appAccountToken"`
}

func (s *SignedTransaction) DecodeSignedTransaction() (ti *TransactionsItem, err error) {
Expand Down
5 changes: 5 additions & 0 deletions doc/wechat_v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ wechat.V3DecryptScoreNotifyCipherText()
* 反馈处理完成:`client.V3ComplaintComplete()`
* 更新退款审批结果:`client.V3ComplaintUpdateRefundProgress()`
* 商户上传反馈图片:`client.V3ComplaintUploadImage()`
* <font color='#07C160' size='4'>商户平台处置通知</font>
* 创建商户违规通知回调回调地址:`client.V3ViolationNotifyUrlCreate()`
* 查询商户违规通知回调回调地址:`client.V3ViolationNotifyUrlQuery()`
* 更新商户违规通知回调回调地址:`client.V3ViolationNotifyUrlUpdate()`
* 删除商户违规通知回调回调地址:`client.V3ViolationNotifyUrlDelete()`
* <font color='#07C160' size='4'>其他能力</font>
* 图片上传:`client.V3MediaUploadImage()`
* 视频上传:`client.V3MediaUploadVideo()`
Expand Down
6 changes: 6 additions & 0 deletions wechat/v3/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ const (
v3ComplaintUploadImage = "/v3/merchant-service/images/upload" // 商户上传反馈图片 POST
v3ComplaintUpdateRefundProgress = "/v3/merchant-service/complaints-v2/%s/update-refund-progress" // complaint_id 更新退款审批结果 POST

// 商户平台处置通知
v3ViolationNotifyUrlCreate = "/v3/merchant-risk-manage/violation-notifications" // 创建商户违规通知回调地址 POST
v3ViolationNotifyUrlQuery = "/v3/merchant-risk-manage/violation-notifications" // 查询商户违规通知回调地址 GET
v3ViolationNotifyUrlUpdate = "/v3/merchant-risk-manage/violation-notifications" // 查询商户违规通知回调地址 PUT
v3ViolationNotifyUrlDelete = "/v3/merchant-risk-manage/violation-notifications" // 删除商户违规通知回调地址 DELETE

// 分账(服务商)
v3ProfitShareOrder = "/v3/profitsharing/orders" // 请求分账 POST
v3ProfitShareQuery = "/v3/profitsharing/orders/%s" // 查询分账结果 GET
Expand Down
13 changes: 13 additions & 0 deletions wechat/v3/model_violation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package wechat

// 创建、查询、更新投诉通知回调地址 Rsp
type ViolationNotifyUrlRsp struct {
Code int `json:"-"`
SignInfo *SignInfo `json:"-"`
Response *ViolationNotifyUrl `json:"response,omitempty"`
Error string `json:"-"`
}

type ViolationNotifyUrl struct {
NotifyUrl string `json:"notify_url"` // 通知地址,仅支持https。
}
106 changes: 106 additions & 0 deletions wechat/v3/violation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package wechat

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

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

// 创建商户违规通知回调地址API
// Code = 0 is success
func (c *ClientV3) V3ViolationNotifyUrlCreate(ctx context.Context, url string) (wxRsp *ViolationNotifyUrlRsp, err error) {
bm := make(gopay.BodyMap)
bm.Set("notify_url", url)
authorization, err := c.authorization(MethodPost, v3ViolationNotifyUrlCreate, bm)
if err != nil {
return nil, err
}
res, si, bs, err := c.doProdPost(ctx, bm, v3ViolationNotifyUrlCreate, authorization)
if err != nil {
return nil, err
}
wxRsp = &ViolationNotifyUrlRsp{Code: Success, SignInfo: si}
wxRsp.Response = new(ViolationNotifyUrl)
if err = json.Unmarshal(bs, wxRsp.Response); err != nil {
return nil, fmt.Errorf("[%w]: %v, bytes: %s", gopay.UnmarshalErr, err, string(bs))
}
if res.StatusCode != http.StatusOK {
wxRsp.Code = res.StatusCode
wxRsp.Error = string(bs)
return wxRsp, nil
}
return wxRsp, c.verifySyncSign(si)
}

// 查询商户违规通知回调地址API
// Code = 0 is success
func (c *ClientV3) V3ViolationNotifyUrlQuery(ctx context.Context) (wxRsp *ViolationNotifyUrlRsp, err error) {
authorization, err := c.authorization(MethodGet, v3ViolationNotifyUrlQuery, nil)
if err != nil {
return nil, err
}
res, si, bs, err := c.doProdGet(ctx, v3ViolationNotifyUrlQuery, authorization)
if err != nil {
return nil, err
}
wxRsp = &ViolationNotifyUrlRsp{Code: Success, SignInfo: si}
wxRsp.Response = new(ViolationNotifyUrl)
if err = json.Unmarshal(bs, wxRsp.Response); err != nil {
return nil, fmt.Errorf("[%w]: %v, bytes: %s", gopay.UnmarshalErr, err, string(bs))
}
if res.StatusCode != http.StatusOK {
wxRsp.Code = res.StatusCode
wxRsp.Error = string(bs)
return wxRsp, nil
}
return wxRsp, c.verifySyncSign(si)
}

// 更新商户违规通知回调地址API
// Code = 0 is success
func (c *ClientV3) V3ViolationNotifyUrlUpdate(ctx context.Context, url string) (wxRsp *ViolationNotifyUrlRsp, err error) {
bm := make(gopay.BodyMap)
bm.Set("notify_url", url)
authorization, err := c.authorization(MethodPut, v3ViolationNotifyUrlUpdate, bm)
if err != nil {
return nil, err
}
res, si, bs, err := c.doProdPut(ctx, bm, v3ViolationNotifyUrlUpdate, authorization)
if err != nil {
return nil, err
}
wxRsp = &ViolationNotifyUrlRsp{Code: Success, SignInfo: si}
wxRsp.Response = new(ViolationNotifyUrl)
if err = json.Unmarshal(bs, wxRsp.Response); err != nil {
return nil, fmt.Errorf("[%w]: %v, bytes: %s", gopay.UnmarshalErr, err, string(bs))
}
if res.StatusCode != http.StatusOK {
wxRsp.Code = res.StatusCode
wxRsp.Error = string(bs)
return wxRsp, nil
}
return wxRsp, c.verifySyncSign(si)
}

// 删除商户违规通知回调地址API
// Code = 0 is success
func (c *ClientV3) V3ViolationNotifyUrlDelete(ctx context.Context) (wxRsp *EmptyRsp, err error) {
authorization, err := c.authorization(MethodDelete, v3ViolationNotifyUrlDelete, nil)
if err != nil {
return nil, err
}
res, si, bs, err := c.doProdDelete(ctx, nil, v3ViolationNotifyUrlDelete, authorization)
if err != nil {
return nil, err
}
wxRsp = &EmptyRsp{Code: Success, SignInfo: si}
if res.StatusCode != http.StatusNoContent {
wxRsp.Code = res.StatusCode
wxRsp.Error = string(bs)
return wxRsp, nil
}
return wxRsp, c.verifySyncSign(si)
}

0 comments on commit d91e20e

Please sign in to comment.