支付宝闪电开票快速接入

第一步:创建应用并获取APPID

要在您的应用中使用支付宝开放产品的接口能力,您需要先去蚂蚁金服开放平台(open.alipay.com),在开发者中心中创建登记您的应用,并提交审核,审核通过后会为您生成应用唯一标识(APPID),并且可以申请开通开放产品使用权限,通过APPID您的应用才能调用开放产品的接口能力。需要详细了解开放平台创建应用步骤请参考《开放平台应用创建指南》

第二步:配置密钥

开发者调用接口前需要先生成RSA密钥,RSA密钥包含应用私钥(APP_PRIVATE_KEY)、应用公钥(APP_PUBLIC_KEY)。生成密钥后在开放平台开发者中心进行密钥配置,配置完成后可以获取支付宝公钥(ALIPAY_PUBLIC_KEY)。详细步骤请参考《配置应用环境》

第三步:搭建和配置开发环境

1.下载服务端SDK

为了帮助开发者调用开放接口,我们提供了开放平台服务端SDK,包含JAVA、PHP和.NET三个语言版本,封装了签名&验签、HTTP接口请求等基础功能。请先下载对应语言版本的SDK并引入您的开发工程。
各语言版本服务端SDK详细使用说明,请参考《服务端SDK使用说明

2.接口调用配置

在SDK调用前需要进行初始化,代码如下:

AlipayClient alipayClient = new DefaultAlipayClient(URL, APP_ID, APP_PRIVATE_KEY, FORMAT, CHARSET, ALIPAY_PUBLIC_KEY, SIGN_TYPE);
配置参数 示例值解释 获取方式/示例值
URL 支付宝网关(固定) https://openapi.alipay.com/gateway.do
APPID APPID 即创建应用后生成 获取见上面创建应用并获取APPID
APP_PRIVATE_KEY 开发者私钥,由开发者自己生成 获取详见上面配置密钥
FORMAT 参数返回格式,只支持json json(固定)
CHARSET 编码集,支持GBK/UTF-8 开发者根据实际工程编码配置
ALIPAY_PUBLIC_KEY 支付宝公钥,由支付宝生成 获取详见上面配置密钥
SIGN_TYPE 商户生成签名字符串所使用的签名算法类型,目前支持RSA2和RSA,推荐使用RSA2 RSA2

第四步:发邮件申请接通支付宝闪电开票

邮箱:antinvoice
邮件格式:
主体:【公司名称】申请开通支付宝闪电开票
申请公司名称:
申请人:
申请人手机号:
公司支付宝账号:
创建的APPID:
公司简介:
说明:我们将在2个工作日内进行审核并通知您审核结果。

第五步:发送服务商准入资格

审核通过后,我们将邮件回复您,并将【服务商简称】发送给您;
【服务商简称】的作用:以下接口调用时需要使用到服务商简称,在收到服务商简称后,请妥善保管。

第六步:接口调用

6.1商家批量入驻接口调用

场景说明:
只有在支付宝端入驻成为服务方(即“第四步”)之后才能调用该接口。


商家批量入驻申请:alipay.ebpp.invoice.merchantlist.enter.apply
SDK调用示例(以JAVA为例,更多语言示例参见接口文档)

AlipayClient alipayClient = new DefaultAlipayClient("
https://openapi.alipay.com/gateway.do
","app_id","your private_key","json","GBK","alipay_public_key","RSA2");
AlipayEbppInvoiceMerchantlistEnterApplyRequest request = new AlipayEbppInvoiceMerchantlistEnterApplyRequest();
request.setBizContent("{" +
"\"merchant_base\":{" +
"\"m_short_name\":\"MYJF\"," +
"\"m_name\":\"蚂蚁金融服务集团\"," +
"\"logo_info\":\"/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAA...\"" +
"    }," +
"      \"sub_merchant_list\":[{" +
"        \"sub_m_short_name\":\"MYJF_HZ\"," +
"\"sub_m_name\":\"杭州蚂蚁金服信息技术有限公司\"," +
"\"register_no\":\"91500000747150346A\"" +
"        }]," +
"\"sub_merchant_common_info\":{" +
"\"product_code\":\"QRCODE_MERCHANT_OPEN\"," +
"\"s_short_name\":\"SAD\"" +
"    }" +
"  }");
AlipayEbppInvoiceMerchantlistEnterApplyResponse response = alipayClient.execute(request);
if(response.isSuccess()){
System.out.println("调用成功");
} else {
System.out.println("调用失败");
}

JSON响应示例

{
"alipay_ebpp_invoice_merchantlist_enter_apply_response":{
    "code":"10000",
    "msg":"Success"
  }
,"sign":"ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
}

6.2获取抬头列表接口调用

场景说明:
开票系统为消费者开具发票时,可以调用消费者抬头列表接口获取消费者在支付宝预设的抬头列表,消费者选择抬头后提交开票申请。

TIPS:在唤起消费者授权页面的过程中,需在拼接跳转的url中指定发票管家固定的scope参数值,此参数可保证较长时间的有效性(为期一年),即消费者仅需授权一次后即可维持一年的授权有效期,参数值为scope=auth_invoice_info,详情请参见 消费者信息授权。
 
消费者发票抬头列表查询:alipay.ebpp.invoice.title.list.get
SDK调用示例(以JAVA为例,更多语言示例参见接口文档)

AlipayClient alipayClient = new DefaultAlipayClient("
https://openapi.alipay.com/gateway.do
","app_id","your private_key","json","GBK","alipay_public_key","RSA2");
AlipayEbppInvoiceTitleListGetRequest request = new AlipayEbppInvoiceTitleListGetRequest();
request.setBizContent("{" +
"\"user_id\":\"2088000000000000\"" +
"  }");
AlipayEbppInvoiceTitleListGetResponse response = alipayClient.execute(request,accessToken);
if(response.isSuccess()){
System.out.println("调用成功");
} else {
System.out.println("调用失败");
}


JSON响应示例

{

"alipay_ebpp_invoice_title_list_get_response":{
    "code":"10000",
    "msg":"Success",
      "title_list":[{
        "user_id":"2088000000000000",
"title_name":"支付宝(中国)网络技术有限公司",
"title_type":"CORPORATION",
"is_default":true,
"user_mobile":"13900000000",
"logon_id":"138****09",
"user_email":"abc@aliyun.com",
"tax_register_no":"123",
"user_address":"杭州市 西湖区 天目山路 黄龙时代广场",
"open_bank_name":"中国建设银行",
"open_bank_account":"6332000010001000"
        }]
  }
,"sign":"ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
}

关键入参:

参数名称 参数说明
user_id 支付宝消费者id ,必须和发起授权消费者的user_id一致

关键出参:

参数名称 参数说明
title_list 抬头列表,包括title_name(抬头名称),is_default(是否是消费者默认抬头)等信息,具体包含字段见此行下方
user_id 抬头所属的支付宝消费者id
title_name 抬头名称
title_type 抬头类型
值包含两种情况:
PERSONAL(个人抬头)
CORPORATION(单位抬头)
is_default 是否是消费者设置的默认抬头
值包含两种情况
false(非默认)
true(默认抬头)
user_mobile 单位电话
tax_register_no 纳税人识别号
user_address 单位地址
open_bank_name 单位开户银行
open_bank_account 单位开户银行账号


Tips:关键出参和消费者填写抬头表单映射关系图如下所示
个人抬头表单与接口输出参数映射关系

单位抬头表单与接口输出参数映射关系

6.3发票信息发送接口调用

场景说明:
该接口调用的前提是该商家已经在支付宝端调用【商家批量入驻接口-alipay.ebpp.invoice.merchantlist.enter.apply】完成了入驻。商家系统为消费者开具的发票可以通过该接口发送至支付宝端,之后消费者便可以在支付宝端查看该发票信息或者下载发票pdf文件。

发票信息发送:alipay.ebpp.invoice.info.send
SDK调用示例(以JAVA为例,更多语言示例参见接口文档)

AlipayClient alipayClient = new DefaultAlipayClient("
https://openapi.alipay.com/gateway.do
","app_id","your private_key","json","GBK","alipay_public_key","RSA2");
AlipayEbppInvoiceInfoSendRequest request = new AlipayEbppInvoiceInfoSendRequest();
request.setBizContent("{" +
"\"m_short_name\":\"XSD\"," +
"\"sub_m_short_name\":\"XSD_HL\"," +
"      \"invoice_info_list\":[{" +
"        \"user_id\":\"2088399922382233\"," +
"\"invoice_code\":\"4112740003\"," +
"\"invoice_no\":\"41791003\"," +
"\"invoice_date\":\"2017-10-10\"," +
"\"sum_amount\":\"101.00\"," +
"\"ex_tax_amount\":\"100.00\"," +
"\"tax_amount\":\"1.00\"," +
"          \"invoice_content\":[{" +
"            \"item_name\":\"餐饮费\"," +
"\"item_no\":\"1010101990000000000\"," +
"\"item_spec\":\"G39\"," +
"\"item_unit\":\"台\"," +
"\"item_quantity\":1," +
"\"item_unit_price\":\"100.00\"," +
"\"item_ex_tax_amount\":\"100.00\"," +
"\"item_tax_rate\":\"0.01\"," +
"\"item_tax_amount\":\"1.00\"," +
"\"item_sum_amount\":\"101.00\"," +
"\"row_type\":\"0\"" +
"            }]," +
"\"out_trade_no\":\"20171023293456785924325\"," +
"\"invoice_type\":\"BLUE\"," +
"\"invoice_kind\":\"PLAIN\"," +
"\"invoice_title\":{" +
"\"title_name\":\"支付宝(中国)网络技术有限公司\"," +
"\"payer_register_no\":\"9133010060913454XP\"," +
"\"payer_address_tel\":\"杭州市西湖区天目山路黄龙时代广场0571-11111111\"," +
"\"payer_bank_name_account\":\"中国建设银行11111111\"" +
"        }," +
"\"payee_register_no\":\"310101000000090\"," +
"\"payee_register_name\":\"支付宝(杭州)信息技术有限公司\"," +
"\"payee_address_tel\":\"杭州市西湖区某某办公楼 0571-237405862\"," +
"\"payee_bank_name_account\":\"西湖区建行11111111111\"," +
"\"check_code\":\"15170246985745164986\"," +
"\"out_invoice_id\":\"201710283459661232435535\"," +
"\"ori_blue_inv_code\":\"4112740002\"," +
"\"ori_blue_inv_no\":\"41791002\"," +
"\"file_download_type\":\"PDF\"," +
"\"file_download_url\":\"
http://img.hadalo.com/aa/kq/ddhrtdefgxKVXXXXa6apXXXXXXXXXX.pdf
\"," +
"\"payee\":\"张三\"," +
"\"checker\":\"李四\"," +
"\"clerk\":\"赵吴\"," +
"\"invoice_memo\":\"订单号:2017120800001\"," +
"\"extend_fields\":\"m_invoice_detail_url=
http://196.021.871.011:8080/invoice/detail.action?fpdm=
 4112740003&fphm=41791003\"" +
"        }]" +
"  }");
AlipayEbppInvoiceInfoSendResponse response = alipayClient.execute(request);
if(response.isSuccess()){
System.out.println("调用成功");
} else {
System.out.println("调用失败");
}

JSON响应示例

{
"alipay_ebpp_invoice_info_send_response":{
    "code":"10000",
    "msg":"Success",
"url":"
alipays://platformapi/startapp?appId=20000920&url=%2Fwww%2Flist.htm%3Ffrom%3Doffline
"
  }
,"sign":"ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
}

关于沙箱

如何接入沙箱

沙箱环境是开放平台提供给开发者调试接口的环境,具体操作步骤见沙箱接入指南:https://tech.open.alipay.com/support/knowledge/index.htm?knowledgeId=201602053521&categoryId=20068#/?_k=uajm0b

支付宝闪电开票沙箱接入注意点

1、支付宝闪电开票沙箱接入,详见沙箱接入指引,沙箱接口调通后,再进行线上测试与验收;
2、支付宝闪电开票沙箱接入接口调试的抬头数据准备需要使用沙箱买家账号(点击开发者中心-沙箱环境-沙箱账号)登录沙箱钱包(点击开发者中心-沙箱环境-沙箱工具)进入应用“支付宝闪电开票”添加。

onlineServer