• python 工行 api 查询


    最近学习python 又在做接口 于是找了N多资料 终于实现了 下面是代码

    # -*- coding:gbk -*- 
    import httplib 
    import cookielib
    import urllib2
    import urllib

    # 用chilkat拆分pfx得到key,cert的pem格式
    key_file = 'chilkat_pkey.pem'
    cert_file 
    = 'chilkat_cert.pem'

    class HTTPSClientAuthConnection(httplib.HTTPSConnection):
        
    def __init__(self, host, timeout=None):
            httplib.HTTPSConnection.
    __init__(self, host, key_file=key_file,cert_file=cert_file)
            self.timeout 
    = timeout # Only valid in Python 2.6

    class HTTPSClientAuthHandler(urllib2.HTTPSHandler):
        
    def https_open(self, req):
            
    return self.do_open(HTTPSClientAuthConnection, req)

    class ICBCAPI(object):
        
    def __init__(self):
            self._cookiejar 
    = cookielib.CookieJar()

        
    def get(self, url, **data):
            parameters 
    = urllib.urlencode(data)
            opener 
    = urllib2.build_opener(urllib2.HTTPHandler(), HTTPSClientAuthHandler(), urllib2.HTTPCookieProcessor(self._cookiejar))
            req 
    = urllib2.Request(url, parameters)
            server_response 
    = opener.open(req).read()
            
    return urllib2.unquote(server_response)

    def test():
        api 
    = ICBCAPI()
        apiUrl 
    = "https://corporbank3.dccnet.com.cn/servlet/ICBCINBSEBusinessServlet"
        merReqData = '''
        <?xml version="1.0" encoding="GBK\" standalone="no" ?>
        <ICBCAPI>
            <in>
                <orderNum>填你们自己的</orderNum>
                <tranDate>填你们自己的</tranDate>
                <ShopCode>填你们自己的</ShopCode>
                <ShopAccount>填你们自己的</ShopAccount>
            </in>
        </ICBCAPI>
    '''
        
    print api.get(apiUrl,APIName='EAPI',APIVersion='001.001.002.001',MerReqData=merReqData)
        
    if __name__ == '__main__':

        test() 

    希望对你们有帮助
  • 相关阅读:
    四层和七层负载均衡的区别-转
    MySQL高可用方案一(MHA)
    EC2.0开启多规格后,编辑无法获取规格数据
    PHP中取出字符串中的空格 逗号
    ECSTORE1.2 重启开启信任登陆模块(删除KEY)
    云体检通用代码补丁
    zendguard安装破解
    MySQL历史版本下载(官方)
    linux watch命令
    python判断值是否为空
  • 原文地址:https://www.cnblogs.com/Death/p/1994069.html
Copyright © 2020-2023  润新知