VB6 simply implements Alipay QR code scanning horse payment

VB6 simply implements Alipay QR code scanning horse payment

Insert image description here
Insert image description here

The complete source code is as follows

Private Declare Function 初始化 Lib "alipay.dll" (ByVal 服务器 As String, ByVal 帐号 As String, ByVal 私钥 As String) As Boolean
Private Declare Function 支付 Lib "alipay.dll" (ByVal 订单号 As String, ByVal 金额 As String, ByVal 标题 As String, ByVal 返回信息 As String) As Boolean
Private Declare Function 查询 Lib "alipay.dll" (ByVal 订单号 As String, ByVal 返回信息 As String) As Boolean
Private Declare Function 关闭 Lib "alipay.dll" (ByVal 订单号 As String, ByVal 返回信息 As String) As Boolean
Private Sub Command1_Click()
    Dim 服务器 As String
    Dim 帐号 As String
    Dim 私钥 As String
    服务器 = "https://openapi.alipaydev.com/gateway.do" '沙箱模式服务器     服务器 = "https://openapi.alipay.com/gateway.do" '真实模式服务器
    帐号 = Text3.Text
    私钥 = Text4.Text
    
    Dim 请求状态 As Boolean
    请求状态 = 初始化(服务器, 帐号, 私钥)
    If 请求状态 Then
       
       List1.AddItem "初始化成功"
    Else
        List1.AddItem "初始化失败"
    End If
End Sub
Private Sub Command2_Click()
    Dim 返回信息 As String
    Dim 请求状态 As Boolean
    '存放变量 设置足够的缓冲区
    返回信息 = Space$(100000)
    
    Dim 订单号 As String
    订单号 = Text2.Text
    请求状态 = 支付(订单号, Text5.Text, Text6.Text, 返回信息)
    If 请求状态 Then
        List1.AddItem 返回信息
        List1.AddItem (json解析(返回信息, "alipay_trade_precreate_response.qr_code"))
        刷新二维码 (json解析(返回信息, "alipay_trade_precreate_response.qr_code"))
    Else
        List1.AddItem "支付请求失败"
    End If
    返回信息 = ""
    Text1.Text = 订单号
End Sub
Private Sub Command3_Click()
    Dim 返回信息 As String
    Dim 请求状态 As Boolean
    '存放变量 设置足够的缓冲区
    返回信息 = Space$(100000)
       
    Dim 订单号 As String
    订单号 = Text1.Text
    请求状态 = 查询(订单号, 返回信息)
    If 请求状态 Then
       
       List1.AddItem 返回信息
    Else
        List1.AddItem "查询请求失败"
    End If
    
    返回信息 = ""
End Sub
Private Sub Command4_Click()
    Dim 返回信息 As String
    Dim 请求状态 As Boolean
    '存放变量 设置足够的缓冲区
    返回信息 = Space$(100000)
    Dim 订单号 As String
    订单号 = Text1.Text
    
    请求状态 = 关闭(订单号, 返回信息)
    
    If 请求状态 Then
        
        List1.AddItem 返回信息
    Else
        List1.AddItem "关闭订单请求失败"
    End If
    
    返回信息 = ""
End Sub


Private Function json解析(ByVal JsonStr As String, ByVal code As String) As String
    Dim ScriptObj As Object
    Set ScriptObj = CreateObject("MSScriptControl.ScriptControl")
    ScriptObj.Language = "JavaScript"
    ScriptObj.AddCode "var Json = " & JsonStr & ";"
    json解析 = ScriptObj.eval("Json." & code)
End Function

Private Function 刷新二维码(ByVal code As String) As String
   QRmaker1.InputData = code
End Function


A project created by a novice, please don’t laugh at me
. In fact, this is a case of using vb6 to call dll. Unfortunately, the article cannot upload attachments. It needs to use the alipay.dll library, which cannot be shared. If any friends need it, you can send me a private message. , or follow my public account: Ctp interface quantification

Guess you like

Origin blog.csdn.net/qq_20575249/article/details/121187093