通过AES加密网站的接口来传值,不需要手动加密字符串后复制过来传值。

 #coding:utf-8
import requests
import re
def get_aes_url(key, text):
url = 'http://www.ssleye.com/des/web_aes_encrypt'
header = {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
}
payload = {
"text": text,
"encode_flag": "utf8",
"key": key,
"iv": "",
"mode": "ECB",
"padding": "pkcs5",
"out_mode": "base64"
}
r = requests.post(url=url, headers=header, data=payload)
result = r.text
aa = re.findall("<pre>(.+?)</pre>", result)
bb = str(aa[0])
return bb if __name__ == '__main__':
# key = 'WuMlCJRN8zO886dw'
# text = '<REQUEST_FPKJXX><FPKJXX_FPTXX><NSRSBH>330201999999868</NSRSBH><NSRMC>航信培训企业</NSRMC><DDLSH>3302019999998682223</DDLSH><DDH></DDH><DDDATE>2018-07-20</DDDATE><BMB_BBH>13.0</BMB_BBH><XHF_DZ><![CDATA[宁波研发园]]></XHF_DZ><XHF_DH><![CDATA[88776655]]></XHF_DH><XHF_YHZH><![CDATA[中国银行6228480310540239016]]></XHF_YHZH><GHFMC><![CDATA[Nobita]]></GHFMC><GHF_NSRSBH><![CDATA[330203999999018]]></GHF_NSRSBH><GHF_DZ><![CDATA[宁波研发园]]></GHF_DZ><GHF_GDDH><![CDATA[55667788]]></GHF_GDDH><GHF_SJ>13867866196</GHF_SJ><GHF_EMAIL><![CDATA[364942727@qq.com]]></GHF_EMAIL><GHF_YHZH><![CDATA[光大银行6228480310540239018]]></GHF_YHZH><KPLY>999</KPLY><KPY>Nobita</KPY><SKY>Nobita</SKY><FHR>Nobita</FHR><KPLX>1</KPLX><YFP_DM></YFP_DM><YFP_HM></YFP_HM><KPHJJE>0.1</KPHJJE><HJBHSJE>0.1</HJBHSJE><HJSE>0</HJSE><BZ><![CDATA[公共能耗费,面积]]></BZ><BB></BB><WB></WB><FPZL></FPZL><SGBZ></SGBZ></FPKJXX_FPTXX><FPKJXX_XMXXS><FPKJXX_XMXX><XMMC><![CDATA[1]]></XMMC><XMDW></XMDW><GGXH></GGXH><XMSL>0</XMSL><HSBZ>0</HSBZ><XMDJ>0</XMDJ><FPHXZ>0</FPHXZ><SPBM>20300000</SPBM><ZXBM></ZXBM><YHZCBS>0</YHZCBS><LSLBS>3</LSLBS><ZZSTSGL></ZZSTSGL><XMJE>0.1</XMJE><SL>0</SL><SE>0</SE><KCE></KCE><KCQHSJE></KCQHSJE></FPKJXX_XMXX></FPKJXX_XMXXS></REQUEST_FPKJXX>'
# aa = get_aes_url(key, text)
# print(aa)
# print(type(aa))
pass

api_DZFPKJ 代码如下:

 #coding:utf-8
