
1package main
2
3import (
4 "demo/wxpay_utility"
5 "encoding/json"
6 "fmt"
7 "net/http"
8 "net/url"
9)
10
11func main() {
12
13 config, err := wxpay_utility.CreateMchConfig(
14 "19xxxxxxxx",
15 "1DDE55AD98Exxxxxxxxxx",
16 "/path/to/apiclient_key.pem",
17 "PUB_KEY_ID_xxxxxxxxxxxxx",
18 "/path/to/wxp_pub.pem",
19 )
20 if err != nil {
21 fmt.Println(err)
22 return
23 }
24
25 request := &GetAuditResultRequest{
26 ApplymentId: wxpay_utility.Int64(20000011111),
27 BusinessCode: wxpay_utility.String("1900013511_10000"),
28 }
29
30 response, err := GetAuditResult(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 GetAuditResult(config *wxpay_utility.MchConfig, request *GetAuditResultRequest) (response *GetAuditResultResponse, err error) {
42 const (
43 host = "https://api.mch.weixin.qq.com"
44 method = "GET"
45 path = "/v3/apply4subject/applyment"
46 )
47
48 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path))
49 if err != nil {
50 return nil, err
51 }
52 query := reqUrl.Query()
53 if request.ApplymentId != nil {
54 query.Add("applyment_id", fmt.Sprintf("%v", *request.ApplymentId))
55 }
56 if request.BusinessCode != nil {
57 query.Add("business_code", *request.BusinessCode)
58 }
59 reqUrl.RawQuery = query.Encode()
60 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil)
61 if err != nil {
62 return nil, err
63 }
64 httpRequest.Header.Set("Accept", "application/json")
65 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId())
66 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil)
67 if err != nil {
68 return nil, err
69 }
70 httpRequest.Header.Set("Authorization", authorization)
71
72 client := &http.Client{}
73 httpResponse, err := client.Do(httpRequest)
74 if err != nil {
75 return nil, err
76 }
77 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse)
78 if err != nil {
79 return nil, err
80 }
81 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 {
82
83 err = wxpay_utility.ValidateResponse(
84 config.WechatPayPublicKeyId(),
85 config.WechatPayPublicKey(),
86 &httpResponse.Header,
87 respBody,
88 )
89 if err != nil {
90 return nil, err
91 }
92 response := &GetAuditResultResponse{}
93 if err := json.Unmarshal(respBody, response); err != nil {
94 return nil, err
95 }
96
97 return response, nil
98 } else {
99 return nil, wxpay_utility.NewApiException(
100 httpResponse.StatusCode,
101 httpResponse.Header,
102 respBody,
103 )
104 }
105}
106
107type GetAuditResultRequest struct {
108 ApplymentId *int64 `json:"applyment_id,omitempty"`
109 BusinessCode *string `json:"business_code,omitempty"`
110}
111
112func (o *GetAuditResultRequest) MarshalJSON() ([]byte, error) {
113 type Alias GetAuditResultRequest
114 a := &struct {
115 ApplymentId *int64 `json:"applyment_id,omitempty"`
116 BusinessCode *string `json:"business_code,omitempty"`
117 *Alias
118 }{
119
120 ApplymentId: nil,
121 BusinessCode: nil,
122 Alias: (*Alias)(o),
123 }
124 return json.Marshal(a)
125}
126
127type GetAuditResultResponse struct {
128 ApplymentState *ApplymentState `json:"applyment_state,omitempty"`
129 QrcodeData *string `json:"qrcode_data,omitempty"`
130 RejectParam *string `json:"reject_param,omitempty"`
131 RejectReason *string `json:"reject_reason,omitempty"`
132}
133
134type ApplymentState string
135
136func (e ApplymentState) Ptr() *ApplymentState {
137 return &e
138}
139
140const (
141 APPLYMENTSTATE_APPLYMENT_STATE_EDITTING ApplymentState = "APPLYMENT_STATE_EDITTING"
142 APPLYMENTSTATE_APPLYMENT_STATE_WAITTING_FOR_AUDIT ApplymentState = "APPLYMENT_STATE_WAITTING_FOR_AUDIT"
143 APPLYMENTSTATE_APPLYMENT_STATE_WAITTING_FOR_CONFIRM_CONTACT ApplymentState = "APPLYMENT_STATE_WAITTING_FOR_CONFIRM_CONTACT"
144 APPLYMENTSTATE_APPLYMENT_STATE_WAITTING_FOR_CONFIRM_LEGALPERSON ApplymentState = "APPLYMENT_STATE_WAITTING_FOR_CONFIRM_LEGALPERSON"
145 APPLYMENTSTATE_APPLYMENT_STATE_PASSED ApplymentState = "APPLYMENT_STATE_PASSED"
146 APPLYMENTSTATE_APPLYMENT_STATE_REJECTED ApplymentState = "APPLYMENT_STATE_REJECTED"
147 APPLYMENTSTATE_APPLYMENT_STATE_FREEZED ApplymentState = "APPLYMENT_STATE_FREEZED"
148 APPLYMENTSTATE_APPLYMENT_STATE_CANCELED ApplymentState = "APPLYMENT_STATE_CANCELED"
149)
150