Skip to main content

国税总局发票查验平台验证码获取与识别

使用指北

  1. pip install invoice-captcha

  2. 调用示例:

    import requests
    from invoice_captcha.utils import get_captcha_params, parse_captcha_resp, kill_captcha_fast, ua
    
    CAPTCHA_URL = "https://fpcy.guangdong.chinatax.gov.cn/NWebQuery/yzmQuery"
    
    
    # 发票代码
    key1 = "011111111111"
    # 发票号码
    key2 = "11111111"
    
    # # 开票日期
    # key3 = "20200603"
    # # 校验码或发票金额
    # key4 = "000000"
    
    
    def fetch_captcha(invoice_code, invoice_no):
    
        sess = requests.Session()
    
        # 使用代理,需要自备代理
        # sess.proxies = proxy
        sess.headers = {"User-Agent": ua.random}
    
        # 获取验证码请求参数
        payload = get_captcha_params(
            invoice_code=invoice_code, invoice_no=invoice_no
        )
    
        # 通过官网获取验证码
        r = sess.get(CAPTCHA_URL, params=payload)
    
        # 验证码请求参数解密
        plain_dict = parse_captcha_resp(r)
    
        # 验证码请求返回明文
        # key1 图片base64
        # key4 验证码需要识别的颜色代码
        print("解密参数 --- ", plain_dict)
    
        # 调用识别测试接口
        captcha_text = kill_captcha_fast(
            plain_dict, 
          	# 默认API有使用次数限制,可联系作者QQ:27009583,测试独立接口
            # api="http://kerlomz-ac86u.asuscomm.com:19811/captcha/v1"
        )
    
        # 输出识别结果
        print("识别结果 --- ", captcha_text)
        
        
    if __name__ == '__main__':
        for i in range(10):
            fetch_captcha(key1, key2)
    

输出结果:

解密参数 ---  {'key1': 'iVBORw0KGgoA...5ErkJggg==', 'key2': '2020-06-16 16:56:36', 'key3': '9636e07df9aae6bd0483c5f6ea1ecbdc', 'key4': '03', 'key5': '2'}
识别结果 ---  xm8
解密参数 ---  {'key1': 'iVBORw0KGgoA...UVORK5CYII=', 'key2': '2020-06-16 16:56:42', 'key3': 'd202f846119faa08a0e95eec48ca1bfe', 'key4': '01', 'key5': '2'}
识别结果 ---  命初

Metadata

Release files for invoice-captcha 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for invoice-captcha 0.0.1
File Size Uploaded
invoice-captcha-0.0.1.tar.gz 7.8 kB Details

Release files / invoice-captcha-0.0.1.tar.gz

Download URL invoice-captcha-0.0.1.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
470bc40c53524d694bf3fa445f2a09a872db8b9ce956946d4a66bd094c2c7dcd
BLAKE2b-256 checksum
How to use checksums
169e770bde4f8c3df9a5eafc3922ad2be75f7b1c46247be172bc164f588940c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page