from get_AES_url import get_aes_url
from get_urlencode import jm_urlencode
from get_Base64 import str_base64
from get_Sha1 import hash_hmac
from hashlib import sha1
import requests
import time
#定义参数
host = "http://test2.51fapiaonb.cn:4011/DZFP_Four"
data_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
nsrsbh = "" #这里填需要查询的纳税人识别号
DDLSH_str1 = ""
DDLSH_str2 = ""
DDLSH = DDLSH_str1 + DDLSH_str2
ddh = ""
date = "2018-07-20"
KPLX = "" #1 蓝票 2 红票
YFP_DM = ""
YFP_HM = ""
SGBZ = "" #传空
YHZCBS = "" #优惠标识
LSLBS = "" #0税率标志
ZZSTSGL = "" #内容
SPBM = "" #免税 4030000000000000000 不征收 6010000000000000000
#所有商品行数据
KPHJJE = "0.1"
HJBHSJE = "0.1"
HJSE = ""
#单个商品行数据
XMJE = "0.1"
SL = ""
SE = ""
#发票开具信息
mxs = "<FPKJXX_XMXX>" + \
"<XMMC><![CDATA[1]]></XMMC>" + \
"<XMDW></XMDW>" + \
"<GGXH></GGXH>" + \
"<XMSL>0</XMSL>" + \
"<HSBZ>0</HSBZ>" + \
"<XMDJ>0</XMDJ>" + \
"<FPHXZ>0</FPHXZ>" + \
"<SPBM>" + SPBM + "</SPBM>" + \
"<ZXBM></ZXBM>" + \
"<YHZCBS>" + YHZCBS + "</YHZCBS>" + \
"<LSLBS>" + LSLBS + "</LSLBS>" + \
"<ZZSTSGL>" + ZZSTSGL + "</ZZSTSGL>" + \
"<XMJE>" + XMJE + "</XMJE>" + \
"<SL>" + SL + "</SL>" + \
"<SE>" + SE + "</SE>" + \
"<KCE></KCE>" + \
"<KCQHSJE></KCQHSJE>" + \
"</FPKJXX_XMXX>" #电子发票外部API-DZFPKJ(电子发票开具)
original_content = "<REQUEST_FPKJXX>" + \
"<FPKJXX_FPTXX>" + \
"<NSRSBH>" + nsrsbh + "</NSRSBH>" + \
"<NSRMC>航信培训企业</NSRMC>" + \
"<DDLSH>" + DDLSH + "</DDLSH>" + \
"<DDH>" + ddh + "</DDH>" + \
"<DDDATE>" + date + "</DDDATE>" + \
"<BMB_BBH>13.0</BMB_BBH>" + \
"<XHF_DZ><![CDATA[宁波研发园]]></XHF_DZ>" + \
"<XHF_DH><![CDATA[88776655]]></XHF_DH>" + \
"<XHF_YHZH><![CDATA[中国银行6228480310540239016]]></XHF_YHZH>" + \
"<GHFMC><![CDATA[Nobita]]></GHFMC>" + \
"<GHF_NSRSBH><![CDATA[330203999999018]]></GHF_NSRSBH>" + \
"<GHF_DZ><![CDATA[宁波研发园]]></GHF_DZ>" + \
"<GHF_GDDH><![CDATA[55667788]]></GHF_GDDH>" + \
"<GHF_SJ>13867866196</GHF_SJ>" + \
"<GHF_EMAIL><![CDATA[364942727@qq.com]]></GHF_EMAIL>" + \
"<GHF_YHZH><![CDATA[光大银行6228480310540239018]]></GHF_YHZH>" + \
"<KPLY>999</KPLY>" + \
"<KPY>Nobita</KPY>" + \
"<SKY>Nobita</SKY>" + \
"<FHR>Nobita</FHR>" + \
"<KPLX>" + KPLX + "</KPLX>" + \
"<YFP_DM>" + YFP_DM + "</YFP_DM>" + \
"<YFP_HM>" + YFP_HM + "</YFP_HM>" + \
"<KPHJJE>" + KPHJJE + "</KPHJJE>" + \
"<HJBHSJE>" + HJBHSJE + "</HJBHSJE>" + \
"<HJSE>" + HJSE + "</HJSE>" + \
"<BZ><![CDATA[公共能耗费,面积]]></BZ>" + \
"<BB></BB>" + \
"<WB></WB>" + \
"<FPZL></FPZL>" + \
"<SGBZ>" + SGBZ + "</SGBZ>" + \
"</FPKJXX_FPTXX>" + \
"<FPKJXX_XMXXS>" + \
mxs + \
"</FPKJXX_XMXXS>" + \
"</REQUEST_FPKJXX>"
#AES密钥
key = 'WuMlCJRN8zO886dw'
# print(original_content)
''' AES加密算法的网站:http://www.ssleye.com/aes_cipher.html
AES加密(加解密算法/工作模式/填充方式:AES/ECB/PKCS5Padding;测试环境key值:WuMlCJRN8zO886dw
'''
#初始数据original_content进行AES和Base64加密后,得到original_content_Aes
original_content_Aes_Base64 = get_aes_url(key, original_content) #通用报文初始数据(DZFPCX发票查询)
original_data = '<?xml version=\"1.0\" encoding=\"utf-8\"?>' + \
"<interface>" + \
"<globalInfo>" + \
"<version>4.0</version>" + \
"<interfaceCode>DZFPKJ</interfaceCode>" + \
"<token>{}</token>".format(nsrsbh) + \
"<requestTime>{}</requestTime>".format(data_time) + \
"</globalInfo>" + \
"<Data>" + \
"<content>{}</content>".format(original_content_Aes_Base64) + \
"</Data>" + \
"</interface>" #通用报文原始数据original_data进行Base64加密后,得到RequestParam,再进行urlencode解码
RequestParam_Base64 = str_base64(original_data)
# print("通用报文进行Base64加密后:\n", RequestParam_Base64)
RequestParam_Base64_Urlencode = jm_urlencode(RequestParam_Base64)
# print("通用报文进行Base64和Urlencode加密后:\n", RequestParam_Base64_Urlencode) #RequestParam通过HMAC-SHA1加密,得到Signature
Signature = hash_hmac('I7GBo4w9E6dmGlLVJMaVtXrhbNqp4KBh', RequestParam_Base64, sha1)
# print("通用报文进行Base64和Hash_hmac加密后:\n", Signature) #请求体data构建
RequestParam = RequestParam_Base64_Urlencode
data = "RequestParam=" + RequestParam + "&Signature=" + Signature
result = requests.post(url=host, params=data)
# print(result.url)
print('订单流水号为:\n{}'.format(DDLSH))
print('发票查询返回报文为:\n{}'.format(result.text))

