将PHP脚本转换为C#

时间:2018-07-08 09:44:57

标签: c# php

我想将我的站点(mvc5)连接到Payeer付款处理程序。我阅读了Payeers文档,但是文档的所有脚本都在php中。请帮助我将此脚本转换为C#。

<?php if (!in_array($_SER VER['REMOTE_AD DR'], array('185.71.65.92', '185.71.65.189','149.202.17.210'))) return; if isset($_POST['m_operation_id']) && isset($_POST['m_sign'])){ $m_key = 'Your secret key';$arHash = array($_POST['m_operation_id'],$_POST['m_operation_ps'],$_POST['m_operation_date'],$_POST['m_operation_pay_date'],$_POST['m_shop'],$_POST['m_orderid'],$_POST['m_amount'],$_POST['m_curr'],$_POST['m_desc'],$_POST['m_status']);if isset($_POST['m_params'])){$arHash[] = $_POST['m_params'];}$arHash[] = $m_key;$sign_hash = strtoupper(hash('sha256', implode(':', $arHash)));if $_POST['m_sign'] == $sign_hash && $_POST['m_status'] == 'success'){exit($_POST['m_orderid'].'|success');}exit($_POST['m_orderid'].'|error');}?>

1 个答案:

答案 0 :(得分:1)

if (!in_array($_SERVER['REMOTE_AD DR'], array('185.71.65.92', '185.71.65.189','149.202.17.210'))) return;
此行代码中的

检查客户端地址是否在白名单中,如果不在白名单中,则阻止请求,您可以使用以下代码在c#中执行此操作:

string[] whiteListIps = new string[]{'185.71.65.92', '185.71.65.189','149.202.17.210'};
var clientIp = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if(!whiteListIps.Contains(clientIp))
     return Redirect("/UnAuthorized");

在下一行中,您应该检查Request.Body

中是否存在 m_operation_id m_sign

下面是在php中:

if isset($_POST['m_operation_id']) && isset($_POST['m_sign']))

在c#中:

 if(Request.Form["m_operation_id"] != null && Request.Form("m_sign") != null)

$ m_key $ arHash 只是基于发布值声明的变量和将在 SHA256 算法中用于解码消息的密钥确保接收到的消息哈希值等于参数值