如何在控制器中使用后值在回调中接收表单数据?

时间:2018-07-17 09:54:19

标签: php callback yii2 yii2-advanced-app swap

我正在尝试验证在线支付。

使用function actionToken连接到银行通行证并付款后,银行向我发送了一些信息,以POST的方式验证付款,但我收不到信息使用POST方法。

这是我的payment controllerfunction actionToken用于从我的网站发送数据,例如 amount ,而function actionVerify用于验证我已收到银行的付款信息。这是我的问题,我不知道该怎么办。

<?php

namespace frontend\controllers;

use Yii;
use common\models\Order;

class PaymentController extends \yii\web\Controller {

public function actionRequest() {
    include_once('lib/nusoap.php');
    $terminalId     = "xxxx";                    // Terminal ID
    $userName       = "xxxx";                    // Username
    $userPassword   = "xxxxxxx";                 // Password
    $orderId        = time();                       // Order ID
    $amount         = $amount.'0';                  // Price / Rial
    $localDate      = date('Ymd');                  // Date
    $localTime      = date('Gis');                  // Time
    $additionalData = $model['notes'];
    $callBackUrl    = "http://dastsazkala.com/payment/verify?id=".$id;  // Callback URL
    $payerId        =  $id;

    $parameters = [
    'terminalId'        => $terminalId,
    'userName'          => $userName,
    'userPassword'      => $userPassword,
    'orderId'           => $orderId,
    'amount'            => $amount,
    'localDate'         => $localDate,
    'localTime'         => $localTime,
    'additionalData'    => $additionalData,
    'callBackUrl'       => $callBackUrl,
    'payerId'           => $payerId];

    $client = new \nusoap_client('https://bpm.shaparak.ir/pgwchannel/services/pgw?wsdl');
    $namespace='http://interfaces.core.sw.bps.com/';
    $result     = $client->call('bpPayRequest', $parameters, $namespace);

}

public function actionVerify($id = null, $check = null) {
//my promblem is in this function, that I cant receive posts.

if ($_POST['ResCode'] == '0') {
    //payment is correct
    include_once('lib/nusoap.php');
    $client = new nusoap_client('https://bpm.shaparak.ir/pgwchannel/services/pgw?wsdl');
    $namespace='http://interfaces.core.sw.bps.com/';

            $terminalId             = "xxxx";                    // Terminal ID
            $userName               = "xxxxx";                    // Username
            $userPassword           = "xxxxx";                   // Password
            $orderId                = $_POST['SaleOrderId'];        // Order ID
            $verifySaleOrderId      = $_POST['SaleOrderId'];
            $verifySaleReferenceId  = $_POST['SaleReferenceId'];

            $parameters = [
            'terminalId' => $terminalId,
            'userName' => $userName,
            'userPassword' => $userPassword,
            'orderId' => $orderId,
            'saleOrderId' => $verifySaleOrderId,
            'saleReferenceId' => $verifySaleReferenceId];
            // Call the SOAP method
            $result = $client->call('bpVerifyRequest', $parameters, $namespace);
            if($result == 0) {
                //verify is correct
                 echo 'The transaction was successful';
            } else {
                //error in pyament
            }
        } else {
            //error in pyament
        }
    }
}

在此function中,我什么也没收到。

我是否必须做一些控制器行为或其他事情?

为什么我不能在控制器中收到任何帖子?

普通铬:

Request URL: http://dastsazkala.com/payment/verify
Request Method: POST
Status Code: 301 Moved Permanently
Remote Address: 138.201.30.123:80
Referrer Policy: no-referrer-when-downgrade

这是我收到的:

Here is my respond from bank

2 个答案:

答案 0 :(得分:0)

问题是这样的:我的网站网址开头是 www,但是www中没有没有 callBackUrl

所以我改变了

$callBackUrl = "http://www.dastsazkala.com/payment/verify?id=".$id; //add www. in the beginning

代替

$callBackUrl = "http://dastsazkala.com/payment/verify?id=".$id;

,我可以使用POST方法从银行快线接收表格数据

答案 1 :(得分:0)

dastsazkala.com/payment/verify重定向到www.dastsazkala.com/payment/verify,请注意www!

查询结果:

Status Code: 301 Moved Permanently

明确暗示可能正在进行重定向