api_DZFPKJ_QDFP 代码如下:

 #coding:utf-8
from get_AES_url import get_aes_url
from get_urlencode import jm_urlencode
from get_Base64 import str_base64
from get_Sha1 import hash_hmac
from hashlib import sha1
import requests
import time
#定义参数
host = "http://test2.51fapiaonb.cn:4011/DZFP_Four"
data_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
nsrsbh = "" #这里填需要查询的纳税人识别号
DDLSH_str1 = ""
DDLSH_str2 = ""
DDLSH = DDLSH_str1 + DDLSH_str2
ddh = ""
date = "2018-07-20"
KPLX = "" #1 蓝票 2 红票
YFP_DM = ""
YFP_HM = ""
SGBZ = "" #传空
YHZCBS = "" #优惠标识
LSLBS = "" #0税率标志
ZZSTSGL = "" #内容
SPBM = "" #免税 4030000000000000000 不征收 6010000000000000000
#所有商品行数据
KPHJJE = "1.0"
HJBHSJE = "1.0"
HJSE = ""
#单个商品行数据
XMJE = "0.1"
SL = ""
SE = ""
#发票开具信息
mxs = "<FPKJXX_XMXX>" + \
"<XMMC><![CDATA[1]]></XMMC>" + \
"<XMDW></XMDW>" + \
"<GGXH></GGXH>" + \
"<XMSL>0</XMSL>" + \
"<HSBZ>0</HSBZ>" + \
"<XMDJ>0</XMDJ>" + \
"<FPHXZ>0</FPHXZ>" + \
"<SPBM>20300000</SPBM>" + \
"<ZXBM></ZXBM>" + \
"<YHZCBS>0</YHZCBS>" + \
"<LSLBS>3</LSLBS>" + \
"<ZZSTSGL></ZZSTSGL>" + \
"<XMJE>0.1</XMJE>" + \
"<SL>0</SL>" + \
"<SE>0</SE>" + \
"<KCE></KCE>" + \
"<KCQHSJE></KCQHSJE>" + \
"</FPKJXX_XMXX>" + \
"<FPKJXX_XMXX>" + \
"<XMMC><![CDATA[1]]></XMMC>" + \
"<XMDW></XMDW>" + \
"<GGXH></GGXH>" + \
"<XMSL>0</XMSL>" + \
"<HSBZ>0</HSBZ>" + \
"<XMDJ>0</XMDJ>" + \
"<FPHXZ>0</FPHXZ>" + \
"<SPBM>20300000</SPBM>" + \
"<ZXBM></ZXBM>" + \
"<YHZCBS>0</YHZCBS>" + \
"<LSLBS>3</LSLBS>" + \
"<ZZSTSGL></ZZSTSGL>" + \
"<XMJE>0.1</XMJE>" + \
"<SL>0</SL>" + \
"<SE>0</SE>" + \
"<KCE></KCE>" + \
"<KCQHSJE></KCQHSJE>" + \
"</FPKJXX_XMXX>" + \
"<FPKJXX_XMXX>" + \
"<XMMC><![CDATA[1]]></XMMC>" + \
"<XMDW></XMDW>" + \
"<GGXH></GGXH>" + \
"<XMSL>0</XMSL>" + \
"<HSBZ>0</HSBZ>" + \
"<XMDJ>0</XMDJ>" + \
"<FPHXZ>0</FPHXZ>" + \
"<SPBM>20300000</SPBM>" + \
"<ZXBM></ZXBM>" + \
"<YHZCBS>0</YHZCBS>" + \
"<LSLBS>3</LSLBS>" + \
"<ZZSTSGL></ZZSTSGL>" + \
"<XMJE>0.1</XMJE>" + \
"<SL>0</SL>" + \
"<SE>0</SE>" + \
"<KCE></KCE>" + \
"<KCQHSJE></KCQHSJE>" + \
"</FPKJXX_XMXX>" + \
"<FPKJXX_XMXX>" + \
"<XMMC><![CDATA[1]]></XMMC>" + \
"<XMDW></XMDW>" + \
"<GGXH></GGXH>" + \
"<XMSL>0</XMSL>" + \
"<HSBZ>0</HSBZ>" + \
"<XMDJ>0</XMDJ>" + \
"<FPHXZ>0</FPHXZ>" + \
"<SPBM>20300000</SPBM>" + \
"<ZXBM></ZXBM>" + \
"<YHZCBS>0</YHZCBS>" + \
"<LSLBS>3</LSLBS>" + \
"<ZZSTSGL></ZZSTSGL>" + \
"<XMJE>0.1</XMJE>" + \
"<SL>0</SL>" + \
"<SE>0</SE>" + \
"<KCE></KCE>" + \
"<KCQHSJE></KCQHSJE>" + \
"</FPKJXX_XMXX>" + \
"<FPKJXX_XMXX>" + \
"<XMMC><![CDATA[1]]></XMMC>" + \
"<XMDW></XMDW>" + \
"<GGXH></GGXH>" + \
"<XMSL>0</XMSL>" + \
"<HSBZ>0</HSBZ>" + \
"<XMDJ>0</XMDJ>" + \
"<FPHXZ>0</FPHXZ>" + \
"<SPBM>20300000</SPBM>" + \
"<ZXBM></ZXBM>" + \
"<YHZCBS>0</YHZCBS>" + \
"<LSLBS>3</LSLBS>" + \
"<ZZSTSGL></ZZSTSGL>" + \
"<XMJE>0.1</XMJE>" + \
"<SL>0</SL>" + \
"<SE>0</SE>" + \
"<KCE></KCE>" + \
"<KCQHSJE></KCQHSJE>" + \
"</FPKJXX_XMXX>" + \
"<FPKJXX_XMXX>" + \
"<XMMC><![CDATA[1]]></XMMC>" + \
"<XMDW></XMDW>" + \
"<GGXH></GGXH>" + \
"<XMSL>0</XMSL>" + \
"<HSBZ>0</HSBZ>" + \
"<XMDJ>0</XMDJ>" + \
"<FPHXZ>0</FPHXZ>" + \
"<SPBM>20300000</SPBM>" + \
"<ZXBM></ZXBM>" + \
"<YHZCBS>0</YHZCBS>" + \
"<LSLBS>3</LSLBS>" + \
"<ZZSTSGL></ZZSTSGL>" + \
"<XMJE>0.1</XMJE>" + \
"<SL>0</SL>" + \
"<SE>0</SE>" + \
"<KCE></KCE>" + \
"<KCQHSJE></KCQHSJE>" + \
"</FPKJXX_XMXX>" + \
"<FPKJXX_XMXX>" + \
"<XMMC><![CDATA[1]]></XMMC>" + \
"<XMDW></XMDW>" + \
"<GGXH></GGXH>" + \
"<XMSL>0</XMSL>" + \
"<HSBZ>0</HSBZ>" + \
"<XMDJ>0</XMDJ>" + \
"<FPHXZ>0</FPHXZ>" + \
"<SPBM>20300000</SPBM>" + \
"<ZXBM></ZXBM>" + \
"<YHZCBS>0</YHZCBS>" + \
"<LSLBS>3</LSLBS>" + \
"<ZZSTSGL></ZZSTSGL>" + \
"<XMJE>0.1</XMJE>" + \
"<SL>0</SL>" + \
"<SE>0</SE>" + \
"<KCE></KCE>" + \
"<KCQHSJE></KCQHSJE>" + \
"</FPKJXX_XMXX>" + \
"<FPKJXX_XMXX>" + \
"<XMMC><![CDATA[1]]></XMMC>" + \
"<XMDW></XMDW>" + \
"<GGXH></GGXH>" + \
"<XMSL>0</XMSL>" + \
"<HSBZ>0</HSBZ>" + \
"<XMDJ>0</XMDJ>" + \
"<FPHXZ>0</FPHXZ>" + \
"<SPBM>20300000</SPBM>" + \
"<ZXBM></ZXBM>" + \
"<YHZCBS>0</YHZCBS>" + \
"<LSLBS>3</LSLBS>" + \
"<ZZSTSGL></ZZSTSGL>" + \
"<XMJE>0.1</XMJE>" + \
"<SL>0</SL>" + \
"<SE>0</SE>" + \
"<KCE></KCE>" + \
"<KCQHSJE></KCQHSJE>" + \
"</FPKJXX_XMXX>" + \
"<FPKJXX_XMXX>" + \
"<XMMC><![CDATA[1]]></XMMC>" + \
"<XMDW></XMDW>" + \
"<GGXH></GGXH>" + \
"<XMSL>0</XMSL>" + \
"<HSBZ>0</HSBZ>" + \
"<XMDJ>0</XMDJ>" + \
"<FPHXZ>0</FPHXZ>" + \
"<SPBM>20300000</SPBM>" + \
"<ZXBM></ZXBM>" + \
"<YHZCBS>0</YHZCBS>" + \
"<LSLBS>3</LSLBS>" + \
"<ZZSTSGL></ZZSTSGL>" + \
"<XMJE>0.1</XMJE>" + \
"<SL>0</SL>" + \
"<SE>0</SE>" + \
"<KCE></KCE>" + \
"<KCQHSJE></KCQHSJE>" + \
"</FPKJXX_XMXX>" + \
"<FPKJXX_XMXX>" + \
"<XMMC><![CDATA[1]]></XMMC>" + \
"<XMDW></XMDW>" + \
"<GGXH></GGXH>" + \
"<XMSL>0</XMSL>" + \
"<HSBZ>0</HSBZ>" + \
"<XMDJ>0</XMDJ>" + \
"<FPHXZ>0</FPHXZ>" + \
"<SPBM>20300000</SPBM>" + \
"<ZXBM></ZXBM>" + \
"<YHZCBS>0</YHZCBS>" + \
"<LSLBS>3</LSLBS>" + \
"<ZZSTSGL></ZZSTSGL>" + \
"<XMJE>0.1</XMJE>" + \
"<SL>0</SL>" + \
"<SE>0</SE>" + \
"<KCE></KCE>" + \
"<KCQHSJE></KCQHSJE>" + \
"</FPKJXX_XMXX>" #电子发票外部API-DZFPKJ(电子发票开具)
original_content = "<REQUEST_FPKJXX>" + \
"<FPKJXX_FPTXX>" + \
"<NSRSBH>" + nsrsbh + "</NSRSBH>" + \
"<NSRMC>航信培训企业</NSRMC>" + \
"<DDLSH>" + DDLSH + "</DDLSH>" + \
"<DDH>" + ddh + "</DDH>" + \
"<DDDATE>" + date + "</DDDATE>" + \
"<BMB_BBH>13.0</BMB_BBH>" + \
"<XHF_DZ><![CDATA[222]]></XHF_DZ>" + \
"<XHF_DH><![CDATA[222]]></XHF_DH>" + \
"<XHF_YHZH><![CDATA[222]]></XHF_YHZH>" + \
"<GHFMC><![CDATA[22 2]]></GHFMC>" + \
"<GHF_NSRSBH><![CDATA[330203999999018]]></GHF_NSRSBH>" + \
"<GHF_DZ><![CDATA[地址]]></GHF_DZ>" + \
"<GHF_GDDH><![CDATA[电话]]></GHF_GDDH>" + \
"<GHF_SJ>17871838087</GHF_SJ>" + \
"<GHF_EMAIL><![CDATA[zxy@ms.whb.ac.cn]]></GHF_EMAIL>" + \
"<GHF_YHZH><![CDATA[yhzh]]></GHF_YHZH>" + \
"<KPLY>999</KPLY>" + \
"<KPY>综合服务公共能耗</KPY>" + \
"<SKY>日常维修综合服务</SKY>" + \
"<FHR>车位管理综合面积</FHR>" + \
"<KPLX>" + KPLX + "</KPLX>" + \
"<YFP_DM>" + YFP_DM + "</YFP_DM>" + \
"<YFP_HM>" + YFP_HM + "</YFP_HM>" + \
"<KPHJJE>" + KPHJJE + "</KPHJJE>" + \
"<HJBHSJE>" + HJBHSJE + "</HJBHSJE>" + \
"<HJSE>" + HJSE + "</HJSE>" + \
"<BZ><![CDATA[公共能耗费,面积]]></BZ>" + \
"<BB></BB>" + \
"<WB></WB>" + \
"<FPZL></FPZL>" + \
"<SGBZ>" + SGBZ + "</SGBZ>" + \
"</FPKJXX_FPTXX>" + \
"<FPKJXX_XMXXS>" + \
mxs + \
"</FPKJXX_XMXXS>" + \
"</REQUEST_FPKJXX>"
#AES密钥
key = 'WuMlCJRN8zO886dw'
# print(original_content)
''' AES加密算法的网站:http://www.ssleye.com/aes_cipher.html
AES加密(加解密算法/工作模式/填充方式:AES/ECB/PKCS5Padding;测试环境key值:WuMlCJRN8zO886dw
'''
#初始数据original_content进行AES和Base64加密后,得到original_content_Aes
original_content_Aes_Base64 = get_aes_url(key, original_content) #通用报文初始数据(DZFPCX发票查询)
original_data = '<?xml version=\"1.0\" encoding=\"utf-8\"?>' + \
"<interface>" + \
"<globalInfo>" + \
"<version>4.0</version>" + \
"<interfaceCode>DZFPKJ</interfaceCode>" + \
"<token>{}</token>".format(nsrsbh) + \
"<requestTime>{}</requestTime>".format(data_time) + \
"</globalInfo>" + \
"<Data>" + \
"<content>{}</content>".format(original_content_Aes_Base64) + \
"</Data>" + \
"</interface>" #通用报文原始数据original_data进行Base64加密后,得到RequestParam,再进行urlencode解码
RequestParam_Base64 = str_base64(original_data)
# print("通用报文进行Base64加密后:\n", RequestParam_Base64)
RequestParam_Base64_Urlencode = jm_urlencode(RequestParam_Base64)
# print("通用报文进行Base64和Urlencode加密后:\n", RequestParam_Base64_Urlencode) #RequestParam通过HMAC-SHA1加密,得到Signature
Signature = hash_hmac('I7GBo4w9E6dmGlLVJMaVtXrhbNqp4KBh', RequestParam_Base64, sha1)
# print("通用报文进行Base64和Hash_hmac加密后:\n", Signature) #请求体data构建
RequestParam = RequestParam_Base64_Urlencode
data = "RequestParam=" + RequestParam + "&Signature=" + Signature
result = requests.post(url=host, params=data)
# print(result.url)
print('发票查询ddlsh为:\n{}'.format(DDLSH))
print('发票查询返回报文为:\n{}'.format(result.text))

