
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 := &GetMchArchiveRequest{
26 Mchid: wxpay_utility.String("1900016681"),
27 BalAccountNo: wxpay_utility.String("8609cb22e1774a50a930e414cc71eca06121bcd266335cda230d24a7886a8d9f"),
28 }
29
30 response, err := GetMchArchive(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 GetMchArchive(config *wxpay_utility.MchConfig, request *GetMchArchiveRequest) (response *MchArchive, err error) {
42 const (
43 host = "https://api.mch.weixin.qq.com"
44 method = "GET"
45 path = "/v3/aggracct-bc/wb-channel/account/mch_archives"
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.Mchid != nil {
54 query.Add("mchid", *request.Mchid)
55 }
56 if request.BalAccountNo != nil {
57 query.Add("bal_account_no", *request.BalAccountNo)
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 := &MchArchive{}
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 GetMchArchiveRequest struct {
108 Mchid *string `json:"mchid,omitempty"`
109 BalAccountNo *string `json:"bal_account_no,omitempty"`
110}
111
112func (o *GetMchArchiveRequest) MarshalJSON() ([]byte, error) {
113 type Alias GetMchArchiveRequest
114 a := &struct {
115 Mchid *string `json:"mchid,omitempty"`
116 BalAccountNo *string `json:"bal_account_no,omitempty"`
117 *Alias
118 }{
119
120 Mchid: nil,
121 BalAccountNo: nil,
122 Alias: (*Alias)(o),
123 }
124 return json.Marshal(a)
125}
126
127type MchArchive struct {
128 Mchid *string `json:"mchid,omitempty"`
129 BalAccountNo *string `json:"bal_account_no,omitempty"`
130 MerchantType *string `json:"merchant_type,omitempty"`
131 MerchantIdType *string `json:"merchant_id_type,omitempty"`
132 MerchantName *string `json:"merchant_name,omitempty"`
133 MerchantIdNo *string `json:"merchant_id_no,omitempty"`
134 EffectiveDate *string `json:"effective_date,omitempty"`
135 ExpireDate *string `json:"expire_date,omitempty"`
136 MerchantImgFrontId *string `json:"merchant_img_front_id,omitempty"`
137 RegisterAddress *string `json:"register_address,omitempty"`
138 BusinessScope *string `json:"business_scope,omitempty"`
139 LegalRepresentative *LegalRepresentative `json:"legal_representative,omitempty"`
140 BeneficialOwner []BeneficialOwner `json:"beneficial_owner,omitempty"`
141}
142
143type LegalRepresentative struct {
144 LegalRepresentativeIdType *string `json:"legal_representative_id_type,omitempty"`
145 LegalRepresentativeName *string `json:"legal_representative_name,omitempty"`
146 LegalRepresentativeIdNo *string `json:"legal_representative_id_no,omitempty"`
147 LegalRepresentativeEffectiveDate *string `json:"legal_representative_effective_date,omitempty"`
148 LegalRepresentativeExpireDate *string `json:"legal_representative_expire_date,omitempty"`
149 LegalRepresentativeImgFrontId *string `json:"legal_representative_img_front_id,omitempty"`
150 LegalRepresentativeImgBackId *string `json:"legal_representative_img_back_id,omitempty"`
151 LegalRepresentativeAddress *string `json:"legal_representative_address,omitempty"`
152}
153
154type BeneficialOwner struct {
155 BeneficialOwnerNo *string `json:"beneficial_owner_no,omitempty"`
156 BeneficialOwnerIdType *string `json:"beneficial_owner_id_type,omitempty"`
157 BeneficialOwnerName *string `json:"beneficial_owner_name,omitempty"`
158 BeneficialOwnerIdNo *string `json:"beneficial_owner_id_no,omitempty"`
159 BeneficialOwnerEffectiveDate *string `json:"beneficial_owner_effective_date,omitempty"`
160 BeneficialOwnerExpireDate *string `json:"beneficial_owner_expire_date,omitempty"`
161 BeneficialOwnerImgFrontId *string `json:"beneficial_owner_img_front_id,omitempty"`
162 BeneficialOwnerImgBackId *string `json:"beneficial_owner_img_back_id,omitempty"`
163 BeneficialOwnerAddress *string `json:"beneficial_owner_address,omitempty"`
164}
165