【问题标题】:Laravel 5.8 redirect returns 200 but doesn’t open the pageLaravel 5.8 重定向返回 200 但不打开页面
【发布时间】:2019-06-06 15:15:03
【问题描述】:

问题是我在一个条件下使用 laravel 重定向将用户重定向到特定的外部 URL,条件为真,但重定向只登录网络,并没有真正改变浏览器中的 URL。我也尝试了纯 PHP 中的 header 函数,但没有帮助。

这是我的代码:

public function purchase(Request $request, Transaction $transaction, User $user_model)
{
    $username = $request->input('username');
    if (!isset($username)) {
        $this->setMessage(400, 'پر کردن فیلد username الزامی است');
        return response()->json(['status' => 'error', 'data' => $this->getMessage()]);
    }
    $user = $user_model->scopeGetUserId($username);
    if ($user == null) {
        $this->setMessage(404, 'کاربر یافت نشد');
        return response()->json(['status' => 'error', 'data' => $this->getMessage()], 200);
    }
    $user_id = $user->id;
    $diet_type_id = $request->input('diet_type_id');
    $price = 100;

        $Amount = $price; //Amount will be based on Toman  - Required
        $Description = "پرداخت مبلغ $price تومان برای دریافت رژیم از سلامتپاد";  // Required
        $Email = 'm.esmiran@gmail.com'; // Optional
        $Mobile = '09123456789'; // Optional
        $CallbackURL = 'http://salamatpaad.com/test/public/api/verify/' . $user_id . '/' . $diet_type_id;  // Required
        $client = new SoapClient('https://ir.zarinpal.com/pg/services/WebGate/wsdl', array('encoding' => 'UTF-8'));

        $result = $client->PaymentRequest(
            array(
                'MerchantID' => $transaction->scopeGetMerchantId(),
                'Amount' => $Amount,
                'Description' => $Description,
                'Email' => $Email,
                'Mobile' => $Mobile,
                'CallbackURL' => $CallbackURL
            )
        );
        //Redirect to URL You can do it also by creating a form
        if ($result->Status == 100) {
            return redirect()->to('https://www.zarinpal.com/pg/StartPay/' . $result->Authority);
        } else {
            echo 'ERR: ' . $result->Status;
        }

}

response

【问题讨论】:

  • 它似乎坏了......你对这个问题的描述期望什么答案??
  • 请出示您的代码。如果您使用 Ajax 来获取重定向的 url,那么您将不得不使用 javascript/jquery 来执行重定向。
  • 你的意思是我不能从服务器端重定向? '因为我正在使用重定向 laravel 功能
  • 这取决于您如何进行重定向,以及您如何触发它。如果没有代码,我们无法准确告诉您发生了什么。
  • 您需要什么信息? @黑豹

标签: php laravel redirect


【解决方案1】:

正如Documentation 中所说,要重定向到外部链接,请使用redirect()->away() 方法。

【讨论】:

  • 谢谢,但我已经尝试过 away()、to() 和 redirect('url')。它们都不起作用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-26
  • 2016-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-15
相关资源
最近更新 更多