api_DZFPCX 代码如下:

 #coding:utf-8
from get_AES_url import get_aes_url
from get_urlencode import jm_urlencode
from get_Base64 import str_base64
from get_Sha1 import hash_hmac
from hashlib import sha1
import requests
import time
#定义参数
host = "http://test2.51fapiaonb.cn:4011/DZFP_Four"
data_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
nsrsbh = "" #这里填需要查询的纳税人识别号
# #电子发票外部API-DZFPCX(电子发票查询)
ddlsh = "" #这里填写发票对应的订单流水号
original_content = "<FPXX>" + \
"<NSRSBH>{}</NSRSBH>".format(nsrsbh) + \
"<DDLSH>{}</DDLSH>".format(ddlsh) + "</FPXX>" #AES密钥
key = 'WuMlCJRN8zO886dw'
#初始数据original_content进行AES和Base64加密后,得到original_content_Aes_Base64
original_content_Aes_Base64 = get_aes_url(key, original_content)
# print("content进行AES和Base64加密后:\n", original_content_Aes_Base64) # #通用报文初始数据(DZFPCX发票查询)
original_data = '<?xml version=\"1.0\" encoding=\"utf-8\"?>' + \
"<interface>" + \
"<globalInfo>" + \
"<version>4.1</version>" + \
"<interfaceCode>DZFPCX</interfaceCode>" + \
"<token>" + nsrsbh + "</token>" + \
"<requestTime>" + data_time + "</requestTime>" + \
"</globalInfo>" + \
"<Data>" + \
"<content>" + original_content_Aes_Base64 + "</content>" + \
"</Data>" + \
"</interface>" #通用报文原始数据original_data进行Base64加密后,得到RequestParam,再进行urlencode解码
RequestParam_Base64 = str_base64(original_data)
# print("通用报文进行Base64加密后:\n", RequestParam_Base64)
RequestParam_Base64_Urlencode = jm_urlencode(RequestParam_Base64)
# print("通用报文进行Base64和Urlencode加密后:\n", RequestParam_Base64_Urlencode) #RequestParam通过HMAC-SHA1加密,得到Signature
Signature = hash_hmac('I7GBo4w9E6dmGlLVJMaVtXrhbNqp4KBh', RequestParam_Base64, sha1)
# print("通用报文进行Base64和Hash_hmac加密后:\n", Signature) #请求体data构建
RequestParam = RequestParam_Base64_Urlencode
# url = host + "?RequestParam=" + RequestParam + "&Signature=" + Signature
data = "RequestParam=" + RequestParam + "&Signature=" + Signature
result = requests.post(url=host, params=data)
# print(result.url) #打印请求url
# print(RequestParam)
# print(Signature)
print('发票查询返回报文为:\n{}'.format(result.text))

