|
| 1 | +package merchantService |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "github.com/ArtisanCloud/PowerLibs/v3/object" |
| 7 | + "github.com/ArtisanCloud/PowerWeChat/v3/src/kernel" |
| 8 | + response2 "github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/response" |
| 9 | + payment "github.com/ArtisanCloud/PowerWeChat/v3/src/payment/kernel" |
| 10 | + "github.com/ArtisanCloud/PowerWeChat/v3/src/payment/merchantService/request" |
| 11 | + "github.com/ArtisanCloud/PowerWeChat/v3/src/payment/merchantService/response" |
| 12 | + "net/http" |
| 13 | +) |
| 14 | + |
| 15 | +type Client struct { |
| 16 | + *payment.BaseClient |
| 17 | +} |
| 18 | + |
| 19 | +func NewClient(app *payment.ApplicationPaymentInterface) (*Client, error) { |
| 20 | + baseClient, err := payment.NewBaseClient(app) |
| 21 | + if err != nil { |
| 22 | + return nil, err |
| 23 | + } |
| 24 | + return &Client{ |
| 25 | + baseClient, |
| 26 | + }, nil |
| 27 | +} |
| 28 | + |
| 29 | +// 查询投诉单列表 |
| 30 | +// https://pay.weixin.qq.com/docs/merchant/apis/consumer-complaint/complaints/list-complaints-v2.html |
| 31 | +func (comp *Client) Complaints(ctx context.Context, params *request.RequestComplaints) (*response.ResponseComplaints, error) { |
| 32 | + |
| 33 | + result := &response.ResponseComplaints{} |
| 34 | + |
| 35 | + data, _ := object.StructToStringMap(params) |
| 36 | + |
| 37 | + endpoint := "/v3/merchant-service/complaints-v2" |
| 38 | + _, err := comp.Request(ctx, endpoint, data, http.MethodGet, &object.HashMap{}, false, nil, result) |
| 39 | + |
| 40 | + return result, err |
| 41 | +} |
| 42 | + |
| 43 | +// 查询投诉单详情 |
| 44 | +// https://pay.weixin.qq.com/docs/merchant/apis/consumer-complaint/complaints/query-complaint-v2.html |
| 45 | +func (comp *Client) QueryComplaint(ctx context.Context, complaintId string) (*response.ResponseQueryComplaint, error) { |
| 46 | + |
| 47 | + result := &response.ResponseQueryComplaint{} |
| 48 | + |
| 49 | + endpoint := fmt.Sprintf("/v3/merchant-service/complaints-v2/%s", complaintId) |
| 50 | + _, err := comp.Request(ctx, endpoint, nil, http.MethodGet, &object.HashMap{}, false, nil, result) |
| 51 | + |
| 52 | + return result, err |
| 53 | +} |
| 54 | + |
| 55 | +// 查询投诉单协商历史 |
| 56 | +// https://pay.weixin.qq.com/docs/merchant/apis/consumer-complaint/complaints/query-negotiation-history-v2.html |
| 57 | +func (comp *Client) QueryNegotiationHistoriesByComplaint(ctx context.Context, complaintId string, limit int8, offset int8) (*response.ResponseQueryNegotiationHistoriesByComplaint, error) { |
| 58 | + |
| 59 | + result := &response.ResponseQueryNegotiationHistoriesByComplaint{} |
| 60 | + |
| 61 | + data := &object.StringMap{ |
| 62 | + "limit": fmt.Sprintf("%d", limit), |
| 63 | + "offset": fmt.Sprintf("%d", offset), |
| 64 | + } |
| 65 | + |
| 66 | + endpoint := fmt.Sprintf("/v3/merchant-service/complaints-v2/%s/negotiation-historys", complaintId) |
| 67 | + _, err := comp.Request(ctx, endpoint, data, http.MethodGet, &object.HashMap{}, false, nil, result) |
| 68 | + |
| 69 | + return result, err |
| 70 | +} |
| 71 | + |
| 72 | +// 创建投诉通知回调 |
| 73 | +// https://pay.weixin.qq.com/docs/merchant/apis/consumer-complaint/complaint-notifications/create-complaint-notifications.html |
| 74 | +func (comp *Client) CreateComplaintNotifications(ctx context.Context, url string) (*response.ResponseCreateComplaintNotifications, error) { |
| 75 | + |
| 76 | + result := &response.ResponseCreateComplaintNotifications{} |
| 77 | + |
| 78 | + data := &object.HashMap{ |
| 79 | + "url": url, |
| 80 | + } |
| 81 | + |
| 82 | + endpoint := "/v3/merchant-service/complaint-notifications" |
| 83 | + _, err := comp.Request(ctx, endpoint, nil, http.MethodPost, data, false, nil, result) |
| 84 | + |
| 85 | + return result, err |
| 86 | +} |
| 87 | + |
| 88 | +// 查询投诉通知回调 |
| 89 | +// https://pay.weixin.qq.com/docs/merchant/apis/consumer-complaint/complaint-notifications/query-complaint-notifications.html |
| 90 | +func (comp *Client) QueryComplaintNotifications(ctx context.Context, complaintId string, limit int8, offset int8) (*response.ResponseCreateComplaintNotifications, error) { |
| 91 | + |
| 92 | + result := &response.ResponseCreateComplaintNotifications{} |
| 93 | + |
| 94 | + endpoint := "/v3/merchant-service/complaint-notifications" |
| 95 | + _, err := comp.Request(ctx, endpoint, nil, http.MethodGet, &object.HashMap{}, false, nil, result) |
| 96 | + |
| 97 | + return result, err |
| 98 | +} |
| 99 | + |
| 100 | +// 更新投诉通知回调 |
| 101 | +// https://pay.weixin.qq.com/docs/merchant/apis/consumer-complaint/complaint-notifications/update-complaint-notifications.html |
| 102 | +func (comp *Client) UpdateComplaintNotifications(ctx context.Context, url string) (*response.ResponseCreateComplaintNotifications, error) { |
| 103 | + |
| 104 | + result := &response.ResponseCreateComplaintNotifications{} |
| 105 | + |
| 106 | + data := &object.HashMap{ |
| 107 | + "url": url, |
| 108 | + } |
| 109 | + |
| 110 | + endpoint := "/v3/merchant-service/complaint-notifications" |
| 111 | + _, err := comp.Request(ctx, endpoint, nil, http.MethodPut, data, false, nil, result) |
| 112 | + |
| 113 | + return result, err |
| 114 | +} |
| 115 | + |
| 116 | +// 删除投诉通知回调 |
| 117 | +// https://pay.weixin.qq.com/docs/merchant/apis/consumer-complaint/complaint-notifications/delete-complaint-notifications.html |
| 118 | +func (comp *Client) DeleteComplaintNotifications(ctx context.Context, url string) (*response2.ResponsePayment, error) { |
| 119 | + |
| 120 | + result := &response2.ResponsePayment{} |
| 121 | + |
| 122 | + endpoint := "/v3/merchant-service/complaint-notifications" |
| 123 | + _, err := comp.Request(ctx, endpoint, nil, http.MethodDelete, &object.HashMap{}, false, nil, result) |
| 124 | + |
| 125 | + return result, err |
| 126 | +} |
| 127 | + |
| 128 | +// 回复用户 |
| 129 | +// https://pay.weixin.qq.com/docs/merchant/apis/consumer-complaint/complaints/response-complaint-v2.html |
| 130 | +func (comp *Client) ReplyToUser(ctx context.Context, complaintId string, params *request.RequestReplyToUser) (*response2.ResponsePayment, error) { |
| 131 | + |
| 132 | + result := &response2.ResponsePayment{} |
| 133 | + |
| 134 | + data, _ := object.StructToHashMap(params) |
| 135 | + |
| 136 | + endpoint := fmt.Sprintf("/v3/merchant-service/complaints-v2/%s/response", complaintId) |
| 137 | + _, err := comp.Request(ctx, endpoint, nil, http.MethodPost, data, false, nil, result) |
| 138 | + |
| 139 | + return result, err |
| 140 | +} |
| 141 | + |
| 142 | +// 反馈处理完成 |
| 143 | +// https://pay.weixin.qq.com/docs/merchant/apis/consumer-complaint/complaints/complete-complaint-v2.html |
| 144 | +func (comp *Client) CompleteFeedback(ctx context.Context, complaintId string) (*response2.ResponsePayment, error) { |
| 145 | + |
| 146 | + result := &response2.ResponsePayment{} |
| 147 | + |
| 148 | + endpoint := fmt.Sprintf("/v3/merchant-service/complaints-v2/%s/complete", complaintId) |
| 149 | + _, err := comp.Request(ctx, endpoint, nil, http.MethodPost, &object.HashMap{}, false, nil, result) |
| 150 | + |
| 151 | + return result, err |
| 152 | +} |
| 153 | + |
| 154 | +// 更新退款审批结果 |
| 155 | +// https://pay.weixin.qq.com/docs/merchant/apis/consumer-complaint/complaints/complete-complaint-v2.html |
| 156 | +func (comp *Client) UpdateFeedback(ctx context.Context, complaintId string, params *request.RequestUpdateFeedback) (*response2.ResponsePayment, error) { |
| 157 | + |
| 158 | + result := &response2.ResponsePayment{} |
| 159 | + |
| 160 | + data, _ := object.StructToHashMap(params) |
| 161 | + |
| 162 | + endpoint := fmt.Sprintf("/v3/merchant-service/complaints-v2/%s/update-refund-progress", complaintId) |
| 163 | + _, err := comp.Request(ctx, endpoint, nil, http.MethodPost, data, false, nil, result) |
| 164 | + |
| 165 | + return result, err |
| 166 | +} |
| 167 | + |
| 168 | +// 图片上传接口 |
| 169 | +// https://pay.weixin.qq.com/docs/merchant/apis/consumer-complaint/images/create-images.html |
| 170 | +func (comp *Client) UploadImg(ctx context.Context, params *request.RequestMediaUpload) (*response.ResponseMediaUpload, error) { |
| 171 | + |
| 172 | + result := &response.ResponseMediaUpload{} |
| 173 | + |
| 174 | + var files *object.HashMap |
| 175 | + if params.File != "" { |
| 176 | + files = &object.HashMap{ |
| 177 | + "file": params.File, |
| 178 | + } |
| 179 | + } |
| 180 | + |
| 181 | + var formData *kernel.UploadForm |
| 182 | + if params.Meta != nil { |
| 183 | + formData = &kernel.UploadForm{ |
| 184 | + Contents: []*kernel.UploadContent{ |
| 185 | + &kernel.UploadContent{ |
| 186 | + Name: "file", |
| 187 | + Value: params.Meta.Filename, |
| 188 | + }, |
| 189 | + }, |
| 190 | + } |
| 191 | + } |
| 192 | + options, _ := object.StructToHashMap(params.Meta) |
| 193 | + |
| 194 | + _, err := comp.BaseClient.HttpUploadJson(ctx, "/v3/merchant-service/images/upload", files, formData, options, nil, nil, &result) |
| 195 | + return result, err |
| 196 | +} |
0 commit comments