开具不动产租赁行业电子发票
更新时间:2025.09.03商户完成收款后,调用本接口开具不动产租赁行业电子发票并插入微信用户的卡包。请求的交易信息必须真实存在。
注意:本接口成功返回仅代表开票请求已被受理,当开票完成时,微信支付会根据商户配置的回调地址进行回调通知,商户也可以通过【查询电子发票】接口获取开票结果及开票信息。
接口说明
支持商户:【普通服务商】
请求方式:【POST】/v3/new-tax-control-fapiao/fapiao-applications/real-estate-leasing
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
Content-Type 必填 string
请设置为application/json
Wechatpay-Serial 必填 string
【微信支付公钥ID】或【微信支付平台证书序列号】 请求参数中的敏感字段,需要使用微信支付公钥加密(推荐),请参考获取微信支付公钥ID说明以及微信支付公钥加密敏感信息指引;也可以使用微信支付平台证书公钥加密,参考获取平台证书序列号、平台证书加密敏感信息指引
body 包体参数
sub_mchid 必填 string(32)
【子商户号】 微信支付分配的子商户号,具体请参考服务商模式开发必要参数说明
fapiao_apply_id 必填 string(32)
【发票申请单号】 发票申请单号,唯一标识一次开票行为。当需要开具交易信息为非微信支付渠道的发票时,为调用【获取用户抬头填写链接】接口时指定的发票申请单号
buyer_information 必填 object
【购买方信息】 购买方信息,即发票抬头。若商户使用微信官方抬头,可从【获取用户填写抬头信息】接口获取用户填写的抬头;也可自行收集发票抬头
属性 | |
type 必填 string 【购买方类型】 购买方类型 可选取值
name 必填 string(256) 【名称】 购买方名称 taxpayer_id 选填 string(32) 【纳税人识别号】 购买方纳税人识别号,购买方类型为ORGANIZATION时必填 address 选填 string(128) 【地址】 购买方地址 telephone 选填 string(32) 【电话】 购买方电话 bank_name 选填 string(128) 【开户银行名称】 购买方开户银行名称 bank_account 选填 string(32) 【银行账号】 购买方银行账号 phone 选填 string 【手机号】 用户手机号。注意:该字段为密文字段,作为请求字段需加密,使用微信支付公钥加密(推荐),参考获取微信支付公钥ID说明以及微信支付公钥加密敏感信息指引;也可以使用微信支付平台证书公钥加密,参考获取平台证书序列号、平台证书加密敏感信息指引;作为响应字段需解密,参考如何使用API证书解密敏感字段 email 选填 string 【邮箱地址】 用户邮箱地址。注意:该字段为密文字段,作为请求字段需加密,使用微信支付公钥加密(推荐),参考获取微信支付公钥ID说明以及微信支付公钥加密敏感信息指引;也可以使用微信支付平台证书公钥加密,参考获取平台证书序列号、平台证书加密敏感信息指引;作为响应字段需解密,参考如何使用API证书解密敏感字段 amount 选填 integer 【订单金额】 微信支付订单金额,仅在微信支付场景下有效,单位:分 out_trade_no 选填 string(32) 【商户订单号】 商户订单号,仅在微信支付场景下有效 fapiao_bill_type 选填 string 【开具的发票类型】 用户选择提交开具发票的类型 可选取值
user_apply_message 选填 string(100) 【留言信息】 用户申请开票时提交的留言信息 |
fapiao_information 必填 object
【需要开具的数电发票信息】 需要开具的不动产租赁特定行业数电发票信息
属性 | |||||||||||||
fapiao_id 必填 string(32) 【商户发票单号】 商户发票单号,唯一标识一张要开具的发票。只能是字母、数字、中划线-、下划线_、竖线|、星号*这些英文半角字符,且该单号在每个商户下必须唯一。当申请单下没有状态为开具中/已开具/冲红中的发票时,可以新增fapiao_id开票。1个fapiao_apply_id下最多支持5个fapiao_id total_amount 必填 integer 【总价税合计】 总价税合计,所有发票行信息中单行金额合计的累加,展示在发票的价税合计处,单位:分 注意:所有发票的总价税合计之和不能超过交易的总金额 items 必填 array[object] 【发票行信息】 发票行信息,单张发票的发票行不能超过8行
export_business_policy_code 选填 integer 【出口业务适用政策代码】 1:退税政策; 2:免税政策; 3:征税政策 vat_refund_levy_code 选填 integer 【增值税即征即退代码】 1:软件产品; 2:资源综合利用产品; 3:管道运输服务; 4:有形动产融资租赁服务; 5:有形动产融资性售后回租服务; 6:新型墙体材料; 7:风力发电产品; 8:光伏发电产品; 9:动漫软件产品; 10:飞机维修劳务; 11:黄金; 12:铂金 billing_person_id 必填 string(64) 【开票人ID】 税局乐企系统登记的开票人ID billing_person 选填 string(64) 【开票人名称】 税局乐企系统登记的开票人名称 fapiao_bill_type 必填 string 【发票类型】 商户提交申请开票的发票类型 可选取值
transaction_information 必填 array[object] 【交易信息】 发票对应的交易信息
remark 选填 string 【发票备注】 发票备注 |
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/fapiao-applications/real-estate-leasing \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Wechatpay-Serial: 5157F09EFDC096DE15EBE81A47057A7232F1B8E1" \ 6 -H "Content-Type: application/json" \ 7 -d '{ 8 "sub_mchid" : "1900000109", 9 "fapiao_apply_id" : "4200000444201910177461284488", 10 "buyer_information" : { 11 "type" : "INDIVIDUAL", 12 "name" : "深圳市南山区测试企业", 13 "taxpayer_id" : "202003261233701778", 14 "address" : "深圳市南山区深南大道10000号", 15 "telephone" : "075512345678", 16 "bank_name" : "测试银行", 17 "bank_account" : "62001234567890", 18 "phone" : "mI7HGEJ4Q2B91IGjHrl7FNN9QuFPDfzeXoaJM4B8ZghZPzXK+vNotEZu/Gthm87Szv0MK2AoC0/3ZMDgltMtdoY6O0qZ4F1iXiwCuqkkBe+9M4ggvdzpPGM+fyed2QU1seUGbii5RVVVB9s+zLEQ8nv74vsgl77MZx14nd5obtCcfAvPfDJob3oG7FqlThmYKJqjiOwBvvQse7p9R8onj/POzSrbM8re8ZYGp4LcehXopTLdk2ZVWRv8bnJgKZWArAcqMdahq4jY2UVYeY4vpMmq4xuRTYk6xNXvowBBKK2SX8SqM+jm1USyoBIazLu4oaNFNdBO3fip1a1rFW0vRw==", 19 "email" : "NzJy3r0Z2u2Vs5l+WSH0A3CZ1oGlCZ66aa2wUlMXNmACbd4wU8LqqYCuTG4cYWxrVUSmviV59/Uy9vLdIwuHZVrMalYAZGtb8inWGhDj3wUqQnPkmBKBVGIWG5Y6XJmMvpXW6rIKsdzxs8NwWj30cRNfjanLxiWc0aIgl8Knwo0JcxlcYLo38T9ntsrRkQZMQEWHaMYnzjp7ysLbp6yW83OZb/NwEufERBdPnIbDbVE7DUd5MGhvO+tlr2YC1b4VCsrDmjryuTD5nvYYCGHyfXW2CM23hZdBm9tPc+mU18Z9d4XkasnfsecGWd2ISkpPmnk3DtapnD64Nw8JyLtkgw==", 20 "amount" : 1000, 21 "out_trade_no" : "order_20200701_123456", 22 "fapiao_bill_type" : "COMM_FAPIAO", 23 "user_apply_message" : "用户留言" 24 }, 25 "fapiao_information" : { 26 "fapiao_id" : "20200701123456", 27 "total_amount" : 382895, 28 "items" : [ 29 { 30 "tax_code" : "3010101020203000000", 31 "goods_name" : "*经营租赁*车辆停放服务", 32 "specification" : "米", 33 "unit" : "METER", 34 "quantity" : 100000000, 35 "total_amount" : 429900, 36 "tax_rate" : 1300, 37 "discount" : false, 38 "preferential_policy_code" : 1, 39 "real_estate_leasing_information" : { 40 "province" : "重庆市", 41 "city" : "涪陵区", 42 "address" : "xx街道xx小区", 43 "lease_period_start" : "2025-01-01T10:00:00+08:00", 44 "lease_period_end" : "2025-07-01T12:00:00+08:00", 45 "cross_city_flag" : true, 46 "certificate_no" : "OVgc/slzCvzSebaz46sUA4tJmm5GbNC0Tkp0oKmuHev9aTDzzcNIy5fKuywKWa0aYIWPyitr3wCYVPUw5Bnw1VUr6jn9eCeQPQye2t+zNuuCM0vmr1NNhdI3a2FNIx5HxkBrdM0XuiLt2/46UaWuzcUbZ52CCtZGgRzxeuj6oF/RKVG+dzT2HOm3kbYi1cUM10hARPKN+kV84I5WnFglX1cPM7s+OHkWvj38xEAfJBJfj3lf0UTRo", 47 "plate_no" : [ 48 "渝A12345" 49 ] 50 } 51 } 52 ], 53 "export_business_policy_code" : 1, 54 "vat_refund_levy_code" : 1, 55 "billing_person_id" : "187776276864872", 56 "billing_person" : "张伟", 57 "fapiao_bill_type" : "COMM_FAPIAO", 58 "transaction_information" : [ 59 { 60 "pay_channel" : "WECHAT_PAY", 61 "transaction_id" : "4200000008202508080512076713", 62 "out_trade_no" : "order_20200701_123456", 63 "amount" : 382895 64 } 65 ], 66 "remark" : "备注" 67 } 68 }' 69
需配合微信支付工具库 WXPayUtility 使用,请参考 Java
1package com.java.demo; 2 3import com.java.utils.WXPayUtility; // 引用微信支付工具库,参考:https://pay.weixin.qq.com/doc/v3/partner/4014985777 4 5import com.google.gson.annotations.SerializedName; 6import com.google.gson.annotations.Expose; 7import okhttp3.MediaType; 8import okhttp3.OkHttpClient; 9import okhttp3.Request; 10import okhttp3.RequestBody; 11import okhttp3.Response; 12 13import java.io.IOException; 14import java.io.UncheckedIOException; 15import java.security.PrivateKey; 16import java.security.PublicKey; 17import java.util.ArrayList; 18import java.util.HashMap; 19import java.util.List; 20import java.util.Map; 21 22/** 23 * 开具不动产租赁行业电子发票 24 */ 25public class IssueSpecificIndustryFapiaoApplications { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/v3/new-tax-control-fapiao/fapiao-applications/real-estate-leasing"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 IssueSpecificIndustryFapiaoApplications client = new IssueSpecificIndustryFapiaoApplications( 33 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 34 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 35 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 36 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 37 "/path/to/wxp_pub.pem" // 微信支付公钥文件路径,本地文件路径 38 ); 39 40 IssueRealEstateLeasingFapiaoRequest request = new IssueRealEstateLeasingFapiaoRequest(); 41 request.subMchid = "1900000109"; 42 request.fapiaoApplyId = "4200000444201910177461284488"; 43 request.buyerInformation = new UserTitleEntity(); 44 request.buyerInformation.type = BuyerType.INDIVIDUAL; 45 request.buyerInformation.name = "深圳市南山区测试企业"; 46 request.buyerInformation.taxpayerId = "202003261233701778"; 47 request.buyerInformation.address = "深圳市南山区深南大道10000号"; 48 request.buyerInformation.telephone = "075512345678"; 49 request.buyerInformation.bankName = "测试银行"; 50 request.buyerInformation.bankAccount = "62001234567890"; 51 request.buyerInformation.phone = client.encrypt("phone"); 52 request.buyerInformation.email = client.encrypt("email"); 53 request.buyerInformation.amount = 1000L; 54 request.buyerInformation.outTradeNo = "order_20200701_123456"; 55 request.buyerInformation.fapiaoBillType = FapiaoBillType.COMM_FAPIAO; 56 request.buyerInformation.userApplyMessage = "用户留言"; 57 request.fapiaoInformation = new IssueRealEstateLeasingFapiaoInfo(); 58 request.fapiaoInformation.fapiaoId = "20200701123456"; 59 request.fapiaoInformation.totalAmount = 382895L; 60 request.fapiaoInformation.items = new ArrayList<>(); 61 { 62 IssueRealEstateLeasingItem itemsItem = new IssueRealEstateLeasingItem(); 63 itemsItem.taxCode = "3010101020203000000"; 64 itemsItem.goodsName = "*经营租赁*车辆停放服务"; 65 itemsItem.specification = "米"; 66 itemsItem.unit = RealEstateUnit.METER; 67 itemsItem.quantity = 100000000L; 68 itemsItem.totalAmount = 429900L; 69 itemsItem.taxRate = 1300L; 70 itemsItem.discount = false; 71 itemsItem.preferentialPolicyCode = 1L; 72 itemsItem.realEstateLeasingInformation = new RealEstateLeasingExtInfo(); 73 itemsItem.realEstateLeasingInformation.province = "重庆市"; 74 itemsItem.realEstateLeasingInformation.city = "涪陵区"; 75 itemsItem.realEstateLeasingInformation.address = "xx街道xx小区"; 76 itemsItem.realEstateLeasingInformation.leasePeriodStart = "2025-01-01T10:00:00+08:00"; 77 itemsItem.realEstateLeasingInformation.leasePeriodEnd = "2025-07-01T12:00:00+08:00"; 78 itemsItem.realEstateLeasingInformation.crossCityFlag = true; 79 itemsItem.realEstateLeasingInformation.certificateNo = client.encrypt("certificate_no"); 80 itemsItem.realEstateLeasingInformation.plateNo = new ArrayList<>(); 81 { 82 itemsItem.realEstateLeasingInformation.plateNo.add("渝A12345"); 83 }; 84 request.fapiaoInformation.items.add(itemsItem); 85 }; 86 request.fapiaoInformation.exportBusinessPolicyCode = 1L; 87 request.fapiaoInformation.vatRefundLevyCode = 1L; 88 request.fapiaoInformation.billingPersonId = "187776276864872"; 89 request.fapiaoInformation.billingPerson = "张伟"; 90 request.fapiaoInformation.fapiaoBillType = FapiaoBillType.COMM_FAPIAO; 91 request.fapiaoInformation.transactionInformation = new ArrayList<>(); 92 { 93 TransactionInfo transactionInformationItem = new TransactionInfo(); 94 transactionInformationItem.payChannel = PayChannel.WECHAT_PAY; 95 transactionInformationItem.transactionId = "4200000008202508080512076713"; 96 transactionInformationItem.outTradeNo = "order_20200701_123456"; 97 transactionInformationItem.amount = 382895L; 98 request.fapiaoInformation.transactionInformation.add(transactionInformationItem); 99 }; 100 request.fapiaoInformation.remark = "备注"; 101 try { 102 client.run(request); 103 } catch (WXPayUtility.ApiException e) { 104 // TODO: 请求失败,根据状态码执行不同的逻辑 105 e.printStackTrace(); 106 } 107 } 108 109 public void run(IssueRealEstateLeasingFapiaoRequest request) { 110 String uri = PATH; 111 String reqBody = WXPayUtility.toJson(request); 112 113 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 114 reqBuilder.addHeader("Accept", "application/json"); 115 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 116 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 117 reqBuilder.addHeader("Content-Type", "application/json"); 118 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 119 reqBuilder.method(METHOD, requestBody); 120 Request httpRequest = reqBuilder.build(); 121 122 // 发送HTTP请求 123 OkHttpClient client = new OkHttpClient.Builder().build(); 124 try (Response httpResponse = client.newCall(httpRequest).execute()) { 125 String respBody = WXPayUtility.extractBody(httpResponse); 126 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 127 // 2XX 成功,验证应答签名 128 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 129 httpResponse.headers(), respBody); 130 131 return; 132 } else { 133 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 134 } 135 } catch (IOException e) { 136 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 137 } 138 } 139 140 private final String mchid; 141 private final String certificateSerialNo; 142 private final PrivateKey privateKey; 143 private final String wechatPayPublicKeyId; 144 private final PublicKey wechatPayPublicKey; 145 146 public IssueSpecificIndustryFapiaoApplications(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 147 this.mchid = mchid; 148 this.certificateSerialNo = certificateSerialNo; 149 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 150 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 151 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 152 } 153 154 public String encrypt(String plainText) { 155 return WXPayUtility.encrypt(this.wechatPayPublicKey, plainText); 156 } 157 158 public static class IssueRealEstateLeasingFapiaoRequest { 159 @SerializedName("sub_mchid") 160 public String subMchid; 161 162 @SerializedName("fapiao_apply_id") 163 public String fapiaoApplyId; 164 165 @SerializedName("buyer_information") 166 public UserTitleEntity buyerInformation; 167 168 @SerializedName("fapiao_information") 169 public IssueRealEstateLeasingFapiaoInfo fapiaoInformation; 170 } 171 172 public static class UserTitleEntity { 173 @SerializedName("type") 174 public BuyerType type; 175 176 @SerializedName("name") 177 public String name; 178 179 @SerializedName("taxpayer_id") 180 public String taxpayerId; 181 182 @SerializedName("address") 183 public String address; 184 185 @SerializedName("telephone") 186 public String telephone; 187 188 @SerializedName("bank_name") 189 public String bankName; 190 191 @SerializedName("bank_account") 192 public String bankAccount; 193 194 @SerializedName("phone") 195 public String phone; 196 197 @SerializedName("email") 198 public String email; 199 200 @SerializedName("amount") 201 public Long amount; 202 203 @SerializedName("out_trade_no") 204 public String outTradeNo; 205 206 @SerializedName("fapiao_bill_type") 207 public FapiaoBillType fapiaoBillType; 208 209 @SerializedName("user_apply_message") 210 public String userApplyMessage; 211 } 212 213 public static class IssueRealEstateLeasingFapiaoInfo { 214 @SerializedName("fapiao_id") 215 public String fapiaoId; 216 217 @SerializedName("total_amount") 218 public Long totalAmount; 219 220 @SerializedName("items") 221 public List<IssueRealEstateLeasingItem> items = new ArrayList<IssueRealEstateLeasingItem>(); 222 223 @SerializedName("export_business_policy_code") 224 public Long exportBusinessPolicyCode; 225 226 @SerializedName("vat_refund_levy_code") 227 public Long vatRefundLevyCode; 228 229 @SerializedName("billing_person_id") 230 public String billingPersonId; 231 232 @SerializedName("billing_person") 233 public String billingPerson; 234 235 @SerializedName("fapiao_bill_type") 236 public FapiaoBillType fapiaoBillType; 237 238 @SerializedName("transaction_information") 239 public List<TransactionInfo> transactionInformation = new ArrayList<TransactionInfo>(); 240 241 @SerializedName("remark") 242 public String remark; 243 } 244 245 public enum BuyerType { 246 @SerializedName("INDIVIDUAL") 247 INDIVIDUAL, 248 @SerializedName("ORGANIZATION") 249 ORGANIZATION 250 } 251 252 public enum FapiaoBillType { 253 @SerializedName("COMM_FAPIAO") 254 COMM_FAPIAO, 255 @SerializedName("VAT_FAPIAO") 256 VAT_FAPIAO 257 } 258 259 public static class IssueRealEstateLeasingItem { 260 @SerializedName("tax_code") 261 public String taxCode; 262 263 @SerializedName("goods_name") 264 public String goodsName; 265 266 @SerializedName("specification") 267 public String specification; 268 269 @SerializedName("unit") 270 public RealEstateUnit unit; 271 272 @SerializedName("quantity") 273 public Long quantity; 274 275 @SerializedName("total_amount") 276 public Long totalAmount; 277 278 @SerializedName("tax_rate") 279 public Long taxRate; 280 281 @SerializedName("discount") 282 public Boolean discount; 283 284 @SerializedName("preferential_policy_code") 285 public Long preferentialPolicyCode; 286 287 @SerializedName("real_estate_leasing_information") 288 public RealEstateLeasingExtInfo realEstateLeasingInformation; 289 } 290 291 public static class TransactionInfo { 292 @SerializedName("pay_channel") 293 public PayChannel payChannel; 294 295 @SerializedName("transaction_id") 296 public String transactionId; 297 298 @SerializedName("out_trade_no") 299 public String outTradeNo; 300 301 @SerializedName("amount") 302 public Long amount; 303 } 304 305 public enum RealEstateUnit { 306 @SerializedName("METER") 307 METER, 308 @SerializedName("SQUARE_METER") 309 SQUARE_METER, 310 @SerializedName("SQUARE_KILOMETER") 311 SQUARE_KILOMETER, 312 @SerializedName("HECTARE") 313 HECTARE, 314 @SerializedName("SQUARE_KILOMETER_ABBREVIATION") 315 SQUARE_KILOMETER_ABBREVIATION, 316 @SerializedName("SQUARE_METER_ABBREVIATION") 317 SQUARE_METER_ABBREVIATION, 318 @SerializedName("HECTARE_ABBREVIATION") 319 HECTARE_ABBREVIATION, 320 @SerializedName("MU") 321 MU 322 } 323 324 public static class RealEstateLeasingExtInfo { 325 @SerializedName("province") 326 public String province; 327 328 @SerializedName("city") 329 public String city; 330 331 @SerializedName("address") 332 public String address; 333 334 @SerializedName("lease_period_start") 335 public String leasePeriodStart; 336 337 @SerializedName("lease_period_end") 338 public String leasePeriodEnd; 339 340 @SerializedName("cross_city_flag") 341 public Boolean crossCityFlag; 342 343 @SerializedName("certificate_no") 344 public String certificateNo; 345 346 @SerializedName("plate_no") 347 public List<String> plateNo; 348 } 349 350 public enum PayChannel { 351 @SerializedName("WECHAT_PAY") 352 WECHAT_PAY 353 } 354 355} 356
需配合微信支付工具库 wxpay_utility 使用,请参考 Go
1package main 2 3import ( 4 "bytes" 5 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/partner/4015119446 6 "encoding/json" 7 "fmt" 8 "net/http" 9 "net/url" 10) 11 12func main() { 13 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 14 config, err := wxpay_utility.CreateMchConfig( 15 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 16 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 17 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 18 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 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=="), /*请传入 wxpay_utility.EncryptOAEPWithPublicKey 加密结果*/ 38 Email: wxpay_utility.String("NzJy3r0Z2u2Vs5l+WSH0A3CZ1oGlCZ66aa2wUlMXNmACbd4wU8LqqYCuTG4cYWxrVUSmviV59/Uy9vLdIwuHZVrMalYAZGtb8inWGhDj3wUqQnPkmBKBVGIWG5Y6XJmMvpXW6rIKsdzxs8NwWj30cRNfjanLxiWc0aIgl8Knwo0JcxlcYLo38T9ntsrRkQZMQEWHaMYnzjp7ysLbp6yW83OZb/NwEufERBdPnIbDbVE7DUd5MGhvO+tlr2YC1b4VCsrDmjryuTD5nvYYCGHyfXW2CM23hZdBm9tPc+mU18Z9d4XkasnfsecGWd2ISkpPmnk3DtapnD64Nw8JyLtkgw=="), /*请传入 wxpay_utility.EncryptOAEPWithPublicKey 加密结果*/ 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"), /*请传入 wxpay_utility.EncryptOAEPWithPublicKey 加密结果*/ 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("张伟"), 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 // TODO: 请求失败,根据状态码执行不同的处理 87 return 88 } 89 90 // TODO: 请求成功,继续业务逻辑 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 // 2XX 成功,验证应答签名 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
应答参数
无应答包体
应答示例
202 Accepted
1'无应答包体' 2
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
业务错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | INVALID_REQUEST | 请求参数符合参数格式,但不符合业务规则 | 请使用正确的参数重新调用 |
400 | RESOURCE_ALREADY_EXISTS | 发票申请单已存在 | 请稍后调用【查询电子发票】接口获取开票结果 |
400 | INVALID_REQUEST | 交易单已申请开票,两次申请的交易金额不相同 | 修改交易单金额重试 |
400 | INVALID_REQUEST | 当前发票开具中,不可申请重开发票 | 请在调用【查询电子发票】接口获取发票状态 |
400 | INVALID_REQUEST | 当前发票冲红中,不可申请重开发票 | 请在调用【查询电子发票】接口获取发票状态 |
400 | INVALID_REQUEST | 申请开票次数,超过最大限制 | 请在调用【查询电子发票】接口获取当前发票已冲红后,换发票申请单号重试开票 |
400 | INVALID_REQUEST | 开票请求已被受理,请调用【查询电子发票】接口获取开票结果 | 开票请求已被受理,请调用【查询电子发票】接口获取开票结果 |
400 | INVALID_REQUEST | 交易单已申请开票,两次申请的交易金额不相同 | 修改交易单金额重试 |
400 | INVALID_REQUEST | 交易可剩余开票金额不足 | 修改交易订单或者开票金额重试 |
403 | NO_AUTH | 商户乐企不动产租赁发票能力未授权 | 确认商户是否发起不动产租赁发票能力邀请授权,以及电子税局确认操作。确认无误,请稍后重试 |
403 | NO_AUTH | 商户无权限 | 请检查是否已经开通电子发票产品相关功能权限,并检查子商户是否接受了服务商的邀请 |
403 | RULE_LIMIT | 商户尚未配置电子发票卡券模板信息 | 请先调用【创建电子发票卡券模板】接口成功后再重新调用 |
403 | RULE_LIMIT | 商户不可对该货物或应税劳务、服务编码开具发票 | 请检查参数中的货物或应税劳务、服务编码是否在【获取商品和服务税收分类对照表】接口返回的数据中 |
403 | RULE_LIMIT | 商户提交的购买方信息与用户填写的发票抬头不一致 | 请检查参数中的购买方信息与【获取用户填写抬头信息】接口返回的发票抬头信息是否一致 |
403 | RULE_LIMIT | 微信支付订单所属商户与当前商户不一致(仅微信支付场景) | 请检查微信支付订单号是否属于子商户 |
404 | RESOURCE_NOT_EXISTS | 用户尚未完成发票抬头填写(仅非微信支付场景) | 请在调用【获取用户填写抬头信息】接口成功后再以相同发票申请单号重新调用 |
429 | FREQUENCY_LIMITED | 频率超限 | 请降低请求接口频率 |