获取用户抬头填写链接
更新时间:2025.09.03非微信支付场景中,商户需先调用本接口获取抬头填写链接,供用户填写发票抬头。当用户提交抬头信息后,微信支付会根据商户配置的回调地址进行回调通知。
注意:获取到的抬头填写链接有30分钟的有效期,若在用户填写发票抬头之前链接过期,商户需要重新获取(此时无需更换发票申请单号)
接口说明
支持商户:【普通服务商】
请求方式:【GET】/v3/new-tax-control-fapiao/user-title/title-url
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
query 查询参数
sub_mchid 必填 string(32)
【子商户号】 微信支付分配的子商户号,具体请参考服务商模式开发必要参数说明
fapiao_apply_id 必填 string(32)
【发票申请单号】 发票申请单号,唯一标识一次开票行为。只能是字母、数字、中划线-、下划线_、竖线|、星号*这些英文半角字符,且该单号在每个商户下必须唯一。当用户完成抬头填写后,微信支付会以该单号回调商户,商户可通过【获取用户填写抬头信息】接口查询用户填写的抬头信息
source 必填 string
【开票来源】 开票来源
可选取值
WEB
: 微信H5MINIPROGRAM
: 微信小程序
appid 必填 string(32)
【商户AppID】 若开票来源是WEB,则为商户的公众号AppID;若开票来源是MINIPROGRAM,则为商户的小程序AppID。可参考服务商模式开发必要参数说明
openid 必填 string(32)
【用户OpenID】 需要填写发票抬头的用户在商户AppID下的OpenID
total_amount 必填 integer
【总金额】 展示在抬头填写页面的开票金额,对该发票申请单开票时所有发票的总价税合计之和不能超过此金额,单位:分
seller_name 选填 string(32)
【销售方名称】 展示在抬头填写页的销售方名称,若不传则默认取商户名称
show_phone_cell 选填 boolean
【是否需要展示手机号填写栏】 是否需要展示手机号填写栏
must_input_phone 选填 boolean
【用户是否必须填写手机号】 用户是否必须填写手机号,仅当需要展示手机号填写栏时生效
show_email_cell 选填 boolean
【是否需要展示邮箱地址填写栏】 是否需要展示邮箱地址填写栏
must_input_email 选填 boolean
【用户是否必须填写邮箱地址】 用户是否必须填写邮箱地址,仅当需要展示邮箱地址填写栏时生效
请求示例
GET
1curl -X GET \ 2 https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/user-title/title-url?sub_mchid=1900000109&fapiao_apply_id=fapiao_20200701_123456&source=WEB&appid=wxb1170446a4c0a5a2&openid=plN5twRbHym_j-QcqCzstl0HmwEs&total_amount=382895&seller_name=深圳市南山区测试商户&show_phone_cell=true&must_input_phone=true&show_email_cell=true&must_input_email=true \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" 5
需配合微信支付工具库 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 AcquireFapiaoTitleUrl { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "GET"; 28 private static String PATH = "/v3/new-tax-control-fapiao/user-title/title-url"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 AcquireFapiaoTitleUrl client = new AcquireFapiaoTitleUrl( 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 AcquireFapiaoTitleUrlRequest request = new AcquireFapiaoTitleUrlRequest(); 41 request.subMchid = "1900000109"; 42 request.fapiaoApplyId = "fapiao_20200701_123456"; 43 request.source = Source.WEB; 44 request.appid = "wxb1170446a4c0a5a2"; 45 request.openid = "plN5twRbHym_j-QcqCzstl0HmwEs"; 46 request.totalAmount = 382895L; 47 request.sellerName = "深圳市南山区测试商户"; 48 request.showPhoneCell = true; 49 request.mustInputPhone = true; 50 request.showEmailCell = true; 51 request.mustInputEmail = true; 52 try { 53 AcquireFapiaoTitleUrlResponse response = client.run(request); 54 // TODO: 请求成功,继续业务逻辑 55 System.out.println(response); 56 } catch (WXPayUtility.ApiException e) { 57 // TODO: 请求失败,根据状态码执行不同的逻辑 58 e.printStackTrace(); 59 } 60 } 61 62 public AcquireFapiaoTitleUrlResponse run(AcquireFapiaoTitleUrlRequest request) { 63 String uri = PATH; 64 Map<String, Object> args = new HashMap<>(); 65 args.put("sub_mchid", request.subMchid); 66 args.put("fapiao_apply_id", request.fapiaoApplyId); 67 args.put("source", request.source); 68 args.put("appid", request.appid); 69 args.put("openid", request.openid); 70 args.put("total_amount", request.totalAmount); 71 args.put("seller_name", request.sellerName); 72 args.put("show_phone_cell", request.showPhoneCell); 73 args.put("must_input_phone", request.mustInputPhone); 74 args.put("show_email_cell", request.showEmailCell); 75 args.put("must_input_email", request.mustInputEmail); 76 String queryString = WXPayUtility.urlEncode(args); 77 if (!queryString.isEmpty()) { 78 uri = uri + "?" + queryString; 79 } 80 81 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 82 reqBuilder.addHeader("Accept", "application/json"); 83 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 84 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, null)); 85 reqBuilder.method(METHOD, null); 86 Request httpRequest = reqBuilder.build(); 87 88 // 发送HTTP请求 89 OkHttpClient client = new OkHttpClient.Builder().build(); 90 try (Response httpResponse = client.newCall(httpRequest).execute()) { 91 String respBody = WXPayUtility.extractBody(httpResponse); 92 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 93 // 2XX 成功,验证应答签名 94 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 95 httpResponse.headers(), respBody); 96 97 // 从HTTP应答报文构建返回数据 98 return WXPayUtility.fromJson(respBody, AcquireFapiaoTitleUrlResponse.class); 99 } else { 100 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 101 } 102 } catch (IOException e) { 103 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 104 } 105 } 106 107 private final String mchid; 108 private final String certificateSerialNo; 109 private final PrivateKey privateKey; 110 private final String wechatPayPublicKeyId; 111 private final PublicKey wechatPayPublicKey; 112 113 public AcquireFapiaoTitleUrl(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 114 this.mchid = mchid; 115 this.certificateSerialNo = certificateSerialNo; 116 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 117 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 118 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 119 } 120 121 public static class AcquireFapiaoTitleUrlRequest { 122 @SerializedName("sub_mchid") 123 @Expose(serialize = false) 124 public String subMchid; 125 126 @SerializedName("fapiao_apply_id") 127 @Expose(serialize = false) 128 public String fapiaoApplyId; 129 130 @SerializedName("appid") 131 @Expose(serialize = false) 132 public String appid; 133 134 @SerializedName("openid") 135 @Expose(serialize = false) 136 public String openid; 137 138 @SerializedName("total_amount") 139 @Expose(serialize = false) 140 public Long totalAmount; 141 142 @SerializedName("seller_name") 143 @Expose(serialize = false) 144 public String sellerName; 145 146 @SerializedName("show_phone_cell") 147 @Expose(serialize = false) 148 public Boolean showPhoneCell; 149 150 @SerializedName("must_input_phone") 151 @Expose(serialize = false) 152 public Boolean mustInputPhone; 153 154 @SerializedName("show_email_cell") 155 @Expose(serialize = false) 156 public Boolean showEmailCell; 157 158 @SerializedName("must_input_email") 159 @Expose(serialize = false) 160 public Boolean mustInputEmail; 161 162 @SerializedName("source") 163 @Expose(serialize = false) 164 public Source source; 165 } 166 167 public static class AcquireFapiaoTitleUrlResponse { 168 @SerializedName("miniprogram_appid") 169 public String miniprogramAppid; 170 171 @SerializedName("miniprogram_path") 172 public String miniprogramPath; 173 174 @SerializedName("miniprogram_user_name") 175 public String miniprogramUserName; 176 } 177 178 public enum Source { 179 @SerializedName("WEB") 180 WEB, 181 @SerializedName("MINIPROGRAM") 182 MINIPROGRAM 183 } 184 185} 186
需配合微信支付工具库 wxpay_utility 使用,请参考 Go
1package main 2 3import ( 4 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/partner/4015119446 5 "encoding/json" 6 "fmt" 7 "net/http" 8 "net/url" 9) 10 11func main() { 12 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 13 config, err := wxpay_utility.CreateMchConfig( 14 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 15 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 16 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 17 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 18 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 19 ) 20 if err != nil { 21 fmt.Println(err) 22 return 23 } 24 25 request := &AcquireFapiaoTitleUrlRequest{ 26 SubMchid: wxpay_utility.String("1900000109"), 27 FapiaoApplyId: wxpay_utility.String("fapiao_20200701_123456"), 28 Source: SOURCE_WEB.Ptr(), 29 Appid: wxpay_utility.String("wxb1170446a4c0a5a2"), 30 Openid: wxpay_utility.String("plN5twRbHym_j-QcqCzstl0HmwEs"), 31 TotalAmount: wxpay_utility.Int64(382895), 32 SellerName: wxpay_utility.String("深圳市南山区测试商户"), 33 ShowPhoneCell: wxpay_utility.Bool(true), 34 MustInputPhone: wxpay_utility.Bool(true), 35 ShowEmailCell: wxpay_utility.Bool(true), 36 MustInputEmail: wxpay_utility.Bool(true), 37 } 38 39 response, err := AcquireFapiaoTitleUrl(config, request) 40 if err != nil { 41 fmt.Printf("请求失败: %+v\n", err) 42 // TODO: 请求失败,根据状态码执行不同的处理 43 return 44 } 45 46 // TODO: 请求成功,继续业务逻辑 47 fmt.Printf("请求成功: %+v\n", response) 48} 49 50func AcquireFapiaoTitleUrl(config *wxpay_utility.MchConfig, request *AcquireFapiaoTitleUrlRequest) (response *AcquireFapiaoTitleUrlResponse, err error) { 51 const ( 52 host = "https://api.mch.weixin.qq.com" 53 method = "GET" 54 path = "/v3/new-tax-control-fapiao/user-title/title-url" 55 ) 56 57 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 58 if err != nil { 59 return nil, err 60 } 61 query := reqUrl.Query() 62 if request.SubMchid != nil { 63 query.Add("sub_mchid", *request.SubMchid) 64 } 65 if request.FapiaoApplyId != nil { 66 query.Add("fapiao_apply_id", *request.FapiaoApplyId) 67 } 68 if request.Source != nil { 69 query.Add("source", fmt.Sprintf("%v", *request.Source)) 70 } 71 if request.Appid != nil { 72 query.Add("appid", *request.Appid) 73 } 74 if request.Openid != nil { 75 query.Add("openid", *request.Openid) 76 } 77 if request.TotalAmount != nil { 78 query.Add("total_amount", fmt.Sprintf("%v", *request.TotalAmount)) 79 } 80 if request.SellerName != nil { 81 query.Add("seller_name", *request.SellerName) 82 } 83 if request.ShowPhoneCell != nil { 84 query.Add("show_phone_cell", fmt.Sprintf("%v", *request.ShowPhoneCell)) 85 } 86 if request.MustInputPhone != nil { 87 query.Add("must_input_phone", fmt.Sprintf("%v", *request.MustInputPhone)) 88 } 89 if request.ShowEmailCell != nil { 90 query.Add("show_email_cell", fmt.Sprintf("%v", *request.ShowEmailCell)) 91 } 92 if request.MustInputEmail != nil { 93 query.Add("must_input_email", fmt.Sprintf("%v", *request.MustInputEmail)) 94 } 95 reqUrl.RawQuery = query.Encode() 96 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil) 97 if err != nil { 98 return nil, err 99 } 100 httpRequest.Header.Set("Accept", "application/json") 101 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 102 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 103 if err != nil { 104 return nil, err 105 } 106 httpRequest.Header.Set("Authorization", authorization) 107 108 client := &http.Client{} 109 httpResponse, err := client.Do(httpRequest) 110 if err != nil { 111 return nil, err 112 } 113 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 114 if err != nil { 115 return nil, err 116 } 117 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 118 // 2XX 成功,验证应答签名 119 err = wxpay_utility.ValidateResponse( 120 config.WechatPayPublicKeyId(), 121 config.WechatPayPublicKey(), 122 &httpResponse.Header, 123 respBody, 124 ) 125 if err != nil { 126 return nil, err 127 } 128 response := &AcquireFapiaoTitleUrlResponse{} 129 if err := json.Unmarshal(respBody, response); err != nil { 130 return nil, err 131 } 132 133 return response, nil 134 } else { 135 return nil, wxpay_utility.NewApiException( 136 httpResponse.StatusCode, 137 httpResponse.Header, 138 respBody, 139 ) 140 } 141} 142 143type AcquireFapiaoTitleUrlRequest struct { 144 SubMchid *string `json:"sub_mchid,omitempty"` 145 FapiaoApplyId *string `json:"fapiao_apply_id,omitempty"` 146 Appid *string `json:"appid,omitempty"` 147 Openid *string `json:"openid,omitempty"` 148 TotalAmount *int64 `json:"total_amount,omitempty"` 149 SellerName *string `json:"seller_name,omitempty"` 150 ShowPhoneCell *bool `json:"show_phone_cell,omitempty"` 151 MustInputPhone *bool `json:"must_input_phone,omitempty"` 152 ShowEmailCell *bool `json:"show_email_cell,omitempty"` 153 MustInputEmail *bool `json:"must_input_email,omitempty"` 154 Source *Source `json:"source,omitempty"` 155} 156 157func (o *AcquireFapiaoTitleUrlRequest) MarshalJSON() ([]byte, error) { 158 type Alias AcquireFapiaoTitleUrlRequest 159 a := &struct { 160 SubMchid *string `json:"sub_mchid,omitempty"` 161 FapiaoApplyId *string `json:"fapiao_apply_id,omitempty"` 162 Appid *string `json:"appid,omitempty"` 163 Openid *string `json:"openid,omitempty"` 164 TotalAmount *int64 `json:"total_amount,omitempty"` 165 SellerName *string `json:"seller_name,omitempty"` 166 ShowPhoneCell *bool `json:"show_phone_cell,omitempty"` 167 MustInputPhone *bool `json:"must_input_phone,omitempty"` 168 ShowEmailCell *bool `json:"show_email_cell,omitempty"` 169 MustInputEmail *bool `json:"must_input_email,omitempty"` 170 Source *Source `json:"source,omitempty"` 171 *Alias 172 }{ 173 // 序列化时移除非 Body 字段 174 SubMchid: nil, 175 FapiaoApplyId: nil, 176 Appid: nil, 177 Openid: nil, 178 TotalAmount: nil, 179 SellerName: nil, 180 ShowPhoneCell: nil, 181 MustInputPhone: nil, 182 ShowEmailCell: nil, 183 MustInputEmail: nil, 184 Source: nil, 185 Alias: (*Alias)(o), 186 } 187 return json.Marshal(a) 188} 189 190type AcquireFapiaoTitleUrlResponse struct { 191 MiniprogramAppid *string `json:"miniprogram_appid,omitempty"` 192 MiniprogramPath *string `json:"miniprogram_path,omitempty"` 193 MiniprogramUserName *string `json:"miniprogram_user_name,omitempty"` 194} 195 196type Source string 197 198func (e Source) Ptr() *Source { 199 return &e 200} 201 202const ( 203 SOURCE_WEB Source = "WEB" 204 SOURCE_MINIPROGRAM Source = "MINIPROGRAM" 205) 206
应答参数
200 OK
miniprogram_appid 选填 string(32)
【抬头填写小程序AppID】 商户授权的小程序 AppID,当开票来源为WEB或MINIPROGRAM时存在。与miniprogram_path 共同作为小程序跳转插件的参数,用于任意小程序跳转至指定开通小程序,开通服务商电子发票能力。参考:wx.navigateToMiniProgram
miniprogram_path 选填 string(1024)
【抬头填写小程序页面路径】 商户开通服务商电子发票小程序的页面路径,当开票来源为WEB或MINIPROGRAM时存在。与 miniprogram_appid 共同作为小程序跳转插件的参数,用于任意小程序跳转至指定开通小程序,开通服务商电子发票能力。参考:wx.navigateToMiniProgram
miniprogram_user_name 选填 string(32)
【抬头填写小程序的用户名】 抬头填写小程序的用户名,即小程序的原始ID(gh_开头),当开票来源为WEB时存在。与miniprogram_appid, miniprogram_path共同作为WEB端小程序跳转插件的参数,参考:
静态网站H5跳小程序
应答示例
200 OK
1{ 2 "miniprogram_appid" : "wxb1170446a4c0a5a2", 3 "miniprogram_path" : "pages/xxxPage", 4 "miniprogram_user_name" : "gh_86a091e50ad4@app" 5} 6
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
业务错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | INVALID_REQUEST | 请求参数符合参数格式,但不符合业务规则 | 请使用正确的参数重新调用 |
403 | NO_AUTH | 商户无权限 | 请检查是否已经开通电子发票产品相关功能权限,并检查子商户是否接受了服务商的邀请 |
403 | RULE_LIMIT | 商户获取抬头链接指定的用户与已提交抬头的用户不一致 | 请确认发票申请单号对应的用户是否正确 |
429 | FREQUENCY_LIMITED | 频率超限 | 请降低请求接口频率 |