
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 := &QueryComplaintV2Request{
27 ComplaintId: wxpay_utility.String("200201820200101080076610000"),
28 }
29
30 response, err := QueryComplaintV2(config, request)
31 if err != nil {
32 fmt.Printf("请求失败: %+v\n", err)
33
34 return
35 }
36
37
38 fmt.Printf("请求成功: %+v\n", response)
39}
40
41func QueryComplaintV2(config *wxpay_utility.MchConfig, request *QueryComplaintV2Request) (response *ComplaintInfo, err error) {
42 const (
43 host = "https://api.mch.weixin.qq.com"
44 method = "GET"
45 path = "/v3/merchant-service/complaints-v2/{complaint_id}"
46 )
47
48 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path))
49 if err != nil {
50 return nil, err
51 }
52 reqUrl.Path = strings.Replace(reqUrl.Path, "{complaint_id}", url.PathEscape(*request.ComplaintId), -1)
53 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil)
54 if err != nil {
55 return nil, err
56 }
57 httpRequest.Header.Set("Accept", "application/json")
58 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId())
59 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil)
60 if err != nil {
61 return nil, err
62 }
63 httpRequest.Header.Set("Authorization", authorization)
64
65 client := &http.Client{}
66 httpResponse, err := client.Do(httpRequest)
67 if err != nil {
68 return nil, err
69 }
70 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse)
71 if err != nil {
72 return nil, err
73 }
74 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 {
75
76 err = wxpay_utility.ValidateResponse(
77 config.WechatPayPublicKeyId(),
78 config.WechatPayPublicKey(),
79 &httpResponse.Header,
80 respBody,
81 )
82 if err != nil {
83 return nil, err
84 }
85 response := &ComplaintInfo{}
86 if err := json.Unmarshal(respBody, response); err != nil {
87 return nil, err
88 }
89
90 return response, nil
91 } else {
92 return nil, wxpay_utility.NewApiException(
93 httpResponse.StatusCode,
94 httpResponse.Header,
95 respBody,
96 )
97 }
98}
99
100type QueryComplaintV2Request struct {
101 ComplaintId *string `json:"complaint_id,omitempty"`
102}
103
104func (o *QueryComplaintV2Request) MarshalJSON() ([]byte, error) {
105 type Alias QueryComplaintV2Request
106 a := &struct {
107 ComplaintId *string `json:"complaint_id,omitempty"`
108 *Alias
109 }{
110
111 ComplaintId: nil,
112 Alias: (*Alias)(o),
113 }
114 return json.Marshal(a)
115}
116
117type ComplaintInfo struct {
118 ComplaintId *string `json:"complaint_id,omitempty"`
119 ComplaintTime *string `json:"complaint_time,omitempty"`
120 ComplaintDetail *string `json:"complaint_detail,omitempty"`
121 ComplaintState *string `json:"complaint_state,omitempty"`
122 PayerPhone *string `json:"payer_phone,omitempty"`
123 PayerOpenid *string `json:"payer_openid,omitempty"`
124 ComplaintOrderInfo []ComplaintOrderInfo `json:"complaint_order_info,omitempty"`
125 ComplaintFullRefunded *bool `json:"complaint_full_refunded,omitempty"`
126 IncomingUserResponse *bool `json:"incoming_user_response,omitempty"`
127 UserComplaintTimes *int64 `json:"user_complaint_times,omitempty"`
128 ComplaintMediaList []ComplaintMedia `json:"complaint_media_list,omitempty"`
129 ProblemDescription *string `json:"problem_description,omitempty"`
130 ProblemType *ProblemType `json:"problem_type,omitempty"`
131 ApplyRefundAmount *int64 `json:"apply_refund_amount,omitempty"`
132 UserTagList []UserTag `json:"user_tag_list,omitempty"`
133 ServiceOrderInfo []ServiceOrderInfo `json:"service_order_info,omitempty"`
134 AdditionalInfo *AdditionalInfo `json:"additional_info,omitempty"`
135 InPlatformService *bool `json:"in_platform_service,omitempty"`
136 NeedImmediateService *bool `json:"need_immediate_service,omitempty"`
137 IsAgentMode *bool `json:"is_agent_mode,omitempty"`
138}
139
140type ComplaintOrderInfo struct {
141 TransactionId *string `json:"transaction_id,omitempty"`
142 OutTradeNo *string `json:"out_trade_no,omitempty"`
143 Amount *int64 `json:"amount,omitempty"`
144}
145
146type ComplaintMedia struct {
147 MediaType *ComplaintMediaType `json:"media_type,omitempty"`
148 MediaUrl []string `json:"media_url,omitempty"`
149}
150
151type ProblemType string
152
153func (e ProblemType) Ptr() *ProblemType {
154 return &e
155}
156
157const (
158 PROBLEMTYPE_REFUND ProblemType = "REFUND"
159 PROBLEMTYPE_SERVICE_NOT_WORK ProblemType = "SERVICE_NOT_WORK"
160 PROBLEMTYPE_OTHERS ProblemType = "OTHERS"
161)
162
163type UserTag string
164
165func (e UserTag) Ptr() *UserTag {
166 return &e
167}
168
169const (
170 USERTAG_TRUSTED UserTag = "TRUSTED"
171 USERTAG_HIGH_RISK UserTag = "HIGH_RISK"
172)
173
174type ServiceOrderInfo struct {
175 OrderId *string `json:"order_id,omitempty"`
176 OutOrderNo *string `json:"out_order_no,omitempty"`
177 State *ServiceOrderState `json:"state,omitempty"`
178}
179
180type AdditionalInfo struct {
181 Type *AdditionalType `json:"type,omitempty"`
182 SharePowerInfo *SharePowerInfo `json:"share_power_info,omitempty"`
183}
184
185type ComplaintMediaType string
186
187func (e ComplaintMediaType) Ptr() *ComplaintMediaType {
188 return &e
189}
190
191const (
192 COMPLAINTMEDIATYPE_USER_COMPLAINT_IMAGE ComplaintMediaType = "USER_COMPLAINT_IMAGE"
193 COMPLAINTMEDIATYPE_OPERATION_IMAGE ComplaintMediaType = "OPERATION_IMAGE"
194)
195
196type ServiceOrderState string
197
198func (e ServiceOrderState) Ptr() *ServiceOrderState {
199 return &e
200}
201
202const (
203 SERVICEORDERSTATE_DOING ServiceOrderState = "DOING"
204 SERVICEORDERSTATE_REVOKED ServiceOrderState = "REVOKED"
205 SERVICEORDERSTATE_WAITPAY ServiceOrderState = "WAITPAY"
206 SERVICEORDERSTATE_DONE ServiceOrderState = "DONE"
207)
208
209type AdditionalType string
210
211func (e AdditionalType) Ptr() *AdditionalType {
212 return &e
213}
214
215const (
216 ADDITIONALTYPE_SHARE_POWER_TYPE AdditionalType = "SHARE_POWER_TYPE"
217)
218
219type SharePowerInfo struct {
220 ReturnTime *string `json:"return_time,omitempty"`
221 ReturnAddressInfo *ReturnAddressInfo `json:"return_address_info,omitempty"`
222 IsReturnedToSameMachine *bool `json:"is_returned_to_same_machine,omitempty"`
223}
224
225type ReturnAddressInfo struct {
226 ReturnAddress *string `json:"return_address,omitempty"`
227 Longitude *string `json:"longitude,omitempty"`
228 Latitude *string `json:"latitude,omitempty"`
229}
230