From 3d8f3beca9dc386d2356ffe965552032743a2fe7 Mon Sep 17 00:00:00 2001 From: oort Date: Tue, 26 Sep 2023 21:48:48 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=8A=95=E8=AF=89?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E5=9C=B0=E5=9D=80=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wechat/v3/constant.go | 6 ++ wechat/v3/model_violation.go | 13 +++++ wechat/v3/violation.go | 106 +++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 wechat/v3/model_violation.go create mode 100644 wechat/v3/violation.go diff --git a/wechat/v3/constant.go b/wechat/v3/constant.go index 2e2cd804..9e58835a 100644 --- a/wechat/v3/constant.go +++ b/wechat/v3/constant.go @@ -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 diff --git a/wechat/v3/model_violation.go b/wechat/v3/model_violation.go new file mode 100644 index 00000000..95d222cd --- /dev/null +++ b/wechat/v3/model_violation.go @@ -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。 +} diff --git a/wechat/v3/violation.go b/wechat/v3/violation.go new file mode 100644 index 00000000..c1cf55ba --- /dev/null +++ b/wechat/v3/violation.go @@ -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("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("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) +} From 4e68e94fbb40cbebe346ac520619797d2e50b363 Mon Sep 17 00:00:00 2001 From: oort Date: Tue, 26 Sep 2023 22:11:30 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=95=86=E6=88=B7?= =?UTF-8?q?=E8=BF=9D=E8=A7=84=E9=80=9A=E7=9F=A5=E5=9C=B0=E5=9D=80=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wechat/v3/violation.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wechat/v3/violation.go b/wechat/v3/violation.go index c1cf55ba..93f06685 100644 --- a/wechat/v3/violation.go +++ b/wechat/v3/violation.go @@ -13,7 +13,7 @@ import ( // Code = 0 is success func (c *ClientV3) V3ViolationNotifyUrlCreate(ctx context.Context, url string) (wxRsp *ViolationNotifyUrlRsp, err error) { bm := make(gopay.BodyMap) - bm.Set("url", url) + bm.Set("notify_url", url) authorization, err := c.authorization(MethodPost, v3ViolationNotifyUrlCreate, bm) if err != nil { return nil, err @@ -63,7 +63,7 @@ func (c *ClientV3) V3ViolationNotifyUrlQuery(ctx context.Context) (wxRsp *Violat // Code = 0 is success func (c *ClientV3) V3ViolationNotifyUrlUpdate(ctx context.Context, url string) (wxRsp *ViolationNotifyUrlRsp, err error) { bm := make(gopay.BodyMap) - bm.Set("url", url) + bm.Set("notify_url", url) authorization, err := c.authorization(MethodPut, v3ViolationNotifyUrlUpdate, bm) if err != nil { return nil, err From 7521bad7d48b387a1593f94ec65c34f98e0d3f50 Mon Sep 17 00:00:00 2001 From: oort Date: Tue, 26 Sep 2023 22:15:25 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=95=86=E6=88=B7=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E5=A4=84=E7=BD=AE=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/wechat_v3.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/wechat_v3.md b/doc/wechat_v3.md index b3887bf2..ca9403c6 100644 --- a/doc/wechat_v3.md +++ b/doc/wechat_v3.md @@ -356,6 +356,11 @@ wechat.V3DecryptScoreNotifyCipherText() * 反馈处理完成:`client.V3ComplaintComplete()` * 更新退款审批结果:`client.V3ComplaintUpdateRefundProgress()` * 商户上传反馈图片:`client.V3ComplaintUploadImage()` +* 商户平台处置通知 + * 创建商户违规通知回调回调地址:`client.V3ViolationNotifyUrlCreate()` + * 查询商户违规通知回调回调地址:`client.V3ViolationNotifyUrlQuery()` + * 更新商户违规通知回调回调地址:`client.V3ViolationNotifyUrlUpdate()` + * 删除商户违规通知回调回调地址:`client.V3ViolationNotifyUrlDelete()` * 其他能力 * 图片上传:`client.V3MediaUploadImage()` * 视频上传:`client.V3MediaUploadVideo()`