zoukankan      html  css  js  c++  java
  • 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() 

    希望对你们有帮助
  • 相关阅读:
    一道简单的递推题(快速幂+矩阵乘法优化+滚动数组)
    玲珑OJ 1129
    (转)Python函数式编程——map()、reduce()
    在windows中安装两个不同版本的Python
    Python 安装 pytesser 处理验证码出现的问题
    Python爬虫之HDU提交数据
    Python SGMLParser 的1个BUG??
    CF622F:The Sum of the k-th Powers
    LuoGuP3321:[SDOI2015]序列统计
    卡马克开方膜拜笔记
  • 原文地址:https://www.cnblogs.com/Death/p/1994069.html
Copyright © 2011-2022 走看看