如何连接到支付网关

时间:2018-05-15 19:33:04

标签: php curl payment-gateway payment

我有一个加密的现成脚本,无法访问所有代码。 这个脚本有一个支付网关 在付款页面中是一个表单,其中包含对某个页面的操作

<form name="payment" method="post" action="example.com/cPage">
<input name="amount" id="amount">
<button type="submit">pay</button>
<input name="submit" type="hidden" value="1">

我将操作更改为付款页面:action="example.com/.../mpage/send.php" 和mpage是我从银行获得的api,有send.php,get.php和function.php 问题是当我将操作更改为mpage网关工作但不显示在脚本的cms中时,并且仅在cms中的客户配置文件中的默认操作付款资金中显示。

function.php:

function send($url,$api,$amount,$redirect){
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
 curl_setopt($ch,CURLOPT_POSTFIELDS,"api=$api&amount=$amount&redirect=$redirect");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    $res = curl_exec($ch);
    curl_close($ch);
    return $res;
}
function get($url,$api,$trans_id,$id_get){
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
  curl_setopt($ch,CURLOPT_POSTFIELDS,"api=$api&id_get=$id_get&trans_id=$trans_id");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    $res = curl_exec($ch);
    curl_close($ch);
    return $res;
}

send.php:

    include_once("function.php");
    $url = 'http://bankwebsite.com/gateway-send'; 
    $api = '*****';
    $amount = $_POST['amount'];
    $redirect = 'http://example.com/.../mpage/send.php';
    $result = send($url,$api,$amount,$redirect); 
    if($result > 0 && is_numeric($result))
    {
        $go = "http://bankwebsite/gateway-$result"; 
        header("Location: $go");
    } else {
    print_r($result);
}

get.php:

include_once("function.php");
$url = 'http://bankwebsite/gateway-result-second'; 
$api = '********';
$trans_id = $_POST['trans_id']; 
$id_get = $_POST['id_get'];
$result = get($url,$api,$trans_id,$id_get); 
if($result == 1)
{#success msg
    }
else
{#failed msg
    }

现在我将一个newSend函数添加到function.php:

    function newSend($url,$amount,$submit){
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_POSTFIELDS,"amount=$amount&submit=$submit");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    $res = curl_exec($ch);
    curl_close($ch);
    return $res;

和此代码而不是get.php中的#success msg:

$url = "http://example.com/cPage";
newSend($url,$amount,1);

它不起作用。 我不知道如何用两个动作发送金额,用cms写的钱也要付款。

0 个答案:

没有答案