文件上传都是好的,七牛云的后台也能看到对应的文件。
但是$_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);
}
}