Payzippy支付网关在Asp.net中的集成(VB)

时间:2014-04-10 20:13:46

标签: vb.net

请将任何一个转换为VB

这是C Sharp中的payzippy支付网关集成代码,需要它在VB中

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Security.Cryptography;
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
       protected Default2()
        {
            this.Init += Charging_Init;
            Main();
        }
       private void Charging_Init(object sender, EventArgs e)
        {
            this.EnableViewState = false;
        }
       private static string secretKey = "KEY_KEY_KEY_KEY_KEY";
        private static string generateSHA256(String input)
        {
            SHA256Managed crypt = new SHA256Managed();
            string hash = String.Empty;
            byte[] crypto = crypt.ComputeHash(Encoding.ASCII.GetBytes(input), 0, Encoding.ASCII.GetByteCount(input));
            foreach (byte bit in crypto)
            {
                hash += bit.ToString("x2");
            }
            return hash;
        }
        static string GenHash(Dictionary<string, string> chargingParams)
        {
            // Acquire keys and sort them.
            List<string> list = new List<string>(chargingParams.Keys);
            list.Sort();
            StringBuilder stringForHash = new StringBuilder();
            // Loop through keys.
            foreach (var key in list)
            {
                stringForHash.Append(chargingParams[key] + '|');
            }
            stringForHash.Append(secretKey);
            return generateSHA256(stringForHash.ToString());
        }
        public Dictionary<string, string> chargingParams;
        private void Main()
        {
            var currentTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

            this.chargingParams = new Dictionary<string, string>();
            chargingParams.Add("merchant_id", "test"); //Your MID issued by PayZippy.
            chargingParams.Add("buyer_email_address", "email@gmail.com"); // Email Address
            chargingParams.Add("merchant_transaction_id", "PAY_" + currentTime); //Your Transaction Id
            chargingParams.Add("transaction_type", "SALE"); //This is the default Value.
            chargingParams.Add("transaction_amount", "10000"); //Amount must be in paise. So, 1 Rupee= 100.
            chargingParams.Add("payment_method", "CREDIT"); // CREDIT,DEBIT,EMI,NET
            chargingParams.Add("bank_name", ""); //Bank Name required in case of EMI/NET.
            chargingParams.Add("emi_months", "0"); // Emi Months in case of EMI.
            chargingParams.Add("currency", "INR"); //INR is default.
            chargingParams.Add("ui_mode", "IFRAME"); //REDIRECT/IFRAME.
            chargingParams.Add("hash_method", "SHA256"); //MD5, SHA256
            chargingParams.Add("merchant_key_id", "payment"); //This is the default value.
            chargingParams.Add("timegmt", currentTime.ToString());
            chargingParams.Add("callback_url", "http://busnow.in/bus/default.aspx");
            chargingParams.Add("hash", GenHash(chargingParams));

            StringBuilder builder = new StringBuilder();
            builder.Append("https://www.payzippy.com/payment/api/charging/v1?");
            foreach (var entry in chargingParams)
            {
                builder.AppendFormat("{0}={1}&", entry.Key, entry.Value);
            }
            Console.WriteLine(builder.ToString());

        }

    }

请将任何一个转换为VB

这是C Sharp中的payzippy支付网关集成代码,需要它在VB中

1 个答案:

答案 0 :(得分:-2)

Imports System.Collections.Generic

导入System.Linq

Imports System.Web

导入System.Web.UI

导入System.Web.UI.WebControls

导入System.Text

Imports System.Security.Cryptography

Public Partial Class Default2     继承System.Web.UI.Page

Protected Sub Page_Load(sender As Object, e As EventArgs)

End Sub
Protected Sub New()
    AddHandler Me.Init, AddressOf Charging_Init
    Main()
End Sub
Private Sub Charging_Init(sender As Object, e As EventArgs)
    Me.EnableViewState = False
End Sub
Private Shared secretKey As String = "KEY_KEY_KEY_KEY_KEY"
Private Shared Function generateSHA256(input As [String]) As String
    Dim crypt As New SHA256Managed()
    Dim hash As String = [String].Empty
    Dim crypto As Byte() = crypt.ComputeHash(Encoding.ASCII.GetBytes(input), 0, Encoding.ASCII.GetByteCount(input))
    For Each bit As Byte In crypto
        hash += bit.ToString("x2")
    Next
    Return hash
End Function
Private Shared Function GenHash(chargingParams As Dictionary(Of String, String)) As String
    ' Acquire keys and sort them.
    Dim list As New List(Of String)(chargingParams.Keys)
    list.Sort()
    Dim stringForHash As New StringBuilder()
    ' Loop through keys.
    For Each key As var In list
        stringForHash.Append(chargingParams(key) & "|"C)
    Next
    stringForHash.Append(secretKey)
    Return generateSHA256(stringForHash.ToString())
End Function
Public chargingParams As Dictionary(Of String, String)
Private Sub Main()
    Dim currentTime = DateTime.Now.Ticks \ TimeSpan.TicksPerMillisecond

    Me.chargingParams = New Dictionary(Of String, String)()
    chargingParams.Add("merchant_id", "test")
    'Your MID issued by PayZippy.
    chargingParams.Add("buyer_email_address", "email@gmail.com")
    ' Email Address
    chargingParams.Add("merchant_transaction_id", "PAY_" & currentTime)
    'Your Transaction Id
    chargingParams.Add("transaction_type", "SALE")
    'This is the default Value.
    chargingParams.Add("transaction_amount", "10000")
    'Amount must be in paise. So, 1 Rupee= 100.
    chargingParams.Add("payment_method", "CREDIT")
    ' CREDIT,DEBIT,EMI,NET
    chargingParams.Add("bank_name", "")
    'Bank Name required in case of EMI/NET.
    chargingParams.Add("emi_months", "0")
    ' Emi Months in case of EMI.
    chargingParams.Add("currency", "INR")
    'INR is default.
    chargingParams.Add("ui_mode", "IFRAME")
    'REDIRECT/IFRAME.
    chargingParams.Add("hash_method", "SHA256")
    'MD5, SHA256
    chargingParams.Add("merchant_key_id", "payment")
    'This is the default value.
    chargingParams.Add("timegmt", currentTime.ToString())
    chargingParams.Add("callback_url", "http://busnow.in/bus/default.aspx")
    chargingParams.Add("hash", GenHash(chargingParams))

    Dim builder As New StringBuilder()
    builder.Append("https://www.payzippy.com/payment/api/charging/v1?")
    For Each entry As var In chargingParams
        builder.AppendFormat("{0}={1}&", entry.Key, entry.Value)
    Next
    Console.WriteLine(builder.ToString())

End Sub

结束班