• paypal充值加密代码


    借助第三方库m2crypto,在linux下安装使用sudo apt-get install m2crypto即可。

    实现方法:

    paypal代码
    from M2Crypto import BIO, SMIME, X509
    #from django.conf import settings

    #DKY7UM4QRRD5Y
    #
    seller_1301033066_per@163.com

    def paypal_encrypt(attributes):

    plaintext
    = ''

    for key, value in attributes.items():
    plaintext
    += u'%s=%s\n' % (key, value)

    plaintext
    = plaintext.encode('utf-8')

    # Instantiate an SMIME object.
    s = SMIME.SMIME()

    # Load signer's key and cert. Sign the buffer.
    #
    s.load_key_bio(BIO.openfile(settings.MY_KEYPAIR), BIO.openfile(settings.MY_CERT))

    s.load_key_bio(BIO.openfile(
    "facebook-ppy-prvkey.pem"), BIO.openfile("facebook-ppy-pubcert.pem"))

    p7
    = s.sign(BIO.MemoryBuffer(plaintext), flags=SMIME.PKCS7_BINARY)

    # Load target cert to encrypt the signed message to.
    x509 = X509.load_cert_bio(BIO.openfile("paypal_cert_pem_mouren.txt"))
    sk
    = X509.X509_Stack()
    sk.push(x509)
    s.set_x509_stack(sk)

    # Set cipher: 3-key triple-DES in CBC mode.
    s.set_cipher(SMIME.Cipher('des_ede3_cbc'))

    # Create a temporary buffer.
    tmp = BIO.MemoryBuffer()

    # Write the signed message into the temporary buffer.
    p7.write_der(tmp)

    # Encrypt the temporary buffer.
    p7 = s.encrypt(tmp, flags=SMIME.PKCS7_BINARY)

    # Output p7 in mail-friendly format.
    out = BIO.MemoryBuffer()
    p7.write(out)

    return out.read()

    def pay(request, invoice_id):
    """This view displays an encrypted PayPal 'buy now' button"""

    # invoice = get_object_or_404(Invoice, id = 1)

    attributes
    = {}
    attributes[
    'cmd'] = '_xclick'
    attributes[
    'business'] = 'xxx.li@xxx.com'
    # attributes['item_name'] = invoice.item_name
    attributes['item_name'] = 'test'
    # attributes['amount'] = invoice.amount
    attributes['amount'] = 5
    attributes[
    'currency_code'] = 'GBP'
    attributes[
    'cert_id'] = 'DKY7UM4QRRD5Y'

    encrypted_block
    = paypal_encrypt(attributes)

    return render_to_response('pay.html', {'encrypted_block': encrypted_block})


    #<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
    #
    <input type="hidden" name="cmd" value="_s-xclick" />
    #
    <input type="hidden" name="encrypted" value="{{ encrypted_block }}" />
    #
    <input class="button pay" type="submit" name="submit" value="Pay Invoice" />
    #
    </form>

    if __name__ == "__main__":
    attributes
    = {}
    attributes[
    'cmd'] = '_xclick'
    attributes[
    'business'] = 'seller_1301033066_per@163.com'
    attributes[
    'item_name'] = 'test'
    attributes[
    'amount'] = 10
    attributes[
    'currency_code'] = 'USD'
    attributes[
    'cert_id'] = '494G534LA7XZA'

    encrypted_block
    = paypal_encrypt(attributes)
    print encrypted_block
    相关的PIN代码,网上很多,不赘述了。
  • 相关阅读:
    droid开发:如何打开一个.dcm文件作为位图?
    AndroidStudio3.0 Canary 8注解报错Annotation processors must be explicitly declared now.
    Android 异步加载神器Loader全解析
    Android实现RecyclerView的下拉刷新和上拉加载更多
    Android之ViewFlipper的简单使用
    云计算之路-阿里云上:2014年6月11日17点遇到的CPU 100%状况团队
    云计算之路-阿里云上:黑色1秒,微软的问题还是阿里云的问题?团队
    [网站公告]18:07-18:20阿里云SLB故障造成网站不能正常访问团队
    上周热点回顾(6.2-6.8)团队
    云计算之路-阿里云上:受够了OCS,改用ECS+Couchbase跑缓存团队
  • 原文地址:https://www.cnblogs.com/imouren/p/2024720.html
Copyright © 2020-2023  润新知