Asked Jan 11th, 4:19 AM 137 0 3
  • 137 0 3
-5

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

Share
  • 137 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 ANSWERS


Answered Jan 13th, 12:19 PM
+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.

Share
Answered Jan 20th, 2:17 PM
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

Share
Answered Jan 13th, 4:09 AM
-2

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

Share