Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

商户平台处置通知 #354

Merged
merged 3 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}