支付宝app支付转h5python代码

某平台app订单提交支付可获取支付参数跳转支付宝,但只拼接里面参数不能够在web中打开支付链接。

通过抓包发现数据包中将alipay_sdk参数访问阿里接口  加密生成了mclient域名的支付连接,可在 浏览器打开此链接,从而实现支付宝app支付转换到h5来支付。

from flask import Flask, request, jsonify
import json
import requests
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5
import base64
from Crypto.Cipher import DES3
from Crypto.Util.Padding import pad, unpad
class AiliPay(object):
    def __init__(self):
        self.private_key = '''
            ###################################################
            '''
        self.public_key = '''
            ########################################'''
        self.key = '########'

    def encrypt_3des(self,data):
        cipher = DES3.new(self.key.encode(), DES3.MODE_ECB)
        padded_data = pad(data.encode(), DES3.block_size)
        encrypted_data = cipher.encrypt(padded_data)
        return encrypted_data

    def decrypt_3des(self,data):
        ct_bytes = base64.b64decode(data)
        cipher = DES3.new(self.key.encode(), DES3.MODE_ECB)
        plain_text = unpad(cipher.decrypt(ct_bytes), DES3.block_size)
        return plain_text.decode()

    def rsa_encrypt(self, message):
        cipher = Cipher_pkcs1_v1_5.new(RSA.importKey(self.public_key))
        cipher_text = base64.b64encode(cipher.encrypt(message.encode())).decode()
        return cipher_text

    def rsa_decrypt(self, text):
        cipher = Cipher_pkcs1_v1_5.new(RSA.importKey(self.private_key))
        retval = cipher.decrypt(base64.b64decode(text), 'ERROR').decode('utf-8')
        return retval

    def convert_alipay_to_h5(self,alipay_sdk):
        json_form = '{"tid":"######","user_agent":"Msp/9.1.5 (Android 12;Linux 4.4.146;zh_CN;http;540*960;21.0;WIFI;8#####;######################fruicqrn;r2agza5c56pzmev;<unknown ssid>;02:00:00:00:00:00)","has_alipay":false,"has_msp_app":false,"external_info":"' + alipay_sdk + '","app_key":"########","utdid":"########","new_client_key":"#####","action":{"type":"cashier","method":"main"},"gzip":true}'
        encrypted_data = base64.b64encode(self.encrypt_3des(json_form)).decode()
        req_data = parameter1 + parameter3 + encrypted_data
        url = 'http://mcgw.alipay.com/gateway.do'
        data = {"data": {"device": "GOOGLE", "namespace": "com.alipay.mobilecashier", "api_name": "com.alipay.mcpay",
                         "api_version": "4.0.2", "params": {"req_data": req_data}}}

        headers = {
            'Accept-Charset': 'UTF-8',
            'Connection': 'Keep-Alive',
            'Content-Type': 'application/octet-stream;binary/octet-stream',
            'Host': 'mcgw.alipay.com',
            'User-Agent': 'msp'
        }
        response = requests.post(url, headers=headers, json=data, verify=False)
        json_data = json.loads(response.text)
        res_data = self.rsa_encrypt(json_data['data']['params']['res_data'])
        json_data = json.loads(res_data)

if __name__ == '__main__':
    pay = AiliPay()
    pay.convert_alipay_to_h5("alipay_sdk=alipay-easysdk-java&app_id=#############")

  • 6
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个使用Java语言实现支付宝H5支付的示例代码: ```java import com.alipay.api.AlipayApiException; import com.alipay.api.AlipayClient; import com.alipay.api.DefaultAlipayClient; import com.alipay.api.request.AlipayTradeWapPayRequest; import com.alipay.api.response.AlipayTradeWapPayResponse; public class AlipayH5Payment { public static void main(String[] args) { // 在支付宝开发者平台申请得到的应用ID和私钥 String appId = "your_app_id"; String privateKey = "your_private_key"; // 支付宝公钥 String alipayPublicKey = "alipay_public_key"; // 实例化AlipayClient AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", appId, privateKey, "json", "UTF-8", alipayPublicKey, "RSA2"); // 创建AlipayTradeWapPayRequest对象 AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); // 设置支付宝回调URL request.setNotifyUrl("your_notify_url"); // 设置订单号和金额等支付参数 request.setBizContent("{" + "\"out_trade_no\":\"your_order_no\"," + "\"total_amount\":\"your_total_amount\"," + "\"subject\":\"your_order_subject\"," + "\"product_code\":\"QUICK_WAP_PAY\"" + "}"); try { // 发起支付请求,并获取返回结果 AlipayTradeWapPayResponse response = alipayClient.pageExecute(request); // 判断支付请求是否成功 if (response.isSuccess()) { System.out.println("支付请求成功,生成的支付链接:" + response.getBody()); } else { System.out.println("支付请求失败:" + response.getMsg()); } } catch (AlipayApiException e) { e.printStackTrace(); } } } ``` 请注意,上述代码仅为示例,实际使用时需要替换为您自己的应用ID、私钥、支付宝公钥、回调URL、订单号、金额和订单主题等参数。同时,确保已导入支付宝SDK相关的依赖包。另外,对于回调URL,您需要在您的服务器上配置接收支付结果通知的接口,并进行相应的处理。 建议您参考支付宝开发文档和SDK文档,以获取更详细的指导和代码示例。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值