通过AES加密网站的接口来传值,不需要手动加密字符串后复制过来传值。
1 #coding:utf-8 2 import requests 3 import re 4 def get_aes_url(key, text): 5 url = 'http://www.ssleye.com/des/web_aes_encrypt' 6 header = { 7 "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" 8 } 9 payload = { 10 "text": text, 11 "encode_flag": "utf8", 12 "key": key, 13 "iv": "", 14 "mode": "ECB", 15 "padding": "pkcs5", 16 "out_mode": "base64" 17 } 18 r = requests.post(url=url, headers=header, data=payload) 19 result = r.text 20 aa = re.findall("<pre>(.+?)</pre>", result) 21 bb = str(aa[0]) 22 return bb 23 24 if __name__ == '__main__': 25 # key = 'WuMlCJRN8zO886dw' 26 # 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>' 27 # aa = get_aes_url(key, text) 28 # print(aa) 29 # print(type(aa)) 30 pass
api_DZFPKJ 代码如下:
1 #coding:utf-8 2 from get_AES_url import get_aes_url 3 from get_urlencode import jm_urlencode 4 from get_Base64 import str_base64 5 from get_Sha1 import hash_hmac 6 from hashlib import sha1 7 import requests 8 import time 9 #定义参数 10 host = "http://test2.51fapiaonb.cn:4011/DZFP_Four" 11 data_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())) 12 nsrsbh = "330201999999868" #这里填需要查询的纳税人识别号 13 DDLSH_str1 = "3302019999998" 14 DDLSH_str2 = "684229" 15 DDLSH = DDLSH_str1 + DDLSH_str2 16 ddh = "" 17 date = "2018-07-20" 18 KPLX = "1" #1 蓝票 2 红票 19 YFP_DM = "" 20 YFP_HM = "" 21 SGBZ = "" #传空 22 YHZCBS = "0" #优惠标识 23 LSLBS = "3" #0税率标志 24 ZZSTSGL = "" #内容 25 SPBM = "20300000" #免税 4030000000000000000 不征收 6010000000000000000 26 #所有商品行数据 27 KPHJJE = "0.1" 28 HJBHSJE = "0.1" 29 HJSE = "0" 30 #单个商品行数据 31 XMJE = "0.1" 32 SL = "0" 33 SE = "0" 34 #发票开具信息 35 mxs = "<FPKJXX_XMXX>" + 36 "<XMMC><![CDATA[1]]></XMMC>" + 37 "<XMDW></XMDW>" + 38 "<GGXH></GGXH>" + 39 "<XMSL>0</XMSL>" + 40 "<HSBZ>0</HSBZ>" + 41 "<XMDJ>0</XMDJ>" + 42 "<FPHXZ>0</FPHXZ>" + 43 "<SPBM>" + SPBM + "</SPBM>" + 44 "<ZXBM></ZXBM>" + 45 "<YHZCBS>" + YHZCBS + "</YHZCBS>" + 46 "<LSLBS>" + LSLBS + "</LSLBS>" + 47 "<ZZSTSGL>" + ZZSTSGL + "</ZZSTSGL>" + 48 "<XMJE>" + XMJE + "</XMJE>" + 49 "<SL>" + SL + "</SL>" + 50 "<SE>" + SE + "</SE>" + 51 "<KCE></KCE>" + 52 "<KCQHSJE></KCQHSJE>" + 53 "</FPKJXX_XMXX>" 54 55 #电子发票外部API-DZFPKJ(电子发票开具) 56 original_content = "<REQUEST_FPKJXX>" + 57 "<FPKJXX_FPTXX>" + 58 "<NSRSBH>" + nsrsbh + "</NSRSBH>" + 59 "<NSRMC>航信培训企业</NSRMC>" + 60 "<DDLSH>" + DDLSH + "</DDLSH>" + 61 "<DDH>" + ddh + "</DDH>" + 62 "<DDDATE>" + date + "</DDDATE>" + 63 "<BMB_BBH>13.0</BMB_BBH>" + 64 "<XHF_DZ><![CDATA[宁波研发园]]></XHF_DZ>" + 65 "<XHF_DH><![CDATA[88776655]]></XHF_DH>" + 66 "<XHF_YHZH><![CDATA[中国银行6228480310540239016]]></XHF_YHZH>" + 67 "<GHFMC><![CDATA[Nobita]]></GHFMC>" + 68 "<GHF_NSRSBH><![CDATA[330203999999018]]></GHF_NSRSBH>" + 69 "<GHF_DZ><![CDATA[宁波研发园]]></GHF_DZ>" + 70 "<GHF_GDDH><![CDATA[55667788]]></GHF_GDDH>" + 71 "<GHF_SJ>13867866196</GHF_SJ>" + 72 "<GHF_EMAIL><![CDATA[364942727@qq.com]]></GHF_EMAIL>" + 73 "<GHF_YHZH><![CDATA[光大银行6228480310540239018]]></GHF_YHZH>" + 74 "<KPLY>999</KPLY>" + 75 "<KPY>Nobita</KPY>" + 76 "<SKY>Nobita</SKY>" + 77 "<FHR>Nobita</FHR>" + 78 "<KPLX>" + KPLX + "</KPLX>" + 79 "<YFP_DM>" + YFP_DM + "</YFP_DM>" + 80 "<YFP_HM>" + YFP_HM + "</YFP_HM>" + 81 "<KPHJJE>" + KPHJJE + "</KPHJJE>" + 82 "<HJBHSJE>" + HJBHSJE + "</HJBHSJE>" + 83 "<HJSE>" + HJSE + "</HJSE>" + 84 "<BZ><![CDATA[公共能耗费,面积]]></BZ>" + 85 "<BB></BB>" + 86 "<WB></WB>" + 87 "<FPZL></FPZL>" + 88 "<SGBZ>" + SGBZ + "</SGBZ>" + 89 "</FPKJXX_FPTXX>" + 90 "<FPKJXX_XMXXS>" + 91 mxs + 92 "</FPKJXX_XMXXS>" + 93 "</REQUEST_FPKJXX>" 94 #AES密钥 95 key = 'WuMlCJRN8zO886dw' 96 # print(original_content) 97 ''' AES加密算法的网站:http://www.ssleye.com/aes_cipher.html 98 AES加密(加解密算法/工作模式/填充方式:AES/ECB/PKCS5Padding;测试环境key值:WuMlCJRN8zO886dw 99 ''' 100 #初始数据original_content进行AES和Base64加密后,得到original_content_Aes 101 original_content_Aes_Base64 = get_aes_url(key, original_content) 102 103 #通用报文初始数据(DZFPCX发票查询) 104 original_data = '<?xml version="1.0" encoding="utf-8"?>' + 105 "<interface>" + 106 "<globalInfo>" + 107 "<version>4.0</version>" + 108 "<interfaceCode>DZFPKJ</interfaceCode>" + 109 "<token>{}</token>".format(nsrsbh) + 110 "<requestTime>{}</requestTime>".format(data_time) + 111 "</globalInfo>" + 112 "<Data>" + 113 "<content>{}</content>".format(original_content_Aes_Base64) + 114 "</Data>" + 115 "</interface>" 116 117 #通用报文原始数据original_data进行Base64加密后,得到RequestParam,再进行urlencode解码 118 RequestParam_Base64 = str_base64(original_data) 119 # print("通用报文进行Base64加密后: ", RequestParam_Base64) 120 RequestParam_Base64_Urlencode = jm_urlencode(RequestParam_Base64) 121 # print("通用报文进行Base64和Urlencode加密后: ", RequestParam_Base64_Urlencode) 122 123 #RequestParam通过HMAC-SHA1加密,得到Signature 124 Signature = hash_hmac('I7GBo4w9E6dmGlLVJMaVtXrhbNqp4KBh', RequestParam_Base64, sha1) 125 # print("通用报文进行Base64和Hash_hmac加密后: ", Signature) 126 127 #请求体data构建 128 RequestParam = RequestParam_Base64_Urlencode 129 data = "RequestParam=" + RequestParam + "&Signature=" + Signature 130 result = requests.post(url=host, params=data) 131 # print(result.url) 132 print('订单流水号为: {}'.format(DDLSH)) 133 print('发票查询返回报文为: {}'.format(result.text))
api_DZFPKJ_QDFP 代码如下:
1 #coding:utf-8 2 from get_AES_url import get_aes_url 3 from get_urlencode import jm_urlencode 4 from get_Base64 import str_base64 5 from get_Sha1 import hash_hmac 6 from hashlib import sha1 7 import requests 8 import time 9 #定义参数 10 host = "http://test2.51fapiaonb.cn:4011/DZFP_Four" 11 data_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())) 12 nsrsbh = "330201999999868" #这里填需要查询的纳税人识别号 13 DDLSH_str1 = "3302019999998" 14 DDLSH_str2 = "684229" 15 DDLSH = DDLSH_str1 + DDLSH_str2 16 ddh = "" 17 date = "2018-07-20" 18 KPLX = "1" #1 蓝票 2 红票 19 YFP_DM = "" 20 YFP_HM = "" 21 SGBZ = "" #传空 22 YHZCBS = "0" #优惠标识 23 LSLBS = "3" #0税率标志 24 ZZSTSGL = "" #内容 25 SPBM = "20300000" #免税 4030000000000000000 不征收 6010000000000000000 26 #所有商品行数据 27 KPHJJE = "1.0" 28 HJBHSJE = "1.0" 29 HJSE = "0" 30 #单个商品行数据 31 XMJE = "0.1" 32 SL = "0" 33 SE = "0" 34 #发票开具信息 35 mxs = "<FPKJXX_XMXX>" + 36 "<XMMC><![CDATA[1]]></XMMC>" + 37 "<XMDW></XMDW>" + 38 "<GGXH></GGXH>" + 39 "<XMSL>0</XMSL>" + 40 "<HSBZ>0</HSBZ>" + 41 "<XMDJ>0</XMDJ>" + 42 "<FPHXZ>0</FPHXZ>" + 43 "<SPBM>20300000</SPBM>" + 44 "<ZXBM></ZXBM>" + 45 "<YHZCBS>0</YHZCBS>" + 46 "<LSLBS>3</LSLBS>" + 47 "<ZZSTSGL></ZZSTSGL>" + 48 "<XMJE>0.1</XMJE>" + 49 "<SL>0</SL>" + 50 "<SE>0</SE>" + 51 "<KCE></KCE>" + 52 "<KCQHSJE></KCQHSJE>" + 53 "</FPKJXX_XMXX>" + 54 "<FPKJXX_XMXX>" + 55 "<XMMC><![CDATA[1]]></XMMC>" + 56 "<XMDW></XMDW>" + 57 "<GGXH></GGXH>" + 58 "<XMSL>0</XMSL>" + 59 "<HSBZ>0</HSBZ>" + 60 "<XMDJ>0</XMDJ>" + 61 "<FPHXZ>0</FPHXZ>" + 62 "<SPBM>20300000</SPBM>" + 63 "<ZXBM></ZXBM>" + 64 "<YHZCBS>0</YHZCBS>" + 65 "<LSLBS>3</LSLBS>" + 66 "<ZZSTSGL></ZZSTSGL>" + 67 "<XMJE>0.1</XMJE>" + 68 "<SL>0</SL>" + 69 "<SE>0</SE>" + 70 "<KCE></KCE>" + 71 "<KCQHSJE></KCQHSJE>" + 72 "</FPKJXX_XMXX>" + 73 "<FPKJXX_XMXX>" + 74 "<XMMC><![CDATA[1]]></XMMC>" + 75 "<XMDW></XMDW>" + 76 "<GGXH></GGXH>" + 77 "<XMSL>0</XMSL>" + 78 "<HSBZ>0</HSBZ>" + 79 "<XMDJ>0</XMDJ>" + 80 "<FPHXZ>0</FPHXZ>" + 81 "<SPBM>20300000</SPBM>" + 82 "<ZXBM></ZXBM>" + 83 "<YHZCBS>0</YHZCBS>" + 84 "<LSLBS>3</LSLBS>" + 85 "<ZZSTSGL></ZZSTSGL>" + 86 "<XMJE>0.1</XMJE>" + 87 "<SL>0</SL>" + 88 "<SE>0</SE>" + 89 "<KCE></KCE>" + 90 "<KCQHSJE></KCQHSJE>" + 91 "</FPKJXX_XMXX>" + 92 "<FPKJXX_XMXX>" + 93 "<XMMC><![CDATA[1]]></XMMC>" + 94 "<XMDW></XMDW>" + 95 "<GGXH></GGXH>" + 96 "<XMSL>0</XMSL>" + 97 "<HSBZ>0</HSBZ>" + 98 "<XMDJ>0</XMDJ>" + 99 "<FPHXZ>0</FPHXZ>" + 100 "<SPBM>20300000</SPBM>" + 101 "<ZXBM></ZXBM>" + 102 "<YHZCBS>0</YHZCBS>" + 103 "<LSLBS>3</LSLBS>" + 104 "<ZZSTSGL></ZZSTSGL>" + 105 "<XMJE>0.1</XMJE>" + 106 "<SL>0</SL>" + 107 "<SE>0</SE>" + 108 "<KCE></KCE>" + 109 "<KCQHSJE></KCQHSJE>" + 110 "</FPKJXX_XMXX>" + 111 "<FPKJXX_XMXX>" + 112 "<XMMC><![CDATA[1]]></XMMC>" + 113 "<XMDW></XMDW>" + 114 "<GGXH></GGXH>" + 115 "<XMSL>0</XMSL>" + 116 "<HSBZ>0</HSBZ>" + 117 "<XMDJ>0</XMDJ>" + 118 "<FPHXZ>0</FPHXZ>" + 119 "<SPBM>20300000</SPBM>" + 120 "<ZXBM></ZXBM>" + 121 "<YHZCBS>0</YHZCBS>" + 122 "<LSLBS>3</LSLBS>" + 123 "<ZZSTSGL></ZZSTSGL>" + 124 "<XMJE>0.1</XMJE>" + 125 "<SL>0</SL>" + 126 "<SE>0</SE>" + 127 "<KCE></KCE>" + 128 "<KCQHSJE></KCQHSJE>" + 129 "</FPKJXX_XMXX>" + 130 "<FPKJXX_XMXX>" + 131 "<XMMC><![CDATA[1]]></XMMC>" + 132 "<XMDW></XMDW>" + 133 "<GGXH></GGXH>" + 134 "<XMSL>0</XMSL>" + 135 "<HSBZ>0</HSBZ>" + 136 "<XMDJ>0</XMDJ>" + 137 "<FPHXZ>0</FPHXZ>" + 138 "<SPBM>20300000</SPBM>" + 139 "<ZXBM></ZXBM>" + 140 "<YHZCBS>0</YHZCBS>" + 141 "<LSLBS>3</LSLBS>" + 142 "<ZZSTSGL></ZZSTSGL>" + 143 "<XMJE>0.1</XMJE>" + 144 "<SL>0</SL>" + 145 "<SE>0</SE>" + 146 "<KCE></KCE>" + 147 "<KCQHSJE></KCQHSJE>" + 148 "</FPKJXX_XMXX>" + 149 "<FPKJXX_XMXX>" + 150 "<XMMC><![CDATA[1]]></XMMC>" + 151 "<XMDW></XMDW>" + 152 "<GGXH></GGXH>" + 153 "<XMSL>0</XMSL>" + 154 "<HSBZ>0</HSBZ>" + 155 "<XMDJ>0</XMDJ>" + 156 "<FPHXZ>0</FPHXZ>" + 157 "<SPBM>20300000</SPBM>" + 158 "<ZXBM></ZXBM>" + 159 "<YHZCBS>0</YHZCBS>" + 160 "<LSLBS>3</LSLBS>" + 161 "<ZZSTSGL></ZZSTSGL>" + 162 "<XMJE>0.1</XMJE>" + 163 "<SL>0</SL>" + 164 "<SE>0</SE>" + 165 "<KCE></KCE>" + 166 "<KCQHSJE></KCQHSJE>" + 167 "</FPKJXX_XMXX>" + 168 "<FPKJXX_XMXX>" + 169 "<XMMC><![CDATA[1]]></XMMC>" + 170 "<XMDW></XMDW>" + 171 "<GGXH></GGXH>" + 172 "<XMSL>0</XMSL>" + 173 "<HSBZ>0</HSBZ>" + 174 "<XMDJ>0</XMDJ>" + 175 "<FPHXZ>0</FPHXZ>" + 176 "<SPBM>20300000</SPBM>" + 177 "<ZXBM></ZXBM>" + 178 "<YHZCBS>0</YHZCBS>" + 179 "<LSLBS>3</LSLBS>" + 180 "<ZZSTSGL></ZZSTSGL>" + 181 "<XMJE>0.1</XMJE>" + 182 "<SL>0</SL>" + 183 "<SE>0</SE>" + 184 "<KCE></KCE>" + 185 "<KCQHSJE></KCQHSJE>" + 186 "</FPKJXX_XMXX>" + 187 "<FPKJXX_XMXX>" + 188 "<XMMC><![CDATA[1]]></XMMC>" + 189 "<XMDW></XMDW>" + 190 "<GGXH></GGXH>" + 191 "<XMSL>0</XMSL>" + 192 "<HSBZ>0</HSBZ>" + 193 "<XMDJ>0</XMDJ>" + 194 "<FPHXZ>0</FPHXZ>" + 195 "<SPBM>20300000</SPBM>" + 196 "<ZXBM></ZXBM>" + 197 "<YHZCBS>0</YHZCBS>" + 198 "<LSLBS>3</LSLBS>" + 199 "<ZZSTSGL></ZZSTSGL>" + 200 "<XMJE>0.1</XMJE>" + 201 "<SL>0</SL>" + 202 "<SE>0</SE>" + 203 "<KCE></KCE>" + 204 "<KCQHSJE></KCQHSJE>" + 205 "</FPKJXX_XMXX>" + 206 "<FPKJXX_XMXX>" + 207 "<XMMC><![CDATA[1]]></XMMC>" + 208 "<XMDW></XMDW>" + 209 "<GGXH></GGXH>" + 210 "<XMSL>0</XMSL>" + 211 "<HSBZ>0</HSBZ>" + 212 "<XMDJ>0</XMDJ>" + 213 "<FPHXZ>0</FPHXZ>" + 214 "<SPBM>20300000</SPBM>" + 215 "<ZXBM></ZXBM>" + 216 "<YHZCBS>0</YHZCBS>" + 217 "<LSLBS>3</LSLBS>" + 218 "<ZZSTSGL></ZZSTSGL>" + 219 "<XMJE>0.1</XMJE>" + 220 "<SL>0</SL>" + 221 "<SE>0</SE>" + 222 "<KCE></KCE>" + 223 "<KCQHSJE></KCQHSJE>" + 224 "</FPKJXX_XMXX>" 225 226 #电子发票外部API-DZFPKJ(电子发票开具) 227 original_content = "<REQUEST_FPKJXX>" + 228 "<FPKJXX_FPTXX>" + 229 "<NSRSBH>" + nsrsbh + "</NSRSBH>" + 230 "<NSRMC>航信培训企业</NSRMC>" + 231 "<DDLSH>" + DDLSH + "</DDLSH>" + 232 "<DDH>" + ddh + "</DDH>" + 233 "<DDDATE>" + date + "</DDDATE>" + 234 "<BMB_BBH>13.0</BMB_BBH>" + 235 "<XHF_DZ><![CDATA[222]]></XHF_DZ>" + 236 "<XHF_DH><![CDATA[222]]></XHF_DH>" + 237 "<XHF_YHZH><![CDATA[222]]></XHF_YHZH>" + 238 "<GHFMC><![CDATA[22 2]]></GHFMC>" + 239 "<GHF_NSRSBH><![CDATA[330203999999018]]></GHF_NSRSBH>" + 240 "<GHF_DZ><![CDATA[地址]]></GHF_DZ>" + 241 "<GHF_GDDH><![CDATA[电话]]></GHF_GDDH>" + 242 "<GHF_SJ>17871838087</GHF_SJ>" + 243 "<GHF_EMAIL><![CDATA[zxy@ms.whb.ac.cn]]></GHF_EMAIL>" + 244 "<GHF_YHZH><![CDATA[yhzh]]></GHF_YHZH>" + 245 "<KPLY>999</KPLY>" + 246 "<KPY>综合服务公共能耗</KPY>" + 247 "<SKY>日常维修综合服务</SKY>" + 248 "<FHR>车位管理综合面积</FHR>" + 249 "<KPLX>" + KPLX + "</KPLX>" + 250 "<YFP_DM>" + YFP_DM + "</YFP_DM>" + 251 "<YFP_HM>" + YFP_HM + "</YFP_HM>" + 252 "<KPHJJE>" + KPHJJE + "</KPHJJE>" + 253 "<HJBHSJE>" + HJBHSJE + "</HJBHSJE>" + 254 "<HJSE>" + HJSE + "</HJSE>" + 255 "<BZ><![CDATA[公共能耗费,面积]]></BZ>" + 256 "<BB></BB>" + 257 "<WB></WB>" + 258 "<FPZL></FPZL>" + 259 "<SGBZ>" + SGBZ + "</SGBZ>" + 260 "</FPKJXX_FPTXX>" + 261 "<FPKJXX_XMXXS>" + 262 mxs + 263 "</FPKJXX_XMXXS>" + 264 "</REQUEST_FPKJXX>" 265 #AES密钥 266 key = 'WuMlCJRN8zO886dw' 267 # print(original_content) 268 ''' AES加密算法的网站:http://www.ssleye.com/aes_cipher.html 269 AES加密(加解密算法/工作模式/填充方式:AES/ECB/PKCS5Padding;测试环境key值:WuMlCJRN8zO886dw 270 ''' 271 #初始数据original_content进行AES和Base64加密后,得到original_content_Aes 272 original_content_Aes_Base64 = get_aes_url(key, original_content) 273 274 #通用报文初始数据(DZFPCX发票查询) 275 original_data = '<?xml version="1.0" encoding="utf-8"?>' + 276 "<interface>" + 277 "<globalInfo>" + 278 "<version>4.0</version>" + 279 "<interfaceCode>DZFPKJ</interfaceCode>" + 280 "<token>{}</token>".format(nsrsbh) + 281 "<requestTime>{}</requestTime>".format(data_time) + 282 "</globalInfo>" + 283 "<Data>" + 284 "<content>{}</content>".format(original_content_Aes_Base64) + 285 "</Data>" + 286 "</interface>" 287 288 #通用报文原始数据original_data进行Base64加密后,得到RequestParam,再进行urlencode解码 289 RequestParam_Base64 = str_base64(original_data) 290 # print("通用报文进行Base64加密后: ", RequestParam_Base64) 291 RequestParam_Base64_Urlencode = jm_urlencode(RequestParam_Base64) 292 # print("通用报文进行Base64和Urlencode加密后: ", RequestParam_Base64_Urlencode) 293 294 #RequestParam通过HMAC-SHA1加密,得到Signature 295 Signature = hash_hmac('I7GBo4w9E6dmGlLVJMaVtXrhbNqp4KBh', RequestParam_Base64, sha1) 296 # print("通用报文进行Base64和Hash_hmac加密后: ", Signature) 297 298 #请求体data构建 299 RequestParam = RequestParam_Base64_Urlencode 300 data = "RequestParam=" + RequestParam + "&Signature=" + Signature 301 result = requests.post(url=host, params=data) 302 # print(result.url) 303 print('发票查询ddlsh为: {}'.format(DDLSH)) 304 print('发票查询返回报文为: {}'.format(result.text))
api_DZFPCX 代码如下:
1 #coding:utf-8 2 from get_AES_url import get_aes_url 3 from get_urlencode import jm_urlencode 4 from get_Base64 import str_base64 5 from get_Sha1 import hash_hmac 6 from hashlib import sha1 7 import requests 8 import time 9 #定义参数 10 host = "http://test2.51fapiaonb.cn:4011/DZFP_Four" 11 data_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())) 12 nsrsbh = "330201999999868" #这里填需要查询的纳税人识别号 13 # #电子发票外部API-DZFPCX(电子发票查询) 14 ddlsh = "3302019999998684229" #这里填写发票对应的订单流水号 15 original_content = "<FPXX>" + 16 "<NSRSBH>{}</NSRSBH>".format(nsrsbh) + 17 "<DDLSH>{}</DDLSH>".format(ddlsh) + "</FPXX>" 18 19 #AES密钥 20 key = 'WuMlCJRN8zO886dw' 21 #初始数据original_content进行AES和Base64加密后,得到original_content_Aes_Base64 22 original_content_Aes_Base64 = get_aes_url(key, original_content) 23 # print("content进行AES和Base64加密后: ", original_content_Aes_Base64) 24 25 # #通用报文初始数据(DZFPCX发票查询) 26 original_data = '<?xml version="1.0" encoding="utf-8"?>' + 27 "<interface>" + 28 "<globalInfo>" + 29 "<version>4.1</version>" + 30 "<interfaceCode>DZFPCX</interfaceCode>" + 31 "<token>" + nsrsbh + "</token>" + 32 "<requestTime>" + data_time + "</requestTime>" + 33 "</globalInfo>" + 34 "<Data>" + 35 "<content>" + original_content_Aes_Base64 + "</content>" + 36 "</Data>" + 37 "</interface>" 38 39 #通用报文原始数据original_data进行Base64加密后,得到RequestParam,再进行urlencode解码 40 RequestParam_Base64 = str_base64(original_data) 41 # print("通用报文进行Base64加密后: ", RequestParam_Base64) 42 RequestParam_Base64_Urlencode = jm_urlencode(RequestParam_Base64) 43 # print("通用报文进行Base64和Urlencode加密后: ", RequestParam_Base64_Urlencode) 44 45 #RequestParam通过HMAC-SHA1加密,得到Signature 46 Signature = hash_hmac('I7GBo4w9E6dmGlLVJMaVtXrhbNqp4KBh', RequestParam_Base64, sha1) 47 # print("通用报文进行Base64和Hash_hmac加密后: ", Signature) 48 49 #请求体data构建 50 RequestParam = RequestParam_Base64_Urlencode 51 # url = host + "?RequestParam=" + RequestParam + "&Signature=" + Signature 52 data = "RequestParam=" + RequestParam + "&Signature=" + Signature 53 result = requests.post(url=host, params=data) 54 # print(result.url) #打印请求url 55 # print(RequestParam) 56 # print(Signature) 57 print('发票查询返回报文为: {}'.format(result.text))