Пример #1
0
def alipay():
    # for alipay
    key = load_privatekey(FILETYPE_PEM, open("./External/alipay/rsa_private_key.pem").read())

    # 默认是返回已存在的charge对象;若需要新生成charge,写为: DataGen.GetCharge(channel, True)
    scharge = datagen.create_charge(True,'alipay')
    charge_id = scharge['id']
    content, sign_str = Notify.alipay(scharge)

    sign_charge = sign(key, sign_str, 'sha1')

    ############### verify the signature to ensure the pair without any issues###########

    # pem = open("External/alipay/rsa_public_key.pem").read()
    #
    # bio = BIO.MemoryBuffer(pem)
    # rsa = RSA.load_pub_key_bio(bio)
    # pubkey = EVP.PKey()
    # pubkey.assign_rsa(rsa)
    #
    # pubkey.reset_context(md='sha1')
    # pubkey.verify_init()
    # pubkey.verify_update(sign_str)
    # print pubkey.verify_final(sign_charge)

    #########################################################################################

    sign_final = base64.b64encode(sign_charge)
    content['sign_type'] = "RSA"
    content['sign'] = sign_final
    content_final = {k: v.encode('utf-8') for k, v in content.items()}
    print content_final
    result = Notify.send("true",charge_id, content_final)
    if result == 'success':
        print 'The paid status of alipay charge {0} had updated successfully'.format(charge_id)
        return charge_id,"success"
    else:
        print 'Failed during update the paid status of alipay charge {0} '.format(charge_id)
        return charge_id,"Fail"