在C#中集成migs(MasterCard虚拟支付客户端)

时间:2014-06-16 08:06:33

标签: c#

有人可以解释如何在C#中集成第三方支付mig(MasterCard虚拟支付客户端)吗?

任何做过类似项目或有任何线索的人都会对我有很大的帮助。如有任何问题,我将详细说明。谢谢。

try
{
    //Define Variables
    string MerchantId = "00000047";
    string Amount = txtAmountUSD.Text.Trim();
    long PhoneNumber=long.Parse( txtPhoneNumber.Text.Trim().ToString());
    string AccessCode = "4EC13697";
    string SECURE_SECRET = "A1A3999770F5893719AE0076C7F18834";
    string ReturnUrl = "http://localhost:2035/Core/frmMoneyTransfer.aspx";
    string DestinationUrl = "https://migs.mastercard.com.au/vpcpay?";
    string MerchantTransactionRef = Amount + DateTime.Now;
    string Command = "Pay";
    var HashData = SECURE_SECRET;

    string postData = "vpc_Merchant=" + MerchantId;
    postData += ("&vpc_Amount=" + Amount);
    postData += ("&vpc_AccessCode=" + AccessCode);
    postData += ("&vpc_Command=" + Command);
    postData += ("&vpc_MerchTxnRef=" + MerchantTransactionRef);
    postData += ("&vpc_ReturnURL=" + ReturnUrl);
    postData += ("&vpc_SecureHashType=" + "SHA256");
    postData += ("&vpc_OrderInfo=" + PhoneNumber );
    postData += ("&vpc_Version=" + "1.0");
    postData+=("&vpc_SecureHash="+SECURE_SECRET );

    HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(DestinationUrl);                       

    request1.Method = "POST";
    request1.ContentType = "application/x-www-form-urlencoded";
    request1.AllowAutoRedirect = true;
    request1.ProtocolVersion = HttpVersion.Version11;

    byte[] bytes = System.Text.Encoding.UTF8.GetBytes(postData);
    request1.ContentLength = bytes.Length;

    Stream requestStream = request1.GetRequestStream();
    requestStream.Write(bytes, 0, bytes.Length);

    WebResponse response = request1.GetResponse();
    Stream stream = response.GetResponseStream();
    StreamReader reader = new StreamReader(stream);

    var result = reader.ReadToEnd();

    Response.Redirect(request1.Address.ToString(), false );

    stream.Dispose();
    reader.Dispose(); 
}
catch (Exception Ex) 
{ 
    lblInfo.Text= Ex.Message.ToString(); 
}

0 个答案:

没有答案