Skip to content

Commit 8813e0e

Browse files
authored
Merge pull request #477 from ArtisanCloud/develop
Develop
2 parents fb4f16b + a1567b2 commit 8813e0e

File tree

9 files changed

+355
-2
lines changed

9 files changed

+355
-2
lines changed

src/payment/application.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/jssdk"
1616
kernel2 "github.com/ArtisanCloud/PowerWeChat/v3/src/payment/kernel"
1717
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/merchant"
18+
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/merchantService"
1819
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/notify"
1920
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/notify/request"
2021
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/order"
@@ -52,8 +53,9 @@ type Payment struct {
5253
Reverse *reverse.Client
5354
ProfitSharing *profitSharing.Client
5455

55-
Apply4Sub *apply4Sub.Client
56-
Merchant *merchant.Client
56+
Apply4Sub *apply4Sub.Client
57+
Merchant *merchant.Client
58+
MerchantService *merchantService.Client
5759

5860
PayScore *payScore.Client
5961

@@ -216,6 +218,11 @@ func NewPayment(config *UserConfig) (*Payment, error) {
216218
if err != nil {
217219
return nil, err
218220
}
221+
//-------------- Merchant Service --------------
222+
app.MerchantService, err = merchantService.RegisterProvider(app)
223+
if err != nil {
224+
return nil, err
225+
}
219226

220227
//-------------- Pay Score --------------
221228
app.PayScore, err = payScore.RegisterProvider(app)
@@ -284,6 +291,8 @@ func (app *Payment) GetComponent(name string) interface{} {
284291
return app.Tax
285292
case "Merchant":
286293
return app.Merchant
294+
case "MerchantService":
295+
return app.MerchantService
287296
case "PayScore":
288297
return app.PayScore
289298

src/payment/merchantService/client.go

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
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+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package merchantService
2+
3+
import (
4+
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/kernel"
5+
)
6+
7+
func RegisterProvider(app kernel.ApplicationPaymentInterface) (*Client, error) {
8+
9+
return NewClient(&app)
10+
11+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package request
2+
3+
type Meta struct {
4+
Filename string `json:"filename"`
5+
Sha256 string `json:"sha256"`
6+
}
7+
8+
type RequestMediaUpload struct {
9+
File string `json:"file"`
10+
Meta *Meta `json:"meta"`
11+
}
12+
13+
type RequestComplaints struct {
14+
Limit int8 `json:"limit"`
15+
Offset int8 `json:"offset"`
16+
BeginDate string `json:"begin_date"`
17+
EndDate string `json:"end_date"`
18+
ComplaintedMchId string `json:"complainted_mchid"`
19+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package request
2+
3+
type RequestReplyToUser struct {
4+
ComplaintedMchid string `json:"complainted_mchid"`
5+
ResponseContent string `json:"response_content"`
6+
ResponseImages []string `json:"response_images"`
7+
JumpUrl string `json:"jump_url"`
8+
JumpUrlText string `json:"jump_url_text"`
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package request
2+
3+
type RequestUpdateFeedback struct {
4+
Action string `json:"action"`
5+
LaunchRefundDay int `json:"launch_refund_day"`
6+
RejectReason string `json:"reject_reason"`
7+
RejectMediaList []string `json:"reject_media_list"`
8+
Remark string `json:"remark"`
9+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package response
2+
3+
import (
4+
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/response"
5+
"time"
6+
)
7+
8+
type ResponseMediaUpload struct {
9+
response.ResponsePayment
10+
MediaId string `json:"media_id"`
11+
}
12+
13+
type ReturnAddressInfo struct {
14+
ReturnAddress string `json:"return_address"`
15+
Longitude string `json:"longitude"`
16+
Latitude string `json:"latitude"`
17+
}
18+
19+
type SharePowerInfo struct {
20+
ReturnTime time.Time `json:"return_time"`
21+
ReturnAddressInfo ReturnAddressInfo `json:"return_address_info"`
22+
}
23+
24+
type AdditionalInfo struct {
25+
Type string `json:"type"`
26+
SharePowerInfo SharePowerInfo `json:"share_power_info"`
27+
}
28+
29+
type ServiceOrderInfo struct {
30+
OrderId string `json:"order_id"`
31+
OutOrderNo string `json:"out_order_no"`
32+
State string `json:"state"`
33+
}
34+
35+
type ComplaintMediaList struct {
36+
MediaType string `json:"media_type"`
37+
MediaUrl []string `json:"media_url"`
38+
}
39+
40+
type ComplainOrderInfo struct {
41+
TransactionId string `json:"transaction_id"`
42+
OutTradeNo string `json:"out_trade_no"`
43+
Amount int `json:"amount"`
44+
}
45+
46+
type ResponseQueryComplaint struct {
47+
response.ResponsePayment
48+
49+
ComplaintId string `json:"complaint_id"`
50+
ComplaintTime time.Time `json:"complaint_time"`
51+
ComplaintDetail string `json:"complaint_detail"`
52+
ComplaintState string `json:"complaint_state"`
53+
PayerPhone string `json:"payer_phone"`
54+
ComplaintOrderInfo []ComplainOrderInfo `json:"complaint_order_info"`
55+
ComplaintFullRefunded bool `json:"complaint_full_refunded"`
56+
IncomingUserResponse bool `json:"incoming_user_response"`
57+
UserComplaintTimes int `json:"user_complaint_times"`
58+
ComplaintMediaList []ComplaintMediaList `json:"complaint_media_list"`
59+
ProblemDescription string `json:"problem_description"`
60+
ProblemType string `json:"problem_type"`
61+
ApplyRefundAmount int `json:"apply_refund_amount"`
62+
UserTagList []string `json:"user_tag_list"`
63+
ServiceOrderInfo []ServiceOrderInfo `json:"service_order_info"`
64+
AdditionalInfo AdditionalInfo `json:"additional_info"`
65+
}
66+
67+
type ResponseComplaints struct {
68+
response.ResponsePayment
69+
70+
Data []ResponseQueryComplaint `json:"data"`
71+
Limit int `json:"limit"`
72+
Offset int `json:"offset"`
73+
TotalCount int `json:"total_count"`
74+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package response
2+
3+
type ResponseCreateComplaintNotifications struct {
4+
MchId string `json:"mchid"`
5+
Url string `json:"url"`
6+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package response
2+
3+
import "time"
4+
5+
type Data struct {
6+
LogId string `json:"log_id"`
7+
Operator string `json:"operator"`
8+
OperateTime time.Time `json:"operate_time"`
9+
OperateType string `json:"operate_type"`
10+
OperateDetails string `json:"operate_details"`
11+
ImageList []string `json:"image_list"`
12+
ComplaintMediaList ComplaintMediaList `json:"complaint_media_list"`
13+
}
14+
15+
type ResponseQueryNegotiationHistoriesByComplaint struct {
16+
Data []Data `json:"data"`
17+
Limit int `json:"limit"`
18+
Offset int `json:"offset"`
19+
TotalCount int `json:"total_count"`
20+
}

0 commit comments

Comments
 (0)