
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 := &GetBrandStoreRequest{
27 BrandId: wxpay_utility.String("123456789"),
28 StoreId: wxpay_utility.String("1234567890123456"),
29 }
30
31 response, err := GetBrandStore(config, request)
32 if err != nil {
33 fmt.Printf("请求失败: %+v\n", err)
34
35 return
36 }
37
38
39 fmt.Printf("请求成功: %+v\n", response)
40}
41
42func GetBrandStore(config *wxpay_utility.MchConfig, request *GetBrandStoreRequest) (response *BrandStoresEntity, err error) {
43 const (
44 host = "https://api.mch.weixin.qq.com"
45 method = "GET"
46 path = "/v3/brand/partner/store/brandstores/{store_id}"
47 )
48
49 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path))
50 if err != nil {
51 return nil, err
52 }
53 reqUrl.Path = strings.Replace(reqUrl.Path, "{store_id}", url.PathEscape(*request.StoreId), -1)
54 query := reqUrl.Query()
55 if request.BrandId != nil {
56 query.Add("brand_id", *request.BrandId)
57 }
58 reqUrl.RawQuery = query.Encode()
59 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil)
60 if err != nil {
61 return nil, err
62 }
63 httpRequest.Header.Set("Accept", "application/json")
64 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId())
65 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil)
66 if err != nil {
67 return nil, err
68 }
69 httpRequest.Header.Set("Authorization", authorization)
70
71 client := &http.Client{}
72 httpResponse, err := client.Do(httpRequest)
73 if err != nil {
74 return nil, err
75 }
76 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse)
77 if err != nil {
78 return nil, err
79 }
80 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 {
81
82 err = wxpay_utility.ValidateResponse(
83 config.WechatPayPublicKeyId(),
84 config.WechatPayPublicKey(),
85 &httpResponse.Header,
86 respBody,
87 )
88 if err != nil {
89 return nil, err
90 }
91 response := &BrandStoresEntity{}
92 if err := json.Unmarshal(respBody, response); err != nil {
93 return nil, err
94 }
95
96 return response, nil
97 } else {
98 return nil, wxpay_utility.NewApiException(
99 httpResponse.StatusCode,
100 httpResponse.Header,
101 respBody,
102 )
103 }
104}
105
106type GetBrandStoreRequest struct {
107 BrandId *string `json:"brand_id,omitempty"`
108 StoreId *string `json:"store_id,omitempty"`
109}
110
111func (o *GetBrandStoreRequest) MarshalJSON() ([]byte, error) {
112 type Alias GetBrandStoreRequest
113 a := &struct {
114 BrandId *string `json:"brand_id,omitempty"`
115 StoreId *string `json:"store_id,omitempty"`
116 *Alias
117 }{
118
119 BrandId: nil,
120 StoreId: nil,
121 Alias: (*Alias)(o),
122 }
123 return json.Marshal(a)
124}
125
126type BrandStoresEntity struct {
127 BrandId *string `json:"brand_id,omitempty"`
128 StoreId *string `json:"store_id,omitempty"`
129 StoreState *StoreState `json:"store_state,omitempty"`
130 AuditState *AuditState `json:"audit_state,omitempty"`
131 ReviewRejectReason *string `json:"review_reject_reason,omitempty"`
132 StoreBasics *StoreBase `json:"store_basics,omitempty"`
133 StoreAddress *StoreLocation `json:"store_address,omitempty"`
134 StoreBusiness *StoreBusiness `json:"store_business,omitempty"`
135 StoreRecipient []StoreRecipient `json:"store_recipient,omitempty"`
136}
137
138type StoreState string
139
140func (e StoreState) Ptr() *StoreState {
141 return &e
142}
143
144const (
145 STORESTATE_OPEN StoreState = "OPEN"
146 STORESTATE_CREATING StoreState = "CREATING"
147 STORESTATE_CLOSED StoreState = "CLOSED"
148)
149
150type AuditState string
151
152func (e AuditState) Ptr() *AuditState {
153 return &e
154}
155
156const (
157 AUDITSTATE_SUCCESS AuditState = "SUCCESS"
158 AUDITSTATE_PROCESSING AuditState = "PROCESSING"
159 AUDITSTATE_REJECTED AuditState = "REJECTED"
160)
161
162type StoreBase struct {
163 StoreReferenceId *string `json:"store_reference_id,omitempty"`
164 BranchName *string `json:"branch_name,omitempty"`
165}
166
167type StoreLocation struct {
168 AddressCode *string `json:"address_code,omitempty"`
169 AddressDetail *string `json:"address_detail,omitempty"`
170 AddressComplements *string `json:"address_complements,omitempty"`
171 Longitude *string `json:"longitude,omitempty"`
172 Latitude *string `json:"latitude,omitempty"`
173}
174
175type StoreBusiness struct {
176 ServicePhone *string `json:"service_phone,omitempty"`
177 BusinessHours *string `json:"business_hours,omitempty"`
178}
179
180type StoreRecipient struct {
181 Mchid *string `json:"mchid,omitempty"`
182 CompanyName *string `json:"company_name,omitempty"`
183 RecipientState *RecipientState `json:"recipient_state,omitempty"`
184}
185
186type RecipientState string
187
188func (e RecipientState) Ptr() *RecipientState {
189 return &e
190}
191
192const (
193 RECIPIENTSTATE_CONFIRMED RecipientState = "CONFIRMED"
194 RECIPIENTSTATE_ADMIN_REJECTED RecipientState = "ADMIN_REJECTED"
195 RECIPIENTSTATE_CONFIRMING RecipientState = "CONFIRMING"
196 RECIPIENTSTATE_TIMEOUT_REJECTED RecipientState = "TIMEOUT_REJECTED"
197)
198