开具成品油行业电子发票
更新时间:2025.12.03商户完成收款后,调用本接口开具成品油行业电子发票并插入微信用户的卡包。请求的交易信息必须真实存在。 注意:本接口成功返回仅代表开票请求已被受理,当开票完成时,微信支付会根据商户配置的回调地址进行回调通知,商户也可以通过【查询电子发票】接口获取开票结果及开票信息。蓝字发票开具失败时,可以通过更换fapiao_information.fapiao_id,重新填写发票信息进行重试。每个申请单可至多重试4次。
接口说明
支持商户:【普通服务商】
请求方式:【POST】/v3/new-tax-control-fapiao/fapiao-applications/issue-refined-oil
请求域名:【主域名】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] 【交易信息】 发票对应的交易信息,最大支持传入10条交易信息
remark 选填 string 【发票备注】 发票备注 |
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/fapiao-applications/issue-refined-oil \ 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" : "1070101020100000000", 31 "goods_name" : "*燃料油*燃料油", 32 "specification" : "92#", 33 "unit" : "TON", 34 "quantity" : 100000000, 35 "total_amount" : 429900, 36 "tax_rate" : 1300, 37 "discount" : false, 38 "preferential_policy_code" : 1, 39 "refined_oil_information" : { 40 "station" : "中国石油(江北红旗河沟加油站)", 41 "trade_time" : "2025-07-01T00:00:00+08:00", 42 "gun_number" : "1号枪" 43 } 44 } 45 ], 46 "export_business_policy_code" : 1, 47 "vat_refund_levy_code" : 1, 48 "billing_person_id" : "187776276864872", 49 "billing_person" : "**伟 0020", 50 "fapiao_bill_type" : "COMM_FAPIAO", 51 "transaction_information" : [ 52 { 53 "pay_channel" : "WECHAT_PAY", 54 "transaction_id" : "4200000008202508080512076713", 55 "out_trade_no" : "order_20200701_123456", 56 "amount" : 382895 57 } 58 ], 59 "remark" : "备注" 60 } 61 }' 62
需配合微信支付工具库 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 IssueRefinedOilFapiaoApplications { 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/issue-refined-oil"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 IssueRefinedOilFapiaoApplications client = new IssueRefinedOilFapiaoApplications( 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 IssueRefinedOilFapiaoRequest request = new IssueRefinedOilFapiaoRequest(); 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 IssueRefinedOilFapiaoInfo(); 58 request.fapiaoInformation.fapiaoId = "20200701123456"; 59 request.fapiaoInformation.totalAmount = 382895L; 60 request.fapiaoInformation.items = new ArrayList<>(); 61 { 62 IssueRefinedOilFapiaoItem itemsItem = new IssueRefinedOilFapiaoItem(); 63 itemsItem.taxCode = "1070101020100000000"; 64 itemsItem.goodsName = "*燃料油*燃料油"; 65 itemsItem.specification = "92#"; 66 itemsItem.unit = RefinedOilUnit.TON; 67 itemsItem.quantity = 100000000L; 68 itemsItem.totalAmount = 429900L; 69 itemsItem.taxRate = 1300L; 70 itemsItem.discount = false; 71 itemsItem.preferentialPolicyCode = 1L; 72 itemsItem.refinedOilInformation = new RefinedOilExtInfo(); 73 itemsItem.refinedOilInformation.station = "中国石油(江北红旗河沟加油站)"; 74 itemsItem.refinedOilInformation.tradeTime = "2025-07-01T00:00:00+08:00"; 75 itemsItem.refinedOilInformation.gunNumber = "1号枪"; 76 request.fapiaoInformation.items.add(itemsItem); 77 }; 78 request.fapiaoInformation.exportBusinessPolicyCode = 1L; 79 request.fapiaoInformation.vatRefundLevyCode = 1L; 80 request.fapiaoInformation.billingPersonId = "187776276864872"; 81 request.fapiaoInformation.billingPerson = "**伟 0020"; 82 request.fapiaoInformation.fapiaoBillType = FapiaoBillType.COMM_FAPIAO; 83 request.fapiaoInformation.transactionInformation = new ArrayList<>(); 84 { 85 TransactionInfo transactionInformationItem = new TransactionInfo(); 86 transactionInformationItem.payChannel = PayChannel.WECHAT_PAY; 87 transactionInformationItem.transactionId = "4200000008202508080512076713"; 88 transactionInformationItem.outTradeNo = "order_20200701_123456"; 89 transactionInformationItem.amount = 382895L; 90 request.fapiaoInformation.transactionInformation.add(transactionInformationItem); 91 }; 92 request.fapiaoInformation.remark = "备注"; 93 try { 94 client.run(request); 95 } catch (WXPayUtility.ApiException e) { 96 // TODO: 请求失败,根据状态码执行不同的逻辑 97 e.printStackTrace(); 98 } 99 } 100 101 public void run(IssueRefinedOilFapiaoRequest request) { 102 String uri = PATH; 103 String reqBody = WXPayUtility.toJson(request); 104 105 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 106 reqBuilder.addHeader("Accept", "application/json"); 107 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 108 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 109 reqBuilder.addHeader("Content-Type", "application/json"); 110 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 111 reqBuilder.method(METHOD, requestBody); 112 Request httpRequest = reqBuilder.build(); 113 114 // 发送HTTP请求 115 OkHttpClient client = new OkHttpClient.Builder().build(); 116 try (Response httpResponse = client.newCall(httpRequest).execute()) { 117 String respBody = WXPayUtility.extractBody(httpResponse); 118 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 119 // 2XX 成功,验证应答签名 120 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 121 httpResponse.headers(), respBody); 122 123 return; 124 } else { 125 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 126 } 127 } catch (IOException e) { 128 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 129 } 130 } 131 132 private final String mchid; 133 private final String certificateSerialNo; 134 private final PrivateKey privateKey; 135 private final String wechatPayPublicKeyId; 136 private final PublicKey wechatPayPublicKey; 137 138 public IssueRefinedOilFapiaoApplications(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 139 this.mchid = mchid; 140 this.certificateSerialNo = certificateSerialNo; 141 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 142 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 143 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 144 } 145 146 public String encrypt(String plainText) { 147 return WXPayUtility.encrypt(this.wechatPayPublicKey, plainText); 148 } 149 150 public static class IssueRefinedOilFapiaoRequest { 151 @SerializedName("sub_mchid") 152 public String subMchid; 153 154 @SerializedName("fapiao_apply_id") 155 public String fapiaoApplyId; 156 157 @SerializedName("buyer_information") 158 public UserTitleEntity buyerInformation; 159 160 @SerializedName("fapiao_information") 161 public IssueRefinedOilFapiaoInfo fapiaoInformation; 162 } 163 164 public static class UserTitleEntity { 165 @SerializedName("type") 166 public BuyerType type; 167 168 @SerializedName("name") 169 public String name; 170 171 @SerializedName("taxpayer_id") 172 public String taxpayerId; 173 174 @SerializedName("address") 175 public String address; 176 177 @SerializedName("telephone") 178 public String telephone; 179 180 @SerializedName("bank_name") 181 public String bankName; 182 183 @SerializedName("bank_account") 184 public String bankAccount; 185 186 @SerializedName("phone") 187 public String phone; 188 189 @SerializedName("email") 190 public String email; 191 192 @SerializedName("amount") 193 public Long amount; 194 195 @SerializedName("out_trade_no") 196 public String outTradeNo; 197 198 @SerializedName("fapiao_bill_type") 199 public FapiaoBillType fapiaoBillType; 200 201 @SerializedName("user_apply_message") 202 public String userApplyMessage; 203 } 204 205 public static class IssueRefinedOilFapiaoInfo { 206 @SerializedName("fapiao_id") 207 public String fapiaoId; 208 209 @SerializedName("total_amount") 210 public Long totalAmount; 211 212 @SerializedName("items") 213 public List<IssueRefinedOilFapiaoItem> items = new ArrayList<IssueRefinedOilFapiaoItem>(); 214 215 @SerializedName("export_business_policy_code") 216 public Long exportBusinessPolicyCode; 217 218 @SerializedName("vat_refund_levy_code") 219 public Long vatRefundLevyCode; 220 221 @SerializedName("billing_person_id") 222 public String billingPersonId; 223 224 @SerializedName("billing_person") 225 public String billingPerson; 226 227 @SerializedName("fapiao_bill_type") 228 public FapiaoBillType fapiaoBillType; 229 230 @SerializedName("transaction_information") 231 public List<TransactionInfo> transactionInformation = new ArrayList<TransactionInfo>(); 232 233 @SerializedName("remark") 234 public String remark; 235 } 236 237 public enum BuyerType { 238 @SerializedName("INDIVIDUAL") 239 INDIVIDUAL, 240 @SerializedName("ORGANIZATION") 241 ORGANIZATION 242 } 243 244 public enum FapiaoBillType { 245 @SerializedName("COMM_FAPIAO") 246 COMM_FAPIAO, 247 @SerializedName("VAT_FAPIAO") 248 VAT_FAPIAO 249 } 250 251 public static class IssueRefinedOilFapiaoItem { 252 @SerializedName("tax_code") 253 public String taxCode; 254 255 @SerializedName("goods_name") 256 public String goodsName; 257 258 @SerializedName("specification") 259 public String specification; 260 261 @SerializedName("unit") 262 public RefinedOilUnit unit; 263 264 @SerializedName("quantity") 265 public Long quantity; 266 267 @SerializedName("total_amount") 268 public Long totalAmount; 269 270 @SerializedName("tax_rate") 271 public Long taxRate; 272 273 @SerializedName("discount") 274 public Boolean discount; 275 276 @SerializedName("preferential_policy_code") 277 public Long preferentialPolicyCode; 278 279 @SerializedName("refined_oil_information") 280 public RefinedOilExtInfo refinedOilInformation; 281 } 282 283 public static class TransactionInfo { 284 @SerializedName("pay_channel") 285 public PayChannel payChannel; 286 287 @SerializedName("transaction_id") 288 public String transactionId; 289 290 @SerializedName("out_trade_no") 291 public String outTradeNo; 292 293 @SerializedName("amount") 294 public Long amount; 295 } 296 297 public enum RefinedOilUnit { 298 @SerializedName("TON") 299 TON, 300 @SerializedName("LITER") 301 LITER 302 } 303 304 public static class RefinedOilExtInfo { 305 @SerializedName("station") 306 public String station; 307 308 @SerializedName("trade_time") 309 public String tradeTime; 310 311 @SerializedName("gun_number") 312 public String gunNumber; 313 } 314 315 public enum PayChannel { 316 @SerializedName("WECHAT_PAY") 317 WECHAT_PAY 318 } 319 320} 321
需配合微信支付工具库 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 := &IssueRefinedOilFapiaoRequest{ 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: &IssueRefinedOilFapiaoInfo{ 45 FapiaoId: wxpay_utility.String("20200701123456"), 46 TotalAmount: wxpay_utility.Int64(382895), 47 Items: []IssueRefinedOilFapiaoItem{IssueRefinedOilFapiaoItem{ 48 TaxCode: wxpay_utility.String("1070101020100000000"), 49 GoodsName: wxpay_utility.String("*燃料油*燃料油"), 50 Specification: wxpay_utility.String("92#"), 51 Unit: REFINEDOILUNIT_TON.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 RefinedOilInformation: &RefinedOilExtInfo{ 58 Station: wxpay_utility.String("中国石油(江北红旗河沟加油站)"), 59 TradeTime: wxpay_utility.String("2025-07-01T00:00:00+08:00"), 60 GunNumber: wxpay_utility.String("1号枪"), 61 }, 62 }}, 63 ExportBusinessPolicyCode: wxpay_utility.Int64(1), 64 VatRefundLevyCode: wxpay_utility.Int64(1), 65 BillingPersonId: wxpay_utility.String("187776276864872"), 66 BillingPerson: wxpay_utility.String("**伟 0020"), 67 FapiaoBillType: FAPIAOBILLTYPE_COMM_FAPIAO.Ptr(), 68 TransactionInformation: []TransactionInfo{TransactionInfo{ 69 PayChannel: PAYCHANNEL_WECHAT_PAY.Ptr(), 70 TransactionId: wxpay_utility.String("4200000008202508080512076713"), 71 OutTradeNo: wxpay_utility.String("order_20200701_123456"), 72 Amount: wxpay_utility.Int64(382895), 73 }}, 74 Remark: wxpay_utility.String("备注"), 75 }, 76 } 77 78 err = IssueRefinedOilFapiaoApplications(config, request) 79 if err != nil { 80 fmt.Printf("请求失败: %+v\n", err) 81 // TODO: 请求失败,根据状态码执行不同的处理 82 return 83 } 84 85 // TODO: 请求成功,继续业务逻辑 86 fmt.Println("请求成功") 87} 88 89func IssueRefinedOilFapiaoApplications(config *wxpay_utility.MchConfig, request *IssueRefinedOilFapiaoRequest) (err error) { 90 const ( 91 host = "https://api.mch.weixin.qq.com" 92 method = "POST" 93 path = "/v3/new-tax-control-fapiao/fapiao-applications/issue-refined-oil" 94 ) 95 96 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 97 if err != nil { 98 return err 99 } 100 reqBody, err := json.Marshal(request) 101 if err != nil { 102 return err 103 } 104 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 105 if err != nil { 106 return err 107 } 108 httpRequest.Header.Set("Accept", "application/json") 109 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 110 httpRequest.Header.Set("Content-Type", "application/json") 111 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 112 if err != nil { 113 return err 114 } 115 httpRequest.Header.Set("Authorization", authorization) 116 117 client := &http.Client{} 118 httpResponse, err := client.Do(httpRequest) 119 if err != nil { 120 return err 121 } 122 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 123 if err != nil { 124 return err 125 } 126 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 127 // 2XX 成功,验证应答签名 128 err = wxpay_utility.ValidateResponse( 129 config.WechatPayPublicKeyId(), 130 config.WechatPayPublicKey(), 131 &httpResponse.Header, 132 respBody, 133 ) 134 if err != nil { 135 return err 136 } 137 return nil 138 } else { 139 return wxpay_utility.NewApiException( 140 httpResponse.StatusCode, 141 httpResponse.Header, 142 respBody, 143 ) 144 } 145} 146 147type IssueRefinedOilFapiaoRequest struct { 148 SubMchid *string `json:"sub_mchid,omitempty"` 149 FapiaoApplyId *string `json:"fapiao_apply_id,omitempty"` 150 BuyerInformation *UserTitleEntity `json:"buyer_information,omitempty"` 151 FapiaoInformation *IssueRefinedOilFapiaoInfo `json:"fapiao_information,omitempty"` 152} 153 154type UserTitleEntity struct { 155 Type *BuyerType `json:"type,omitempty"` 156 Name *string `json:"name,omitempty"` 157 TaxpayerId *string `json:"taxpayer_id,omitempty"` 158 Address *string `json:"address,omitempty"` 159 Telephone *string `json:"telephone,omitempty"` 160 BankName *string `json:"bank_name,omitempty"` 161 BankAccount *string `json:"bank_account,omitempty"` 162 Phone *string `json:"phone,omitempty"` 163 Email *string `json:"email,omitempty"` 164 Amount *int64 `json:"amount,omitempty"` 165 OutTradeNo *string `json:"out_trade_no,omitempty"` 166 FapiaoBillType *FapiaoBillType `json:"fapiao_bill_type,omitempty"` 167 UserApplyMessage *string `json:"user_apply_message,omitempty"` 168} 169 170type IssueRefinedOilFapiaoInfo struct { 171 FapiaoId *string `json:"fapiao_id,omitempty"` 172 TotalAmount *int64 `json:"total_amount,omitempty"` 173 Items []IssueRefinedOilFapiaoItem `json:"items,omitempty"` 174 ExportBusinessPolicyCode *int64 `json:"export_business_policy_code,omitempty"` 175 VatRefundLevyCode *int64 `json:"vat_refund_levy_code,omitempty"` 176 BillingPersonId *string `json:"billing_person_id,omitempty"` 177 BillingPerson *string `json:"billing_person,omitempty"` 178 FapiaoBillType *FapiaoBillType `json:"fapiao_bill_type,omitempty"` 179 TransactionInformation []TransactionInfo `json:"transaction_information,omitempty"` 180 Remark *string `json:"remark,omitempty"` 181} 182 183type BuyerType string 184 185func (e BuyerType) Ptr() *BuyerType { 186 return &e 187} 188 189const ( 190 BUYERTYPE_INDIVIDUAL BuyerType = "INDIVIDUAL" 191 BUYERTYPE_ORGANIZATION BuyerType = "ORGANIZATION" 192) 193 194type FapiaoBillType string 195 196func (e FapiaoBillType) Ptr() *FapiaoBillType { 197 return &e 198} 199 200const ( 201 FAPIAOBILLTYPE_COMM_FAPIAO FapiaoBillType = "COMM_FAPIAO" 202 FAPIAOBILLTYPE_VAT_FAPIAO FapiaoBillType = "VAT_FAPIAO" 203) 204 205type IssueRefinedOilFapiaoItem struct { 206 TaxCode *string `json:"tax_code,omitempty"` 207 GoodsName *string `json:"goods_name,omitempty"` 208 Specification *string `json:"specification,omitempty"` 209 Unit *RefinedOilUnit `json:"unit,omitempty"` 210 Quantity *int64 `json:"quantity,omitempty"` 211 TotalAmount *int64 `json:"total_amount,omitempty"` 212 TaxRate *int64 `json:"tax_rate,omitempty"` 213 Discount *bool `json:"discount,omitempty"` 214 PreferentialPolicyCode *int64 `json:"preferential_policy_code,omitempty"` 215 RefinedOilInformation *RefinedOilExtInfo `json:"refined_oil_information,omitempty"` 216} 217 218type TransactionInfo struct { 219 PayChannel *PayChannel `json:"pay_channel,omitempty"` 220 TransactionId *string `json:"transaction_id,omitempty"` 221 OutTradeNo *string `json:"out_trade_no,omitempty"` 222 Amount *int64 `json:"amount,omitempty"` 223} 224 225type RefinedOilUnit string 226 227func (e RefinedOilUnit) Ptr() *RefinedOilUnit { 228 return &e 229} 230 231const ( 232 REFINEDOILUNIT_TON RefinedOilUnit = "TON" 233 REFINEDOILUNIT_LITER RefinedOilUnit = "LITER" 234) 235 236type RefinedOilExtInfo struct { 237 Station *string `json:"station,omitempty"` 238 TradeTime *string `json:"trade_time,omitempty"` 239 GunNumber *string `json:"gun_number,omitempty"` 240} 241 242type PayChannel string 243 244func (e PayChannel) Ptr() *PayChannel { 245 return &e 246} 247 248const ( 249 PAYCHANNEL_WECHAT_PAY PayChannel = "WECHAT_PAY" 250) 251
应答参数
无应答包体
应答示例
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 | 频率超限 | 请降低请求接口频率 |