api_DZFPKJ & api_DZFPCX(get_AES_url代码优化)的更多相关文章

  1. api_DZFPKJ & api_DZFPCX

    AES加密算法的网站:http://www.ssleye.com/aes_cipher.html """ AES加密(加解密算法/工作模式/填充方式:AES/ECB/PK ...

  2. PHP代码优化

    1 代码优化 1 尽量静态化 如果一个方法能被静态,那就声明它为静态的,速度可提高1/4,甚至我测试的时候,这个提高了近三倍. 当然了,这个测试方法需要在十万级以上次执行,效果才明显. 其实静态方法和 ...

  3. 跟Unity3D学代码优化

    今天我们来聊聊如何跟Unity学代码优化,准确地说,是通过学习Unity的IL2CPP技术的优化策略,应用到我们的日常逻辑开发中. 做过Unity开发的同学想必对IL2CPP都很清楚,简单地说,IL2 ...

  4. 记录一次bug解决过程:else未补全导致数据泄露和代码优化

    一.总结 快捷键ctrl + alt + 四个方向键 --> 倒置屏幕 未补全else逻辑,倒置查询数据泄露 空指针是最容易犯的错误,数据的空指针,可以普遍采用三目运算符来解决 SVN冲突解决关 ...

  5. 【Java】记录一次代码优化

    前不久的项目时间紧张,为了尽快完成原型开发,写了一段效率相当低的代码. 最近几天闲下来,主动把之前的代码优化了一下:)   标签:Java.Mybatis.MySQL 概况:本地系统从另外一个系统得到 ...

  6. Java代码优化(长期更新)

    前言 2016年3月修改,结合自己的工作和平时学习的体验重新谈一下为什么要进行代码优化.在修改之前,我的说法是这样的: 就像鲸鱼吃虾米一样,也许吃一个两个虾米对于鲸鱼来说作用不大,但是吃的虾米多了,鲸 ...

  7. 微信扫描打开APP下载链接提示代码优化

    上一次我发了一篇文章叫“微信打开网址添加在浏览器中打开提示”,里面我发出来了三个代码,分别是纯JS.js+html.jQuery+HTML代码.今天来一个简化版带可以关闭的按钮操作.使用的是纯JS+H ...

  8. 微信扫描打开APP下载链接提示代码优化(转)

    上一次我发了一篇文章叫“微信打开网址添加在浏览器中打开提示”,里面我发出来了三个代码,分别是纯JS.js+html.jQuery+HTML代码.今天来一个简化版带可以关闭的按钮操作.使用的是纯JS+H ...

  9. [转]SqlSever2005 一千万条以上记录分页数据库优化经验总结【索引优化 + 代码优化】一周搞定

    对普通开发人员来说经常能接触到上千万条数据优化的机会也不是很多,这里还是要感 谢公司提供了这样的一个环境,而且公司让我来做优化工作.当数据库中的记录不超过10万条时,很难分辨出开发人员的水平有多高,当 ...

