
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 := &GetApplyByOutRequestNoRequest{
27 OutRequestNo: wxpay_utility.String("P202410241010125346"),
28 }
29
30 response, err := GetApplyByOutRequestNo(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 GetApplyByOutRequestNo(config *wxpay_utility.MchConfig, request *GetApplyByOutRequestNoRequest) (response *CancelWithdrawaApplyData, err error) {
42 const (
43 host = "https://api.mch.weixin.qq.com"
44 method = "GET"
45 path = "/v3/ecommerce/account/apply-cancel-withdraw/out-request-no/{out_request_no}"
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, "{out_request_no}", url.PathEscape(*request.OutRequestNo), -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 := &CancelWithdrawaApplyData{}
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 GetApplyByOutRequestNoRequest struct {
101 OutRequestNo *string `json:"out_request_no,omitempty"`
102}
103
104func (o *GetApplyByOutRequestNoRequest) MarshalJSON() ([]byte, error) {
105 type Alias GetApplyByOutRequestNoRequest
106 a := &struct {
107 OutRequestNo *string `json:"out_request_no,omitempty"`
108 *Alias
109 }{
110
111 OutRequestNo: nil,
112 Alias: (*Alias)(o),
113 }
114 return json.Marshal(a)
115}
116
117type CancelWithdrawaApplyData struct {
118 ApplymentId *string `json:"applyment_id,omitempty"`
119 OutRequestNo *string `json:"out_request_no,omitempty"`
120 CancelState *CancelState `json:"cancel_state,omitempty"`
121 CancelStateDescription *string `json:"cancel_state_description,omitempty"`
122 Withdraw *ApplyWithdraw `json:"withdraw,omitempty"`
123 WithdrawState *WithdrawState `json:"withdraw_state,omitempty"`
124 WithdrawStateDescription *string `json:"withdraw_state_description,omitempty"`
125 AccountWithdrawResult []AccountWithdrawResult `json:"account_withdraw_result,omitempty"`
126 ModifyTime *string `json:"modify_time,omitempty"`
127 SubMchid *string `json:"sub_mchid,omitempty"`
128 AccountInfo []AccountInfo `json:"account_info,omitempty"`
129}
130
131type CancelState string
132
133func (e CancelState) Ptr() *CancelState {
134 return &e
135}
136
137const (
138 CANCELSTATE_ACCEPTED CancelState = "ACCEPTED"
139 CANCELSTATE_REVIEWING CancelState = "REVIEWING"
140 CANCELSTATE_REJECTED CancelState = "REJECTED"
141 CANCELSTATE_WAITING_MERCHANT_CONFIRM CancelState = "WAITING_MERCHANT_CONFIRM"
142 CANCELSTATE_REVOKED CancelState = "REVOKED"
143 CANCELSTATE_SYSTEM_PROCESSING CancelState = "SYSTEM_PROCESSING"
144 CANCELSTATE_CANCELED CancelState = "CANCELED"
145 CANCELSTATE_FUND_PROCESSING CancelState = "FUND_PROCESSING"
146 CANCELSTATE_FINISH CancelState = "FINISH"
147)
148
149type ApplyWithdraw string
150
151func (e ApplyWithdraw) Ptr() *ApplyWithdraw {
152 return &e
153}
154
155const (
156 APPLYWITHDRAW_NOT_APPLY_WITHDRAW ApplyWithdraw = "NOT_APPLY_WITHDRAW"
157 APPLYWITHDRAW_APPLY_WITHDRAW ApplyWithdraw = "APPLY_WITHDRAW"
158)
159
160type WithdrawState string
161
162func (e WithdrawState) Ptr() *WithdrawState {
163 return &e
164}
165
166const (
167 WITHDRAWSTATE_WITHDRAW_PROCESSING WithdrawState = "WITHDRAW_PROCESSING"
168 WITHDRAWSTATE_WITHDRAW_EXCEPTION WithdrawState = "WITHDRAW_EXCEPTION"
169 WITHDRAWSTATE_WITHDRAW_SUCCEED WithdrawState = "WITHDRAW_SUCCEED"
170)
171
172type AccountWithdrawResult struct {
173 OutAccountType *OutAccountType `json:"out_account_type,omitempty"`
174 PayState *PayState `json:"pay_state,omitempty"`
175 StateDescription *string `json:"state_description,omitempty"`
176}
177
178type AccountInfo struct {
179 OutAccountType *OutAccountType `json:"out_account_type,omitempty"`
180 Amount *int64 `json:"amount,omitempty"`
181}
182
183type OutAccountType string
184
185func (e OutAccountType) Ptr() *OutAccountType {
186 return &e
187}
188
189const (
190 OUTACCOUNTTYPE_BASIC_ACCOUNT OutAccountType = "BASIC_ACCOUNT"
191 OUTACCOUNTTYPE_OPERATE_ACCOUNT OutAccountType = "OPERATE_ACCOUNT"
192 OUTACCOUNTTYPE_MARGIN_ACCOUNT OutAccountType = "MARGIN_ACCOUNT"
193 OUTACCOUNTTYPE_TRADE_FEE_ACCOUNT OutAccountType = "TRADE_FEE_ACCOUNT"
194)
195
196type PayState string
197
198func (e PayState) Ptr() *PayState {
199 return &e
200}
201
202const (
203 PAYSTATE_PAY_PROCESSING PayState = "PAY_PROCESSING"
204 PAYSTATE_PAY_SUCCEED PayState = "PAY_SUCCEED"
205 PAYSTATE_PAY_FAIL PayState = "PAY_FAIL"
206 PAYSTATE_BANK_REFUNDED PayState = "BANK_REFUNDED"
207)
208