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() 

希望对你们有帮助

转载于:https://www.cnblogs.com/Death/archive/2011/03/24/1994069.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值