随机推荐

  1. 家乐的深度学习笔记「4」 - softmax回归

    目录 softmax回归 分类问题 softmax回归模型 softmax运算 矢量表达式 单样本分类的矢量计算表达式 小批量样本分类的矢量计算表达式 交叉熵损失函数 模型预测及评价 图像分类数据集( ...

  2. Java方法调用数组,是否改变原数组元素的总结

    Java方法调用数组,是否改变原数组元素的总结 //个人理解, 欢迎吐槽 注意String是引用型变量, 我的理解也就是指向型, 指向一个数据或变量, 画图理解最容易, string 指向的 数据的值 ...

  3. 生产-消费者,C++11实现

    C++11中新增加了线程库<thread>和原子操作库<atomic>,使用这两个库可以实现生产——消费者模型.上代码 //生产者生产函数 void product(std:: ...

  4. Day19-apache

    HTTPD(俗称apache) 简介:目前来说,Linuxweb服务器主要用apache与nginx. 1.web服务器的输入/输出结构: 单线程I/O结构 多线程I/O结构 复用的I/O结构,单个线 ...

  5. 001_manifest.json手册

    manifest.json 是一个 JSON 格式的文件,是每个 WebExtension必须包含的唯一文件. 使用manifest.json,您可以指定扩展名的基本元数据,如名称和版本,还可以指定扩 ...

  6. 创建一个tar备份包

                                                                 创建一个tar备份包 2.1问题 本例要求使用tar工具完成以下备份任务: 创 ...

  7. SpringCloud(三)之我学 Hystrix

    1.断路器 在消费服务的启动类,添加注解:@EnableCircuitBreaker,在消费服务的调用类上,添加注解:@HystrixCommand(fallbackMethod = "&q ...

  8. 【数据库】MySQL数据库(四)

    一.对数据的操作(详细版) 1.添加数据 1> insert into 表名 (字段1,字段2...) values (值1,值2...); 2> insert into 表名 (字段1, ...

  9. wireshark抓包实战(一),抓包原理

    一.什么样的"包"能被wireshark抓住呢? 1.本机 即直接抓取进出本机网卡的流量包.这种情况下,wireshark会绑定本机的一块网卡. 2.集线器 用于抓取流量泛洪,冲突 ...

  10. OS-DOS/CMD/Windows/各类软件快捷键等使用总结

    一.快捷键 很多软件的快捷键使用相通,在不确定的情况下,先试试其他软件的快捷键的使用方法 Windows电脑快捷键 HP惠普笔记本 win+E 打开文件管器 win+D 显示桌面 win+L 锁计算机 ...