Skip to content

支付宝支付成功,返回回调地址时出现:The Response content must be a string or object implementing __toString(), "boolean" given. #39

Closed
@tianxionglu

Description

@tianxionglu

问题描述

支付宝支付成功,返回回调地址时出现:The Response content must be a string or object implementing __toString(), "boolean" given.

代码

路由:
// 支付宝回调地址
Route::get('alipay/return','AliPayController@return');
// 支付宝异步通知
Route::post('alipay/notify','AliPayController@notify');
// 支付地址
Route::get('alipay','AliPayController@pay');

控制器:
`
namespace App\Http\Controllers;

use Pay;
use Illuminate\Http\Request;

class AliPayController extends Controller
{
public function pay ()
{
$config_biz = [
'out_trade_no' => time(),
'total_amount' => '0.01',
'subject' => 'test',
];

    return Pay::driver('alipay')->gateway()->pay($config_biz);
}

public function return(Request $request)
{
    return Pay::driver('alipay')->gateway()->verify($request->all());
}

public function notify(Request $request)
{
    if (Pay::driver('alipay')->gateway()->verify($request->all())) {
        file_put_contents(storage_path('notify.txt'), "收到来自支付宝的异步通知\r\n", FILE_APPEND);
        file_put_contents(storage_path('notify.txt'), '订单号:' . $request->out_trade_no . "\r\n", FILE_APPEND);
        file_put_contents(storage_path('notify.txt'), '订单金额:' . $request->total_amount . "\r\n\r\n", FILE_APPEND);
    } else {
        file_put_contents(storage_path('notify.txt'), "收到异步通知\r\n", FILE_APPEND);
    }

    echo "success";
}

}
`

报错详情

错误信息:
`*
* @param mixed $content Content that can be cast to string
*
* @return $this
*
* @throws \UnexpectedValueException
*/
public function setContent($content)
{
if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable(array($content, '__toString'))) {
throw new \UnexpectedValueException(sprintf('The Response content must be a string or object implementing __toString(), "%s" given.', gettype($content)));
}

    $this->content = (string) $content;

    return $this;
}

/**
 * Gets the current response content.
 *
 * @return string Content
 */
public function getContent()
{
    return $this->content;
}

/**
 * Sets the HTTP protocol version (1.0 or 1.1).
 *

Arguments
"The Response content must be a string or object implementing __toString(), "boolean" given."`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions