【问题标题】:PHP - How to send post request using php curl instead of form submission and then redirect the page?PHP - 如何使用 php curl 而不是表单提交来发送发布请求,然后重定向页面?
【发布时间】:2019-11-29 12:17:05
【问题描述】:

我想向银行网关https://pep.shaparak.ir/gateway.aspx 发送一个发布请求。存在的示例代码是:

<center>Please Wait...</center>
<div style="display:none">
<form name='myform' method='post' action='https://pep.shaparak.ir/gateway.aspx'>
    <input type='text' name='terminal' value='<?=$terminalCode?>' />
    <input type='text' name='merchant' value='<?=$merchantCode?>' />
    .
    .
    .
</form>
</div>
<script>document.myform.submit()</script>

用户重定向到银行想要的页面..但是我猜它存在安全问题,不是吗?因为用户可以返回到上一页并查看输入中的内容,这些输入是银行请求的凭据。 所以我一直在尝试使用 curl 并用它发送数据:

$postFields = [
    'terminalCode' => $terminalCode,
    'merchantCode' => $merchantCode,
    .
    .
    .
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://pep.shaparak.ir/gateway.aspx");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, count($postFields));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postFields));
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if(isset($info['url'])) {
    // Because I'm using Laravel.
    return redirect()->to($info['url']);
}

但现在的问题是它不会自动重定向到银行想要的页面。

如何将用户重定向到银行退货页面?

【问题讨论】:

  • 请求成功后API返回什么?
  • 你能添加一个链接到它的文档吗?
  • $info['url'] 的值为https://pep.shaparak.ir/payment.aspx?n=KkLLrzcvjsGxZHdBOKpK2AE8NGPVF8+SqexHYdRG8CE=&amp;Language=Fan 参数可以是其他任何值。它重定向到银行,但银行的响应是:购买的时间限制已结束。顺便说一句,我在本地做,这可能是问题吗?
  • 文档为波斯语。你会读波斯语吗?

标签: php payment-gateway form-submit php-curl


【解决方案1】:

不用担心安全问题。 PEP 付款通过您的电子签名(您通过表单发送的sign 参数)验证您的身份。因此,即使有人知道您的商家代码、终端 ID 或其他任何东西,这也并不重要,因为 PEP 不会在没有电子签名的情况下授权任何操作。

【讨论】:

  • 但是如果我不想暴露这两个呢?
  • 嗯,这是不可能的。我知道这种设计不是最好的,但这就是他们所做的并且有效。
  • 此外,这些也不是那么秘密,因为客户可以在网关页面本身上看到它们。
猜你喜欢
  • 2021-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-27
  • 1970-01-01
  • 1970-01-01
  • 2012-08-31
  • 1970-01-01
相关资源
最近更新 更多