api_DZFPKJ & api_DZFPCX
AES加密算法的网站:http://www.ssleye.com/aes_cipher.html
"""
AES加密(加解密算法/工作模式/填充方式:AES/ECB/PKCS5Padding;测试环境key值:WuMlCJRN8zO886dw
"""
api_DZFPKJ 代码如下:
#coding:utf-8
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[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)
#初始数据original_content进行AES加密后,得到original_content_Aes
# original_content_Aes = jm_Aes(key, original_content)
# print("content进行AES加密后:\n", original_content_Ae
original_content_Aes = '9qyQm/1khrFeC+rlbwMd5/RaEIb+zZOLlS0yk+6kTlc8ZQLWS1VzwJGmbB1Qg4jetlFZYOAyeDXzNW5+8QIRZGLuTbvLwW5w40V/QeSXn+CsT0P+IWSyXmB6dJ6PQUXHYRn3Jh2UV4SMD1yx+C5SdSSW1D7dGpyMSPEIzuDxYdLEpoT21XXCSK9j0VvswRKhdYzMAEmpeGWxuqnyA2ARAojEREo/RBKj4ZLpH9yMkpueQ0YcgOQoosb38M9mumcuLfyBgkIKdEPYkgXyxPwFpm4IraXamKV9z6sjpMozgkPf5kW8e6dpLctqaWszILuZzmqha/MU3+4pLObonPdK4EUZ9zjdHPG8qwqLbtOE1RrjansSkDFq7pYlSYc0bceMWcb/zywR2MnpaVBfG6IwBjKlSUmYzarVq+UNhNGiyJQS0o6I9W5DpeRJwE8reSWLiItdZuU/MwrkYcrmn75W3KPDbL+Cqs/Rdy/v4JEQI19Ln7EkV9pnOHghS6X4yd/kCPSCnw5FaQzJiChf8tZRC4bUrgjKOZBpZM13aRu8nyXnrjAv8WyEZoISlvWHat2kI1A2pUEBCQRCOMSD62VlW6rBQsi52at+tJbxF1hw8tnuY3EEAbfHiQ6zyx5zJzhm6QhjqhaKWyf8rSOJcHga+5U5oB7qtzaAouK2us5oz25lO/sxDmui1UXooTUsN+9iRRn3ON0c8byrCotu04TVGnHj1hgooHvGVrVMbQsTHdaCXDqA5mUt/36CWOK6Hu+/q8nbTD1un4xuxIxsgly1TgmQkd+v8cbvTm29UJYt3tW2YgUlbjWILNVvUqfncIGgoaSCX33ma8AsBUSBR5cnE0HBNJmJCMmVnvCVddNAMST+/Ti0iUwkW1hsM4cSDatWwr7+iheiFYPznKh6GYbHOFocJkKcGJf4p/9rErtBXxCRHi8/Ce3jvT7XxCajQj7VCUvdd2pfi844ILFuAwrCSNwnblwlKLy+6fizrMBs6R2kwifRQcdvF4oiKT0Ni2yK/TNzEZfL4kTT/bYpkw4DcxBLhPgWP3T5lx9PJ4XunVAp5xblupvOfoxskhdjonTrCZYodTvEm3wCbKUbOij0GWlaERgf8bjrzBeZBSMKUKnpGkK8S8j9a29LsscqvFfGrGeSEsdk3URvahnM9qFuc+vf+bkX4cDmq09y7Ot1RQW6xN1fA9SrJP/73dfKo588QjpgRA4cSb6tPTbNGAbluu3jMTof+q+b7pGH8XR9a3YYzBi3ehk7sTo7SaOa50ifpUAh+HQHO1E70d5MMBcsh2sVbfPeicZU3sYhE+cKGxaW2CNM7mgasSmzyky5IuWpKgUOyL57eZejUAce5y4MWYgu1hBN+Y28uBcUhstapNiOfLBh8OBGSZrQByVQa8dBU/TO/hWUDnrS0JMWHqgRIJVsMPcszBo0ab0P8N7U3omkbX4nJ2xZ/oNlFIt9ObxRy0T0S7fGnfth4GHNZ5pzmepCxYc1KFvVdw8a9afLk3v4mVwi6bOnm4XDpgD0OdW8Lkgb9WWGbawDE1WbchGbSOa9xSpUA9VxTZvo4ZsKPEXe49aFLZctkeiuQ3JGqHKmsmrZUbtuD4EnajwxYs24OSfV7xsLI7T0ZrW9w5e1P3M=' #初始数据original_content_Aes进行Base64加密后,得到original_content_Aes_Base64
original_content_Aes_Base64 = str_base64(original_content_Aes)
# print("content进行AES和Base64加密后:\n", original_content_Aes_Base64) # #通用报文初始数据(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) + \
"</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)
print('发票查询返回报文为:\n{}'.format(result.text))
api_DZFPCX 代码如下:
#coding:utf-8
from get_Aes import jm_Aes
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加密后,得到original_content_Aes
original_content_Aes = jm_Aes(key, original_content)
# print("content进行AES加密后:\n", original_content_Aes) #初始数据original_content_Aes进行Base64加密后,得到original_content_Aes_Base64
original_content_Aes_Base64 = str_base64(original_content_Aes)
# 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 + "</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('发票查询返回报文为:\n{}'.format(result.text))
str_AES_ECB加密算法:
#coding:utf-8
"""
AES加密(加解密算法/工作模式/填充方式:AES/ECB/PKCS5Padding;测试环境key值:WuMlCJRN8zO886dw
"""
import base64
from Crypto.Cipher import AES
# 补足字符串长度为16的倍数
def add_to_16(s):
while len(s) % 16 != 0:
s += (16 - len(s) % 16) * chr(16 - len(s) % 16)
return str.encode(s) # 返回bytes def jm_Aes(key_input, text_input):
aes = AES.new(str.encode(key_input), AES.MODE_ECB) # 初始化加密器,本例采用ECB加密模式
encrypted_text = str(base64.encodebytes(aes.encrypt(add_to_16(text_input))), encoding='utf8').replace('\n', '') # 加密
# decrypted_text = aes.decrypt(base64.decodebytes(bytes(encrypted_text, encoding='utf8'))).decode("utf8") # 解密
# decrypted_text = decrypted_text[:-ord(decrypted_text[-1])] # 去除多余补位
# print('pkcs5加密值:', encrypted_text)
# print('pkcs5解密值:', decrypted_text)
return encrypted_text if __name__ == '__main__':
key = 'WuMlCJRN8zO886dw' # 密码
text1 = '<FPXX><NSRSBH>330201999999868</NSRSBH><DDLSH>3302019999998682019112609102712218</DDLSH></FPXX>' # 待加密文本
# text2 = '<REQUEST_FPKJXX><FPKJXX_FPTXX><NSRSBH>330201999999868</NSRSBH><NSRMC>测试1</NSRMC><DDLSH>3302019999998684935</DDLSH><DDH></DDH><DDDATE>2018-07-20</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>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>'
print(jm_Aes(key, text1))
pass
str_Base64加密算法:
#coding:utf-8
import base64
#对输入的字符进行base64加密
def str_base64(code):
jm_one = base64.b64encode(code.encode('utf-8'))
jm_two = str(jm_one, 'utf-8')
return jm_two if __name__ == '__main__':
# reslut = str_base64('abcd1234')
# print(reslut)
pass
str_SHA1加密算法:
#coding:utf-8
from hashlib import sha1
import hmac
#对输入的字符进行Base64加密后,再进行hmac-sha1加密
def hash_hmac(key, code, sha1):
hmac_code = hmac.new(key.encode(), code.encode(), sha1)
return hmac_code.hexdigest() if __name__ == '__main__':
# reslut = hash_hmac('I7GBo4w9E6dmGlLVJMaVtXrhbNqp4KBh', 'YWJjZDEyMzQ=', sha1)
# print(reslut)
pass
Python_Urlencode算法:
#coding=utf-8
from urllib import parse def jm_urlencode(code):
s_encode = parse.quote(code, 'utf8')
return s_encode if __name__ == '__main__':
# url = 'hhCWnmDtU1NxQlXiE+LMiRozGLJpbu2P/2hraeHuWUQdSUtwMmwlRlPzIJqI+lbiXind8vWCsOlZenQgb7JNNIdjqpEZK3gGQguik3hddTDMYL2GZ6NlNH4SL+NWXTVb'
# print(jm_urlencode(url))
pass
api_DZFPKJ & api_DZFPCX的更多相关文章
- api_DZFPKJ & api_DZFPCX(get_AES_url代码优化)
通过AES加密网站的接口来传值,不需要手动加密字符串后复制过来传值. #coding:utf-8 import requests import re def get_aes_url(key, text ...
随机推荐
- 动态网站项目(Dynamic Web Project)登录功能的实现(mvc(五层架构)+jdbc+servlet+tomcat7.0+jdk1.8)(js验证+cookie)
1.index.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" p ...
- java基于Hash表和双向链表简单实现LRU Cache
package lru; import java.util.HashMap; public class LRUCache2<K,V> { public final int capacity ...
- selenium 使用教程详解-java版本
第一章 Selenium 概述 1.1.Selenium 发展史 Selenium是一系列基于Web的自动化工具,提供一套测试函数,用于支持Web自动化测试.函数非常灵活,能够完成界面元素定位.窗 ...
- tcp/ip面试题
TCP协议 1.OSI与TCP/IP各层的结构和功能,协议和作用. OSI七层模型对应TCP/IP四层模型,只是分法不同而已. 应用层:提供应用层服务,文件传输(FTP),电子邮件( ...
- UVA - 548 根据中序遍历和后序遍历建二叉树(关于三种遍历二叉树)
题意: 同时给两个序列,分别是二叉树的中序遍历和后序遍历,求出根节点到叶子结点路径上的权值最小和 的那个 叶子节点的值,若有多个最小权值,则输出最小叶子结点的和. 想法: 一开始想着建树,但是没有这样 ...
- coding++:js实现基于Base64的编码及解码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- python—os模块
os模块(操作目录) 1 import os 2 os.rename('旧','新') #修改文件名 3 os.remove('') #删除文件 4 print(os.listdir('.')) # ...
- 面试:给我说说你平时是如何优化MySQL的?
面试:给我说说你平时是如何优化MySQL的? 1.explain 在MySQL优化的时候.我们使用最多的是explain查看 SQL 的执行计划 类型 解释 type 连接类型.一个好的SQL语句至少 ...
- ScheduledThreadPoolExecutor之remove方法
之前用定时任务的线程池,设置了个任务,但是突然今天产品说,某些个操作需要中断某些任务(如果任务还没有执行),使其不能再到点执行了.于是查了API果然有这样一个方法. 一看API,需要移除的是一个Run ...
- 001_创建一个sidebar切换页面
Table Of Content 准备 基本思路 实现 我们期望实现这样的效果: ![](https://img2018.cnblogs.com/blog/1735896/202001/1735896 ...