Yêu cầu thg 1 11, 2020 4:19 SA 155 0 3
  • 155 0 3
-5

mình bị chrome block không biết tim chỗ nào

Chia sẻ
  • 155 0 3

<?php
header('Content-type: text/html; charset=utf-8');
$endpoint = "https://test-payment.momo.vn/gw_payment/transactionProcessor";
// Lưu ý: link notifyUrl không phải là dạng localhost
$extraData = "";
if (!empty($_POST)) {
    $partnerCode = $_POST["partnerCode"];
    $accessKey = $_POST["accessKey"];
    $serectkey = $_POST["secretKey"];
    $orderId = $_POST["orderId"]; // Mã đơn hàng
    $orderInfo = $_POST["orderInfo"];
    $amount = $_POST["amount"];
    $notifyurl = $_POST["notifyUrl"];
    $returnUrl = $_POST["returnUrl"];
    $extraData = $_POST["extraData"]; 
    $requestId = time() . "";
    $requestType = "captureMoMoWallet";
    $extraData = ($_POST["extraData"] ? $_POST["extraData"] : "");
    //before sign HMAC SHA256 signature
    $rawHash = "partnerCode=" . $partnerCode . "&accessKey=" . $accessKey . "&requestId=" . $requestId . "&amount=" . $amount . "&orderId=" . $orderId . "&orderInfo=" . $orderInfo . "&returnUrl=" . $returnUrl . "&notifyUrl=" . $notifyurl . "&extraData=" . $extraData;
    $signature = hash_hmac("sha256", $rawHash, $serectkey);
    $data = array('partnerCode' => $partnerCode,
        'accessKey' => $accessKey,
        'requestId' => $requestId,
        'amount' => $amount,
        'orderId' => $orderId,
        'orderInfo' => $orderInfo,
        'returnUrl' => $returnUrl,
        'notifyUrl' => $notifyurl,
        'extraData' => $extraData,
        'requestType' => $requestType,
        'signature' => $signature);
    $result = execPostRequest($endpoint, json_encode($data));
    $jsonResult = json_decode($result, true);  // decode json

    //Just a example, please check more in there
    header('Location: ' . $jsonResult['payUrl']);
}
?>
<?php
function execPostRequest($url, $data)
{
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            'Content-Length: ' . strlen($data))
    );
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
    //execute post
    $result = curl_exec($ch);
    //close connection
    curl_close($ch);
    return $result;
}
?>

3 CÂU TRẢ LỜI


Đã trả lời thg 1 13, 2020 12:19 CH
+1

bị block cross-origin hả ? code chạy ở server thì chrome block gì đâu, bị server block rồi. server của thằng khác thì chịu, server mình thì set header("Access-Control-Allow-Origin: *"); Có thể thay * bằng domain server chạy code.

Chia sẻ
Đã trả lời thg 1 20, 2020 2:17 CH
0

cài extension https://chrome.google.com/webstore/detail/allow-cors-access-control/lhobafahddgcelffkeicbaginigeejlf?hl=vi mở lên khi vào localhost, sẽ cho phép cors access 😄 không thì bạn chụp lỗi lên chứ chrome block gì thì mình chịu

Chia sẻ
Đã trả lời thg 1 13, 2020 4:09 SA
-2

Đọc chả hiểu gì cả. Vui lòng update content.

Chia sẻ
Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí