
1package main
2
3import (
4 "bytes"
5 "demo/wxpay_utility"
6 "encoding/json"
7 "fmt"
8 "net/http"
9 "net/url"
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 := &IssueRealEstateLeasingFapiaoRequest{
27 SubMchid: wxpay_utility.String("1900000109"),
28 FapiaoApplyId: wxpay_utility.String("4200000444201910177461284488"),
29 BuyerInformation: &UserTitleEntity{
30 Type: BUYERTYPE_INDIVIDUAL.Ptr(),
31 Name: wxpay_utility.String("深圳市南山区测试企业"),
32 TaxpayerId: wxpay_utility.String("202003261233701778"),
33 Address: wxpay_utility.String("深圳市南山区深南大道10000号"),
34 Telephone: wxpay_utility.String("075512345678"),
35 BankName: wxpay_utility.String("测试银行"),
36 BankAccount: wxpay_utility.String("62001234567890"),
37 Phone: wxpay_utility.String("mI7HGEJ4Q2B91IGjHrl7FNN9QuFPDfzeXoaJM4B8ZghZPzXK+vNotEZu/Gthm87Szv0MK2AoC0/3ZMDgltMtdoY6O0qZ4F1iXiwCuqkkBe+9M4ggvdzpPGM+fyed2QU1seUGbii5RVVVB9s+zLEQ8nv74vsgl77MZx14nd5obtCcfAvPfDJob3oG7FqlThmYKJqjiOwBvvQse7p9R8onj/POzSrbM8re8ZYGp4LcehXopTLdk2ZVWRv8bnJgKZWArAcqMdahq4jY2UVYeY4vpMmq4xuRTYk6xNXvowBBKK2SX8SqM+jm1USyoBIazLu4oaNFNdBO3fip1a1rFW0vRw=="),
38 Email: wxpay_utility.String("NzJy3r0Z2u2Vs5l+WSH0A3CZ1oGlCZ66aa2wUlMXNmACbd4wU8LqqYCuTG4cYWxrVUSmviV59/Uy9vLdIwuHZVrMalYAZGtb8inWGhDj3wUqQnPkmBKBVGIWG5Y6XJmMvpXW6rIKsdzxs8NwWj30cRNfjanLxiWc0aIgl8Knwo0JcxlcYLo38T9ntsrRkQZMQEWHaMYnzjp7ysLbp6yW83OZb/NwEufERBdPnIbDbVE7DUd5MGhvO+tlr2YC1b4VCsrDmjryuTD5nvYYCGHyfXW2CM23hZdBm9tPc+mU18Z9d4XkasnfsecGWd2ISkpPmnk3DtapnD64Nw8JyLtkgw=="),
39 Amount: wxpay_utility.Int64(1000),
40 OutTradeNo: wxpay_utility.String("order_20200701_123456"),
41 FapiaoBillType: FAPIAOBILLTYPE_COMM_FAPIAO.Ptr(),
42 UserApplyMessage: wxpay_utility.String("用户留言"),
43 },
44 FapiaoInformation: &IssueRealEstateLeasingFapiaoInfo{
45 FapiaoId: wxpay_utility.String("20200701123456"),
46 TotalAmount: wxpay_utility.Int64(382895),
47 Items: []IssueRealEstateLeasingItem{IssueRealEstateLeasingItem{
48 TaxCode: wxpay_utility.String("3010101020203000000"),
49 GoodsName: wxpay_utility.String("*经营租赁*车辆停放服务"),
50 Specification: wxpay_utility.String("米"),
51 Unit: REALESTATEUNIT_METER.Ptr(),
52 Quantity: wxpay_utility.Int64(100000000),
53 TotalAmount: wxpay_utility.Int64(429900),
54 TaxRate: wxpay_utility.Int64(1300),
55 Discount: wxpay_utility.Bool(false),
56 PreferentialPolicyCode: wxpay_utility.Int64(1),
57 RealEstateLeasingInformation: &RealEstateLeasingExtInfo{
58 Province: wxpay_utility.String("重庆市"),
59 City: wxpay_utility.String("涪陵区"),
60 Address: wxpay_utility.String("xx街道xx小区"),
61 LeasePeriodStart: wxpay_utility.String("2025-01-01T10:00:00+08:00"),
62 LeasePeriodEnd: wxpay_utility.String("2025-07-01T12:00:00+08:00"),
63 CrossCityFlag: wxpay_utility.Bool(true),
64 CertificateNo: wxpay_utility.String("OVgc/slzCvzSebaz46sUA4tJmm5GbNC0Tkp0oKmuHev9aTDzzcNIy5fKuywKWa0aYIWPyitr3wCYVPUw5Bnw1VUr6jn9eCeQPQye2t+zNuuCM0vmr1NNhdI3a2FNIx5HxkBrdM0XuiLt2/46UaWuzcUbZ52CCtZGgRzxeuj6oF/RKVG+dzT2HOm3kbYi1cUM10hARPKN+kV84I5WnFglX1cPM7s+OHkWvj38xEAfJBJfj3lf0UTRo"),
65 PlateNo: []string{"渝A12345"},
66 },
67 }},
68 ExportBusinessPolicyCode: wxpay_utility.Int64(1),
69 VatRefundLevyCode: wxpay_utility.Int64(1),
70 BillingPersonId: wxpay_utility.String("187776276864872"),
71 BillingPerson: wxpay_utility.String("**伟 0020"),
72 FapiaoBillType: FAPIAOBILLTYPE_COMM_FAPIAO.Ptr(),
73 TransactionInformation: []TransactionInfo{TransactionInfo{
74 PayChannel: PAYCHANNEL_WECHAT_PAY.Ptr(),
75 TransactionId: wxpay_utility.String("4200000008202508080512076713"),
76 OutTradeNo: wxpay_utility.String("order_20200701_123456"),
77 Amount: wxpay_utility.Int64(382895),
78 }},
79 Remark: wxpay_utility.String("备注"),
80 },
81 }
82
83 err = IssueSpecificIndustryFapiaoApplications(config, request)
84 if err != nil {
85 fmt.Printf("请求失败: %+v\n", err)
86
87 return
88 }
89
90
91 fmt.Println("请求成功")
92}
93
94func IssueSpecificIndustryFapiaoApplications(config *wxpay_utility.MchConfig, request *IssueRealEstateLeasingFapiaoRequest) (err error) {
95 const (
96 host = "https://api.mch.weixin.qq.com"
97 method = "POST"
98 path = "/v3/new-tax-control-fapiao/fapiao-applications/real-estate-leasing"
99 )
100
101 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path))
102 if err != nil {
103 return err
104 }
105 reqBody, err := json.Marshal(request)
106 if err != nil {
107 return err
108 }
109 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody))
110 if err != nil {
111 return err
112 }
113 httpRequest.Header.Set("Accept", "application/json")
114 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId())
115 httpRequest.Header.Set("Content-Type", "application/json")
116 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody)
117 if err != nil {
118 return err
119 }
120 httpRequest.Header.Set("Authorization", authorization)
121
122 client := &http.Client{}
123 httpResponse, err := client.Do(httpRequest)
124 if err != nil {
125 return err
126 }
127 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse)
128 if err != nil {
129 return err
130 }
131 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 {
132
133 err = wxpay_utility.ValidateResponse(
134 config.WechatPayPublicKeyId(),
135 config.WechatPayPublicKey(),
136 &httpResponse.Header,
137 respBody,
138 )
139 if err != nil {
140 return err
141 }
142 return nil
143 } else {
144 return wxpay_utility.NewApiException(
145 httpResponse.StatusCode,
146 httpResponse.Header,
147 respBody,
148 )
149 }
150}
151
152type IssueRealEstateLeasingFapiaoRequest struct {
153 SubMchid *string `json:"sub_mchid,omitempty"`
154 FapiaoApplyId *string `json:"fapiao_apply_id,omitempty"`
155 BuyerInformation *UserTitleEntity `json:"buyer_information,omitempty"`
156 FapiaoInformation *IssueRealEstateLeasingFapiaoInfo `json:"fapiao_information,omitempty"`
157}
158
159type UserTitleEntity struct {
160 Type *BuyerType `json:"type,omitempty"`
161 Name *string `json:"name,omitempty"`
162 TaxpayerId *string `json:"taxpayer_id,omitempty"`
163 Address *string `json:"address,omitempty"`
164 Telephone *string `json:"telephone,omitempty"`
165 BankName *string `json:"bank_name,omitempty"`
166 BankAccount *string `json:"bank_account,omitempty"`
167 Phone *string `json:"phone,omitempty"`
168 Email *string `json:"email,omitempty"`
169 Amount *int64 `json:"amount,omitempty"`
170 OutTradeNo *string `json:"out_trade_no,omitempty"`
171 FapiaoBillType *FapiaoBillType `json:"fapiao_bill_type,omitempty"`
172 UserApplyMessage *string `json:"user_apply_message,omitempty"`
173}
174
175type IssueRealEstateLeasingFapiaoInfo struct {
176 FapiaoId *string `json:"fapiao_id,omitempty"`
177 TotalAmount *int64 `json:"total_amount,omitempty"`
178 Items []IssueRealEstateLeasingItem `json:"items,omitempty"`
179 ExportBusinessPolicyCode *int64 `json:"export_business_policy_code,omitempty"`
180 VatRefundLevyCode *int64 `json:"vat_refund_levy_code,omitempty"`
181 BillingPersonId *string `json:"billing_person_id,omitempty"`
182 BillingPerson *string `json:"billing_person,omitempty"`
183 FapiaoBillType *FapiaoBillType `json:"fapiao_bill_type,omitempty"`
184 TransactionInformation []TransactionInfo `json:"transaction_information,omitempty"`
185 Remark *string `json:"remark,omitempty"`
186}
187
188type BuyerType string
189
190func (e BuyerType) Ptr() *BuyerType {
191 return &e
192}
193
194const (
195 BUYERTYPE_INDIVIDUAL BuyerType = "INDIVIDUAL"
196 BUYERTYPE_ORGANIZATION BuyerType = "ORGANIZATION"
197)
198
199type FapiaoBillType string
200
201func (e FapiaoBillType) Ptr() *FapiaoBillType {
202 return &e
203}
204
205const (
206 FAPIAOBILLTYPE_COMM_FAPIAO FapiaoBillType = "COMM_FAPIAO"
207 FAPIAOBILLTYPE_VAT_FAPIAO FapiaoBillType = "VAT_FAPIAO"
208)
209
210type IssueRealEstateLeasingItem struct {
211 TaxCode *string `json:"tax_code,omitempty"`
212 GoodsName *string `json:"goods_name,omitempty"`
213 Specification *string `json:"specification,omitempty"`
214 Unit *RealEstateUnit `json:"unit,omitempty"`
215 Quantity *int64 `json:"quantity,omitempty"`
216 TotalAmount *int64 `json:"total_amount,omitempty"`
217 TaxRate *int64 `json:"tax_rate,omitempty"`
218 Discount *bool `json:"discount,omitempty"`
219 PreferentialPolicyCode *int64 `json:"preferential_policy_code,omitempty"`
220 RealEstateLeasingInformation *RealEstateLeasingExtInfo `json:"real_estate_leasing_information,omitempty"`
221}
222
223type TransactionInfo struct {
224 PayChannel *PayChannel `json:"pay_channel,omitempty"`
225 TransactionId *string `json:"transaction_id,omitempty"`
226 OutTradeNo *string `json:"out_trade_no,omitempty"`
227 Amount *int64 `json:"amount,omitempty"`
228}
229
230type RealEstateUnit string
231
232func (e RealEstateUnit) Ptr() *RealEstateUnit {
233 return &e
234}
235
236const (
237 REALESTATEUNIT_METER RealEstateUnit = "METER"
238 REALESTATEUNIT_SQUARE_METER RealEstateUnit = "SQUARE_METER"
239 REALESTATEUNIT_SQUARE_KILOMETER RealEstateUnit = "SQUARE_KILOMETER"
240 REALESTATEUNIT_HECTARE RealEstateUnit = "HECTARE"
241 REALESTATEUNIT_SQUARE_KILOMETER_ABBREVIATION RealEstateUnit = "SQUARE_KILOMETER_ABBREVIATION"
242 REALESTATEUNIT_SQUARE_METER_ABBREVIATION RealEstateUnit = "SQUARE_METER_ABBREVIATION"
243 REALESTATEUNIT_HECTARE_ABBREVIATION RealEstateUnit = "HECTARE_ABBREVIATION"
244 REALESTATEUNIT_MU RealEstateUnit = "MU"
245)
246
247type RealEstateLeasingExtInfo struct {
248 Province *string `json:"province,omitempty"`
249 City *string `json:"city,omitempty"`
250 Address *string `json:"address,omitempty"`
251 LeasePeriodStart *string `json:"lease_period_start,omitempty"`
252 LeasePeriodEnd *string `json:"lease_period_end,omitempty"`
253 CrossCityFlag *bool `json:"cross_city_flag,omitempty"`
254 CertificateNo *string `json:"certificate_no,omitempty"`
255 PlateNo []string `json:"plate_no,omitempty"`
256}
257
258type PayChannel string
259
260func (e PayChannel) Ptr() *PayChannel {
261 return &e
262}
263
264const (
265 PAYCHANNEL_WECHAT_PAY PayChannel = "WECHAT_PAY"
266)
267