Skip to main content

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

Project description

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

使用指北

  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'}
识别结果 ---  命初

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

invoice-captcha-0.0.1.tar.gz (7.8 kB view details)

Uploaded Source

File details

Details for the file invoice-captcha-0.0.1.tar.gz.

File metadata

  • Download URL: invoice-captcha-0.0.1.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for invoice-captcha-0.0.1.tar.gz
Algorithm Hash digest
SHA256 470bc40c53524d694bf3fa445f2a09a872db8b9ce956946d4a66bd094c2c7dcd
MD5 8287b73b328c7212bdc8aa1709201da4
BLAKE2b-256 169e770bde4f8c3df9a5eafc3922ad2be75f7b1c46247be172bc164f588940c7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page