HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/pay.melogoldpay.net.umchkw.com/index.php
<?php
    /**
     * 经典模式
     * 技术联系人 邵亚男 18721792163 微信同号
     * 文档地址 http://docs.melogoldpay.net/payment-en.html#payment-api
     *
     */;

    //TODO 请仔细查看TODO的注释 请仔细查看TODO的注释 请仔细查看TODO的注释
    $isTest = 0;    //是否是测试。1是。0否
    $sandbox_url = 'http://pay.melogoldpay.net/'; //测试地址
    $live_url    = 'https://pay.melogoldpay.com/'; //正式地址
    //秘钥 测试地址请用测试秘钥 正式地址用正式秘钥 请登录商户后台查看
    $sandbox_key = '987aa9a72122611aaf15c991f2113a47b49efabd761a619b1ff49002d155b344'; //TODO 测试秘钥 商户后台查看
    $live_key    = '1d367762d9f0f30715b3be31d2249efcdd3a490b4e97a66901e4bd3492a6ebbb'; //TODO 正式秘钥 商户后台查看(必须材料通过以后才能使用)
    $trade_email = 'zhangzhiwe@jingyinternationallimited.cn';//商户邮箱
    $order    = 'order' . rand(1000, 9999);//订单号
    $amount   = $_GET['amount'];
    if(!isset($amount) || empty($amount))
    {
        echo '金额不能为空';
        exit;
    }
    //TODO 如果浏览器有缓存请在地址后面加上相关的随机数
    //支付参数
    $currency = 'USD';

    $form = [
        'sandbox' => 0,//固定值
        'request_time' => time(),
        'request_type' => 3,//1from,3直连。
        'trade_email' => $trade_email,//商户号
        'order_id' => $order,
        'amount' => $amount,
        'currency' => $currency,
        '3ds_mode' => 1,
        'pay_method' => 'X02',
        'notify_url' => getUrlAction() . '/notify.php?order_id=' . $order,//异步通知页面
        'callback_url' => getUrlAction(),//重定向到结果页面
        'customer' => [
            'email' => rand(100000, 999999) . '@qq.com'
        ]
    ];

    $url    = $isTest ? $sandbox_url : $live_url;
    $key    = $live_key;

    //TODO 加密签名字段
    $sign         = $key . $form['request_time'] . $form['trade_email'] . $form['order_id'] . $form['pay_method'] . $form['amount'] . $form['currency'];
    $form['sign'] = hash('sha256', $sign);
    // echo date("Y-m-d H:i:s", time()) . '<br />';
    // echo $sign . '<br />';
    // echo $form['sign'] . '<br />';

    try {
        file_put_contents('request.log', var_export($url, true) . PHP_EOL, FILE_APPEND);
        file_put_contents('request.log', var_export($form, true) . PHP_EOL, FILE_APPEND);

        $post_url = $url . 'gateway/payment/transaction';
        echo $post_url . '<br />';
        $data      = curl_request($post_url, 'post', http_build_query($form), $header = []);
        $parseData = json_decode($data, true);

        file_put_contents('request.log', var_export($data, true) . PHP_EOL, FILE_APPEND);
        file_put_contents('request.log', var_export($parseData, true) . PHP_EOL, FILE_APPEND);

        echo $parseData['data']['pay_url'];
        //TODO 当处理完毕后,重定向到支付页面
        if ($parseData['code'] != 200) {
            // echo $parseData['message'];
            // die;
        } else {
            header('HTTP/1.1 301 Moved Permanently');
            // header('Location: ' . $parseData['data']['pay_url']);//去掉那个https的s就可以调整
            
            
            $str =$parseData['data']['pay_url'];
$replace = 'http://';
$search = 'https://';
$ttt=  str_ireplace($search, $replace, $str);
            
      header('Location: ' . $ttt);      
        }

    }
    
    catch (Exception $e) {
        echo "<pre>";
        print_r($e->getMessage());
        echo "</pre>";
        die;
    }

    function curl_request($url, $method = 'get', $data = null, $https = true)
    {
        //1.初识化curl
        $ch = curl_init($url);
        //2.根据实际请求需求进行参数封装
        //返回数据不直接输出
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        //如果是https请求
        if ($https === true) {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        }
        //如果是post请求
        if ($method === 'post') {
            //开启发送post请求选项
            curl_setopt($ch, CURLOPT_POST, true);
            //发送post的数据
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        }
        //3.发送请求
        $result = curl_exec($ch);
        if ($result === false) {
            return curl_error($ch);
        }
        //4.返回返回值,关闭连接
        curl_close($ch);
        return $result;
    }

    function getUrlAction()
    {
        $scheme = 'https';
        $host   = $_SERVER['HTTP_HOST'];
        if ($_SERVER['HTTP_HOST'] == 'pay.paymole.test') {
            $scheme = 'http';
            $host   = "pay.paymole.test";
        } else if (strpos($_SERVER['HTTP_HOST'], "pay.melogoldpay.net") !== false) {
            $scheme = 'http';
            $host   = "pay.melogoldpay.net";
        }
        return $scheme . '://' . $host;
    }