python 使用联动优势支付接口的sign与verify

直接上代码

if options.umpay_private_key is not None and len(options.umpay_private_key) > 0:
    try:
        with open(options.umpay_private_key) as keyfile:
            keydata = keyfile.read()
        rsakey = RSA.importKey(keydata)
        _umpay_signer = PKCS1_v1_5.new(rsakey)
        #测试代码
        #digest = SHA.new()
        #sign_data ="amount=1&amt_type=RMB&charset=UTF-8&expire_time=30&goods_inf=充值支付房租&mer_date=20131009&mer_id=6379&notify_url=http://wap.zufangbao.cn/netpay/ldpaycallback.htm&order_id=111784&ret_url=http://wap.zufangbao.cn/netpay/ldpayreceive.htm&service=pay_req&version=4.0"
        #digest.update(sign_data.encode("gbk"))
        #sign = _umpay_signer.sign(digest)
        #ret = base64.b64encode(sign)
        #print ret
    except:
        log.fatal("load umpay private key failed. %s" % str(sys.exc_info()))

_umpay_verifier = None #联动优势验证器
if options.umpay_public_key is not None and len(options.umpay_public_key) > 0:
    try:
        with open(options.umpay_public_key) as keyfile:
            keydata = keyfile.read()
        from Crypto.Util.asn1 import DerSequence
        cert = DerSequence()
        cert.decode(keydata)
        tbsCertificate = DerSequence()
        tbsCertificate.decode(cert[0])
        subjectPublicKeyInfo = tbsCertificate[6]
        # Initialize RSA key
        rsakey = RSA.importKey(subjectPublicKeyInfo)
        _umpay_verifier = PKCS1_v1_5.new(rsakey)
        #测试代码
        #digest = SHA.new()
        #sign = "nyTGvSfe8AaBj2WHs4vYhr32bBvMS1UdXuSjWwmvqy4GYgpfNuKlkiadsOhxSGv6SzLfPNp+uYHQnWIvcRe8cofzPiaYHgXQn8r/hxljeCq3/L9VHAASMJOjRvHoVDNh1QbuJbWoB1wx+e+2NC4ub1RbEaJbutvHfokUIZxaEzg="
        #sign_decode = base64.b64decode(sign)
        #verify_data = "mer_date=20131009&mer_id=6379&order_id=111790&ret_code=0000&ret_msg=交易成功&token=125880604943823&trade_no=1310091656145373&trade_state=WAIT_BUYER_PAY&version=4.0"
        #digest.update(verify_data.encode("gbk"))
        #ret = _umpay_verifier.verify(digest, sign_decode)
        #print ret
    except:
        print str(sys.exc_info())
        log.fatal("load umpay public key failed. %s" % str(sys.exc_info()))
上一篇:【kate总结】Matlab坐标轴问题


下一篇:我的第一个python web开发框架(18)——前台页面与接口整合