如何修复php变量中的错误?服务器给出500错误

时间:2019-08-11 20:25:48

标签: php laravel

我有一个代码,负责向帐户添加资金。网站页面上有收费计划,当您单击“付款”时,用户将切换为支付账单。代码如下:

   public function pay(Request $request)
    {
        $ticketID = $request->get('tickID');
        if($ticketID = 1){
            $sum = 32;
        }elseif($ticketID = 2){
            $sum = 64;
        }elseif($ticketID = 3){
            $sum = 320;
        }elseif($ticketID = 4){
            $sum = 640;
        }elseif($ticketID = 5){
            $sum = 1600;
        }elseif($ticketID = 6){
            $sum = 3840;
        }elseif($ticketID = 7){
            $sum = 6400;
        }elseif($ticketID = 8){
            $sum = 9600;
        }
        $u = $this->user->steamid64;
        $merchant_id = '423';
        $secret_word1 = '432';
        $sign = md5($merchant_id.':'.$sum.':'.$secret_word1.':'.$u);
        $url = 'https://www.free-kassa.ru/merchant/cash.php?m='.$merchant_id.'&oa='.$sum.'&o='.$u.'&s='.$sign.'&lang=ru&i=&em=';
        $returnValue = [
            'redirect' => $url
        ];
        return $returnValue;
    }

    function getIP() {

        if (isset($_SERVER['HTTP_X_REAL_IP'])) return $_SERVER['HTTP_X_REAL_IP'];

        return $_SERVER['REMOTE_ADDR'];

    }

    public function payaccept(Request $request)
    {
        $merchant_id = '534';
        $secret_word2 = '423423';


        if (!in_array(getIP(), array('144.76.93.115', '144.76.93.119', '78.47.60.198'))) die('hacking attempt!');

        $sign = md5($merchant_id.':'.$_REQUEST['AMOUNT'].':'.$merchant_secret_2.':'.$_REQUEST['MERCHANT_ORDER_ID']);

        if ($sign != $_REQUEST['SIGN']) die('wrong sign');
        $summ = $_REQUEST['AMOUNT'];
        $user = User::Where('steamid64',$_REQUEST['MERCHANT_ORDER_ID']);
        if ($summ = 32) {
            $user->money += $summ;
        }elseif ($summ = 64) {
            $user->money += $summ;
        }elseif ($summ = 320) {
            $user->money += $summ;
        }elseif ($summ = 640) {
            $user->money += round($summ*1.03);
        }elseif ($summ = 1600) {
            $user->money += round($summ*1.05);
        }elseif ($summ = 3840) {
            $user->money += round($summ*1.1);
        }elseif ($summ = 6400) {
            $user->money += round($summ*1.15);
        }elseif ($summ = 9600) {
            $user->money += round($summ*2);
        }
        $user->save();


        die('YES');
    }

功能付款形成链接,金额和数字签名。 paypay函数接受该函数处理付款,并且必须在数据库中输入付款信息。

问题出在$user = User::Where('steamid64',$_REQUEST['MERCHANT_ORDER_ID']);行中,我在var_dump()帮助下知道了。

此行产生一个变量steamid64,但不能在数据库中查找。 我该如何解决?

1 个答案:

答案 0 :(得分:2)

好吧,假设您没有放置任何错误消息或日志。。我假设错误是此行:

$user = User::Where('steamid64',$_REQUEST['MERCHANT_ORDER_ID']);

您在这里创建查询...但不执行查询。为此,请在末尾添加->first()

$user = User::Where('steamid64',$_REQUEST['MERCHANT_ORDER_ID'])->first();

然后,您将可以在$user对象上调用方法。