tp6七牛云上传回调一直都是空怎么解决?

文件上传都是好的,七牛云的后台也能看到对应的文件。
但是$_body = file_get_contents('php://input');一直都拿不到任何数据。

代码如下:

<?php
namespace app\controller;

use app\BaseController;
use think\facade\Db;
use think\facade\View;

use Qiniu\Auth;
use Qiniu\Storage\UploadManager;
use think\facade\Env;


class Upload extends BaseController
{
    
    public function getToken()
    {
        $uid = 1;
        $expires = 3600;
        $accessKey=Env::get('qiniu.qiniu_access_key');
        $secretKey=Env::get('qiniu.qiniu_secret_key');
        $bucket=Env::get('qiniu.qiniu_bucket');
        $domain=Env::get('qiniu.qiniu_domain');

        $auth = new Auth($accessKey, $secretKey);

        $policy = array(
            'callbackUrl' => 'http://' . $domain . '/upload/callback',
            'callbackBody' => '{"fname":"$(fname)", "fkey":"$(key)"}',
            'callbackBodyType' => 'application/json'
            );
        $upToken = $auth->uploadToken($bucket, null, $expires, $policy);

        $data = ['status' => true, 'upToken' => $upToken];

        return json($data);
    }

    public function callback() 
    {
        $_body = file_get_contents('php://input');
        $body = json_decode($_body, true);
        $uid = $body['uid'];
        $fname = $body['fname'];
        $fkey = $body['fkey'];
        $desc = $body['desc'];
        $data = ['status' => true, 'uid' => $uid, 'fname' => $fname, 'fkey' => $fkey, 'desc' => $desc];
        return json($data);
    }
}

image.png

阅读 872
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
七牛云问答
子站问答
访问
宣传栏