-
Notifications
You must be signed in to change notification settings - Fork 729
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 商户平台处置通知
- Loading branch information
Showing
4 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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。 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |