发票接口#

class wechatpy.client.api.WeChatInvoice(client=None)[源代码]#
batch_update_reimburse(openid, reimburse_status, invoice_list)[源代码]#

报销方批量更新发票信息

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Reimburser_API_List.html

参数
  • openid – 用户的 Open ID

  • reimburse_status – 发票报销状态

  • invoice_list (list[dict]) – 发票列表

create_card(base_info, payee, invoice_type, detail=None)[源代码]#

创建发票卡券模板 注意这里的对象和会员卡有类似之处,但是含义有不同。创建发票卡券模板是创建发票卡券的基础。

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Invoicing_Platform_API_List.html

:param base_info:发票卡券模板基础信息 :type base_info: dict :param payee: 收款方(开票方)全称,显示在发票详情内。建议一个收款方对应一个发票卡券模板 :param invoice_type: 发票类型 :param detail: 备注详情 :return: 发票卡券模板的编号,用于后续该商户发票生成后,作为必填参数在调用插卡接口时传入

get_auth_data(s_pappid, order_id)[源代码]#

查询授权数据

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Vendor_API_List.html

参数
  • s_pappid – 开票平台在微信的标识,由开票平台告知商户

  • order_id – 订单id,在商户内单笔开票请求的唯一识别号

返回

用户的开票信息

返回类型

dict

get_auth_field()[源代码]#

获取授权页字段信息

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Vendor_API_List.html

返回

授权页的字段设置

返回类型

dict

get_auth_url(s_pappid, order_id, money, timestamp, source, ticket, auth_type, redirect_url=None)[源代码]#

获取授权页链接

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Vendor_API_List.html

参数
  • s_pappid – 开票平台在微信的标识号,商户需要找开票平台提供

  • order_id – 订单id,在商户内单笔开票请求的唯一识别号

  • money (int) – 订单金额,以分为单位

  • timestamp (int) – Unix 时间戳

  • source – 开票来源。app: App开票, web: 微信H5开票, wap: 普通网页开票, wxa:小程序开发票

  • ticket – 根据获取授权ticket接口取得

  • auth_type (int) – 授权类型。0: 开票授权,1: 填写字段开票授权,2: 领票授权

  • redirect_url – 授权成功后跳转页面。本字段只有在source为H5的时候需要填写。

返回

获取授权页链接

get_contact()[源代码]#

商户获取授权链接之前,需要先设置商户的联系方式 详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Vendor_API_List.html#17

get_pay_mch()[源代码]#

查询商户号与开票平台关联情况

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Vendor_API_List.html

返回

mchid 和 s_pappid

返回类型

dict

get_pdf(s_media_id)[源代码]#

查询已上传的 PDF

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Invoicing_Platform_API_List.html

参数

s_media_id – PDF 文件上传时的 s_media_id

返回

PDF 文件的 URL,以及过期时间

返回类型

dict

get_reimburse(card_id, encrypt_code)[源代码]#

报销方查询发票信息

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/Auto-print/API_Documentation.html#_5-2-%E8%AF%B7%E6%B1%82%E6%96%B9%E5%BC%8F

参数
  • card_id – 发票卡券的 Card ID

  • encrypt_code – 发票卡券的加密 Code

返回

电子发票的结构化信息

返回类型

dict

get_select_title_url(attach=None)[源代码]#

获取商户专属开票链接 商户调用接口,获取链接。用户扫码,可以选择抬头发给商户。可以将链接转成二维码,立在收银台。

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/Quick_issuing/Interface_Instructions.html

参数

attach – 附加字段,用户提交发票时会发送给商户

返回

商户专属开票链接

get_url()[源代码]#

获取自身的开票平台识别码

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Invoicing_Platform_API_List.html

:return:该开票平台专用的授权链接

get_user_title_url(user_fill, title=None, phone=None, tax_no=None, addr=None, bank_type=None, bank_no=None, out_title_id=None)[源代码]#

获取添加发票链接 获取链接,发送给用户。用户同意以后,发票抬头信息将会录入到用户微信中

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/Quick_issuing/Interface_Instructions.html

参数
  • user_fill (bool) – 企业设置抬头为0,用户自己填写抬头为1

  • title – 抬头,当 user_fill 为 False 时必填

  • phone – 联系方式

  • tax_no – 税号

  • addr – 地址

  • bank_type – 银行类型

  • bank_no – 银行号码

  • out_title_id – 开票码

返回

添加发票的链接

insert(order_id, card_id, appid, card_ext)[源代码]#

将电子发票卡券插入用户卡包

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Invoicing_Platform_API_List.html

参数
  • order_id – 发票order_id,既商户给用户授权开票的订单号

  • card_id – 发票卡券模板的编号

  • appid – 商户 AppID

  • card_ext (dict) – 发票具体内容

返回

随机防重字符串,以及用户 Open ID

reject_insert(s_pappid, order_id, reason, redirect_url=None)[源代码]#

拒绝用户的开发票请求

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Vendor_API_List.html

参数
  • s_pappid – 开票平台在微信的标识号,商户需要找开票平台提供

  • order_id – 订单id,在商户内单笔开票请求的唯一识别号

  • reason – 商家解释拒绝开票的原因,如重复开票,抬头无效、已退货无法开票等

  • redirect_url – 跳转链接,引导用户进行下一步处理,如重新发起开票、重新填写抬头、展示订单情况等

scan_title(scan_text)[源代码]#

根据扫描码,获取用户发票抬头 商户扫用户“我的—个人信息—我的发票抬头”里面的抬头二维码后,通过调用本接口,可以获取用户抬头信息

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/Quick_issuing/Interface_Instructions.html

参数

scan_text – 扫码后获取的文本

返回

用户的发票抬头数据

返回类型

dict

set_auth_field(user_field, biz_field)[源代码]#

设置授权页字段信息

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Vendor_API_List.html

参数
  • user_field (dict) – 授权页个人发票字段

  • biz_field (dict) – 授权页单位发票字段

set_contact(phone, time_out)[源代码]#

商户获取授权链接之前,需要先设置商户的联系方式 详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Vendor_API_List.html#17

参数
  • phone – 联系电话

  • time_out – 开票超时时间

set_pay_mch(mchid, s_pappid)[源代码]#

关联商户号与开票平台,设置支付后开票

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Vendor_API_List.html#17

参数
  • mchid – 微信支付商户号

  • s_pappid – 开票平台在微信的标识号,商户需要找开票平台提供

update_reimburse(card_id, encrypt_code, reimburse_status)[源代码]#

报销方更新发票信息

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Reimburser_API_List.html

参数
  • card_id – 发票卡券的 Card ID

  • encrypt_code – 发票卡券的加密 Code

  • reimburse_status – 发票报销状态

update_status(card_id, code, reimburse_status)[源代码]#

更新发票卡券的状态

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Invoicing_Platform_API_List.html

参数
  • card_id – 发票卡券模板的编号

  • code – 发票卡券的编号

  • reimburse_status – 发票报销状态

upload_pdf(pdf)[源代码]#

上传电子发票中的消费凭证 PDF

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Invoicing_Platform_API_List.html

参数

pdf – 要上传的 PDF 文件,一个 File-object

返回

64位整数,在将发票卡券插入用户卡包时使用用于关联pdf和发票卡券。有效期为3天。