
1package main
2
3import (
4 "demo/wxpay_utility"
5 "encoding/json"
6 "fmt"
7 "net/http"
8 "net/url"
9 "strings"
10)
11
12func main() {
13
14 config, err := wxpay_utility.CreateMchConfig(
15 "19xxxxxxxx",
16 "1DDE55AD98Exxxxxxxxxx",
17 "/path/to/apiclient_key.pem",
18 "PUB_KEY_ID_xxxxxxxxxxxxx",
19 "/path/to/wxp_pub.pem",
20 )
21 if err != nil {
22 fmt.Println(err)
23 return
24 }
25
26 request := &QueryNegotiationHistoryV2Request{
27 ComplaintId: wxpay_utility.String("200201820200101080076610000"),
28 Limit: wxpay_utility.Int64(50),
29 Offset: wxpay_utility.Int64(10),
30 }
31
32 response, err := QueryNegotiationHistoryV2(config, request)
33 if err != nil {
34 fmt.Printf("请求失败: %+v\n", err)
35
36 return
37 }
38
39
40 fmt.Printf("请求成功: %+v\n", response)
41}
42
43func QueryNegotiationHistoryV2(config *wxpay_utility.MchConfig, request *QueryNegotiationHistoryV2Request) (response *QueryNegotiationHistoryV2Response, err error) {
44 const (
45 host = "https://api.mch.weixin.qq.com"
46 method = "GET"
47 path = "/v3/merchant-service/complaints-v2/{complaint_id}/negotiation-historys"
48 )
49
50 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path))
51 if err != nil {
52 return nil, err
53 }
54 reqUrl.Path = strings.Replace(reqUrl.Path, "{complaint_id}", url.PathEscape(*request.ComplaintId), -1)
55 query := reqUrl.Query()
56 if request.Limit != nil {
57 query.Add("limit", fmt.Sprintf("%v", *request.Limit))
58 }
59 if request.Offset != nil {
60 query.Add("offset", fmt.Sprintf("%v", *request.Offset))
61 }
62 reqUrl.RawQuery = query.Encode()
63 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil)
64 if err != nil {
65 return nil, err
66 }
67 httpRequest.Header.Set("Accept", "application/json")
68 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId())
69 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil)
70 if err != nil {
71 return nil, err
72 }
73 httpRequest.Header.Set("Authorization", authorization)
74
75 client := &http.Client{}
76 httpResponse, err := client.Do(httpRequest)
77 if err != nil {
78 return nil, err
79 }
80 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse)
81 if err != nil {
82 return nil, err
83 }
84 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 {
85
86 err = wxpay_utility.ValidateResponse(
87 config.WechatPayPublicKeyId(),
88 config.WechatPayPublicKey(),
89 &httpResponse.Header,
90 respBody,
91 )
92 if err != nil {
93 return nil, err
94 }
95 response := &QueryNegotiationHistoryV2Response{}
96 if err := json.Unmarshal(respBody, response); err != nil {
97 return nil, err
98 }
99
100 return response, nil
101 } else {
102 return nil, wxpay_utility.NewApiException(
103 httpResponse.StatusCode,
104 httpResponse.Header,
105 respBody,
106 )
107 }
108}
109
110type QueryNegotiationHistoryV2Request struct {
111 ComplaintId *string `json:"complaint_id,omitempty"`
112 Limit *int64 `json:"limit,omitempty"`
113 Offset *int64 `json:"offset,omitempty"`
114}
115
116func (o *QueryNegotiationHistoryV2Request) MarshalJSON() ([]byte, error) {
117 type Alias QueryNegotiationHistoryV2Request
118 a := &struct {
119 ComplaintId *string `json:"complaint_id,omitempty"`
120 Limit *int64 `json:"limit,omitempty"`
121 Offset *int64 `json:"offset,omitempty"`
122 *Alias
123 }{
124
125 ComplaintId: nil,
126 Limit: nil,
127 Offset: nil,
128 Alias: (*Alias)(o),
129 }
130 return json.Marshal(a)
131}
132
133type QueryNegotiationHistoryV2Response struct {
134 Data []ComplaintNegotiationHistoryWithLogId `json:"data,omitempty"`
135 Limit *int64 `json:"limit,omitempty"`
136 Offset *int64 `json:"offset,omitempty"`
137 TotalCount *int64 `json:"total_count,omitempty"`
138}
139
140type ComplaintNegotiationHistoryWithLogId struct {
141 LogId *string `json:"log_id,omitempty"`
142 Operator *string `json:"operator,omitempty"`
143 OperateTime *string `json:"operate_time,omitempty"`
144 OperateType *ComplaintNegotiationOperateType `json:"operate_type,omitempty"`
145 OperateDetails *string `json:"operate_details,omitempty"`
146 ImageList []string `json:"image_list,omitempty"`
147 ComplaintMediaList *ComplaintMedia `json:"complaint_media_list,omitempty"`
148 UserAppyPlatformServiceReason *string `json:"user_appy_platform_service_reason,omitempty"`
149 UserAppyPlatformServiceReasonDescription *string `json:"user_appy_platform_service_reason_description,omitempty"`
150 NormalMessage *NormalMessage `json:"normal_message,omitempty"`
151 ClickMessage *ClickMessage `json:"click_message,omitempty"`
152}
153
154type ComplaintNegotiationOperateType string
155
156func (e ComplaintNegotiationOperateType) Ptr() *ComplaintNegotiationOperateType {
157 return &e
158}
159
160const (
161 COMPLAINTNEGOTIATIONOPERATETYPE_USER_CREATE_COMPLAINT ComplaintNegotiationOperateType = "USER_CREATE_COMPLAINT"
162 COMPLAINTNEGOTIATIONOPERATETYPE_USER_CONTINUE_COMPLAINT ComplaintNegotiationOperateType = "USER_CONTINUE_COMPLAINT"
163 COMPLAINTNEGOTIATIONOPERATETYPE_USER_RESPONSE ComplaintNegotiationOperateType = "USER_RESPONSE"
164 COMPLAINTNEGOTIATIONOPERATETYPE_PLATFORM_RESPONSE ComplaintNegotiationOperateType = "PLATFORM_RESPONSE"
165 COMPLAINTNEGOTIATIONOPERATETYPE_MERCHANT_RESPONSE ComplaintNegotiationOperateType = "MERCHANT_RESPONSE"
166 COMPLAINTNEGOTIATIONOPERATETYPE_MERCHANT_CONFIRM_COMPLETE ComplaintNegotiationOperateType = "MERCHANT_CONFIRM_COMPLETE"
167 COMPLAINTNEGOTIATIONOPERATETYPE_USER_CREATE_COMPLAINT_SYSTEM_MESSAGE ComplaintNegotiationOperateType = "USER_CREATE_COMPLAINT_SYSTEM_MESSAGE"
168 COMPLAINTNEGOTIATIONOPERATETYPE_COMPLAINT_FULL_REFUNDED_SYSTEM_MESSAGE ComplaintNegotiationOperateType = "COMPLAINT_FULL_REFUNDED_SYSTEM_MESSAGE"
169 COMPLAINTNEGOTIATIONOPERATETYPE_USER_CONTINUE_COMPLAINT_SYSTEM_MESSAGE ComplaintNegotiationOperateType = "USER_CONTINUE_COMPLAINT_SYSTEM_MESSAGE"
170 COMPLAINTNEGOTIATIONOPERATETYPE_USER_REVOKE_COMPLAINT ComplaintNegotiationOperateType = "USER_REVOKE_COMPLAINT"
171 COMPLAINTNEGOTIATIONOPERATETYPE_USER_COMFIRM_COMPLAINT ComplaintNegotiationOperateType = "USER_COMFIRM_COMPLAINT"
172 COMPLAINTNEGOTIATIONOPERATETYPE_PLATFORM_HELP_APPLICATION ComplaintNegotiationOperateType = "PLATFORM_HELP_APPLICATION"
173 COMPLAINTNEGOTIATIONOPERATETYPE_USER_APPLY_PLATFORM_HELP ComplaintNegotiationOperateType = "USER_APPLY_PLATFORM_HELP"
174 COMPLAINTNEGOTIATIONOPERATETYPE_MERCHANT_APPROVE_REFUND ComplaintNegotiationOperateType = "MERCHANT_APPROVE_REFUND"
175 COMPLAINTNEGOTIATIONOPERATETYPE_MERCHANT_REFUSE_RERUND ComplaintNegotiationOperateType = "MERCHANT_REFUSE_RERUND"
176 COMPLAINTNEGOTIATIONOPERATETYPE_USER_SUBMIT_SATISFACTION ComplaintNegotiationOperateType = "USER_SUBMIT_SATISFACTION"
177 COMPLAINTNEGOTIATIONOPERATETYPE_SERVICE_ORDER_CANCEL ComplaintNegotiationOperateType = "SERVICE_ORDER_CANCEL"
178 COMPLAINTNEGOTIATIONOPERATETYPE_SERVICE_ORDER_COMPLETE ComplaintNegotiationOperateType = "SERVICE_ORDER_COMPLETE"
179 COMPLAINTNEGOTIATIONOPERATETYPE_COMPLAINT_PARTIAL_REFUNDED_SYSTEM_MESSAGE ComplaintNegotiationOperateType = "COMPLAINT_PARTIAL_REFUNDED_SYSTEM_MESSAGE"
180 COMPLAINTNEGOTIATIONOPERATETYPE_COMPLAINT_REFUND_RECEIVED_SYSTEM_MESSAGE ComplaintNegotiationOperateType = "COMPLAINT_REFUND_RECEIVED_SYSTEM_MESSAGE"
181 COMPLAINTNEGOTIATIONOPERATETYPE_COMPLAINT_ENTRUSTED_REFUND_SYSTEM_MESSAGE ComplaintNegotiationOperateType = "COMPLAINT_ENTRUSTED_REFUND_SYSTEM_MESSAGE"
182 COMPLAINTNEGOTIATIONOPERATETYPE_USER_APPLY_PLATFORM_SERVICE ComplaintNegotiationOperateType = "USER_APPLY_PLATFORM_SERVICE"
183 COMPLAINTNEGOTIATIONOPERATETYPE_USER_CANCEL_PLATFORM_SERVICE ComplaintNegotiationOperateType = "USER_CANCEL_PLATFORM_SERVICE"
184 COMPLAINTNEGOTIATIONOPERATETYPE_PLATFORM_SERVICE_FINISHED ComplaintNegotiationOperateType = "PLATFORM_SERVICE_FINISHED"
185 COMPLAINTNEGOTIATIONOPERATETYPE_USER_CLICK_RESPONSE ComplaintNegotiationOperateType = "USER_CLICK_RESPONSE"
186)
187
188type ComplaintMedia struct {
189 MediaType *ComplaintMediaType `json:"media_type,omitempty"`
190 MediaUrl []string `json:"media_url,omitempty"`
191}
192
193type NormalMessage struct {
194 Blocks []Block `json:"blocks,omitempty"`
195 SenderIdentity *SenderIdentity `json:"sender_identity,omitempty"`
196 CustomData *string `json:"custom_data,omitempty"`
197}
198
199type ClickMessage struct {
200 MessageContent *string `json:"message_content,omitempty"`
201 ActionId *string `json:"action_id,omitempty"`
202 ClickedLogId *string `json:"clicked_log_id,omitempty"`
203}
204
205type ComplaintMediaType string
206
207func (e ComplaintMediaType) Ptr() *ComplaintMediaType {
208 return &e
209}
210
211const (
212 COMPLAINTMEDIATYPE_USER_COMPLAINT_IMAGE ComplaintMediaType = "USER_COMPLAINT_IMAGE"
213 COMPLAINTMEDIATYPE_OPERATION_IMAGE ComplaintMediaType = "OPERATION_IMAGE"
214)
215
216type Block struct {
217 Type *BlockType `json:"type,omitempty"`
218 Text *Text `json:"text,omitempty"`
219 Image *Image `json:"image,omitempty"`
220 Link *Link `json:"link,omitempty"`
221 FaqList *FaqList `json:"faq_list,omitempty"`
222 Button *Button `json:"button,omitempty"`
223 ButtonGroup *ButtonGroup `json:"button_group,omitempty"`
224}
225
226type SenderIdentity string
227
228func (e SenderIdentity) Ptr() *SenderIdentity {
229 return &e
230}
231
232const (
233 SENDERIDENTITY_UNKNOWN SenderIdentity = "UNKNOWN"
234 SENDERIDENTITY_MANUAL SenderIdentity = "MANUAL"
235 SENDERIDENTITY_MACHINE SenderIdentity = "MACHINE"
236)
237
238type BlockType string
239
240func (e BlockType) Ptr() *BlockType {
241 return &e
242}
243
244const (
245 BLOCKTYPE_TEXT BlockType = "TEXT"
246 BLOCKTYPE_IMAGE BlockType = "IMAGE"
247 BLOCKTYPE_LINK BlockType = "LINK"
248 BLOCKTYPE_FAQ_LIST BlockType = "FAQ_LIST"
249 BLOCKTYPE_BUTTON BlockType = "BUTTON"
250 BLOCKTYPE_BUTTON_GROUP BlockType = "BUTTON_GROUP"
251)
252
253type Text struct {
254 Text *string `json:"text,omitempty"`
255 Color *TextColor `json:"color,omitempty"`
256 IsBold *bool `json:"is_bold,omitempty"`
257}
258
259type Image struct {
260 MediaId *string `json:"media_id,omitempty"`
261 ImageStyleType *ImageStyleType `json:"image_style_type,omitempty"`
262}
263
264type Link struct {
265 Text *string `json:"text,omitempty"`
266 Action *ClickAction `json:"action,omitempty"`
267 InvalidInfo *InvalidInfo `json:"invalid_info,omitempty"`
268}
269
270type FaqList struct {
271 Faqs []FaqListItem `json:"faqs,omitempty"`
272}
273
274type Button struct {
275 Text *string `json:"text,omitempty"`
276 Action *ClickAction `json:"action,omitempty"`
277 InvalidInfo *InvalidInfo `json:"invalid_info,omitempty"`
278}
279
280type ButtonGroup struct {
281 Buttons []InnerButton `json:"buttons,omitempty"`
282 ButtonLayout *ButtonLayout `json:"button_layout,omitempty"`
283 InvalidInfo *InvalidInfo `json:"invalid_info,omitempty"`
284}
285
286type TextColor string
287
288func (e TextColor) Ptr() *TextColor {
289 return &e
290}
291
292const (
293 TEXTCOLOR_DEFAULT TextColor = "DEFAULT"
294 TEXTCOLOR_SECONDARY TextColor = "SECONDARY"
295)
296
297type ImageStyleType string
298
299func (e ImageStyleType) Ptr() *ImageStyleType {
300 return &e
301}
302
303const (
304 IMAGESTYLETYPE_IMAGE_STYLE_TYPE_NARROW ImageStyleType = "IMAGE_STYLE_TYPE_NARROW"
305 IMAGESTYLETYPE_IMAGE_STYLE_TYPE_WIDE ImageStyleType = "IMAGE_STYLE_TYPE_WIDE"
306)
307
308type ClickAction struct {
309 ActionType *ActionType `json:"action_type,omitempty"`
310 JumpUrl *string `json:"jump_url,omitempty"`
311 MiniProgramJumpInfo *MiniProgramJump `json:"mini_program_jump_info,omitempty"`
312 MessageInfo *MessageInfo `json:"message_info,omitempty"`
313 ActionId *string `json:"action_id,omitempty"`
314}
315
316type InvalidInfo struct {
317 ExpiredTime *string `json:"expired_time,omitempty"`
318 MultiClickable *bool `json:"multi_clickable,omitempty"`
319}
320
321type FaqListItem struct {
322 FaqId *string `json:"faq_id,omitempty"`
323 FaqTitle *string `json:"faq_title,omitempty"`
324 Action *ClickAction `json:"action,omitempty"`
325}
326
327type InnerButton struct {
328 Text *string `json:"text,omitempty"`
329 Action *ClickAction `json:"action,omitempty"`
330}
331
332type ButtonLayout string
333
334func (e ButtonLayout) Ptr() *ButtonLayout {
335 return &e
336}
337
338const (
339 BUTTONLAYOUT_LAYOUT_UNKNOWN ButtonLayout = "LAYOUT_UNKNOWN"
340 BUTTONLAYOUT_LAYOUT_HORIZONTAL ButtonLayout = "LAYOUT_HORIZONTAL"
341 BUTTONLAYOUT_LAYOUT_VERTICAL ButtonLayout = "LAYOUT_VERTICAL"
342)
343
344type ActionType string
345
346func (e ActionType) Ptr() *ActionType {
347 return &e
348}
349
350const (
351 ACTIONTYPE_ACTION_TYPE_SEND_MESSAGE ActionType = "ACTION_TYPE_SEND_MESSAGE"
352 ACTIONTYPE_ACTION_TYPE_JUMP_URL ActionType = "ACTION_TYPE_JUMP_URL"
353 ACTIONTYPE_ACTION_TYPE_JUMP_MINI_PROGRAM ActionType = "ACTION_TYPE_JUMP_MINI_PROGRAM"
354)
355
356type MiniProgramJump struct {
357 Appid *string `json:"appid,omitempty"`
358 Path *string `json:"path,omitempty"`
359}
360
361type MessageInfo struct {
362 Content *string `json:"content,omitempty"`
363 CustomData *string `json:"custom_data,omitempty"`
364}
365