会飞的汉斯
2019-03-04 16:59阿里云OSS回调问题Response body is not valid json format
菜鸟一枚,使用阿里云OSS用php签名WEB直传的方式进行数据存储,但是会出现一个问题,就是说我的返回值不是标准的json格式,问题,我用的DEMO是官方的php demo,callbackURL经验证是可以访问到的,也检查了callback.php的返回值为json_encode
。
这是什么问题呢?有没有大佬帮帮忙!!感谢!!!
这个是callback.php
<?php
// 1.获取OSS的签名header和公钥url header
$authorizationBase64 = "";
$pubKeyUrlBase64 = "";
/*
* 注意:如果要使用HTTP_AUTHORIZATION头,你需要先在apache或者nginx中设置rewrite,以apache为例,修改
* 配置文件/etc/httpd/conf/httpd.conf(以你的apache安装路径为准),在DirectoryIndex index.php这行下面增加以下两行
RewriteEngine On
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization},last]
* */
if (isset($_SERVER['HTTP_AUTHORIZATION']))
{
$authorizationBase64 = $_SERVER['HTTP_AUTHORIZATION'];
}
if (isset($_SERVER['HTTP_X_OSS_PUB_KEY_URL']))
{
$pubKeyUrlBase64 = $_SERVER['HTTP_X_OSS_PUB_KEY_URL'];
}
if ($authorizationBase64 == '' || $pubKeyUrlBase64 == '')
{
header("http/1.1 403 Forbidden");
exit();
}
// 2.获取OSS的签名
$authorization = base64_decode($authorizationBase64);
// 3.获取公钥
$pubKeyUrl = base64_decode($pubKeyUrlBase64);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $pubKeyUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$pubKey = curl_exec($ch);
if ($pubKey == "")
{
//header("http/1.1 403 Forbidden");
exit();
}
// 4.获取回调body
$body = file_get_contents('php://input');
// 5.拼接待签名字符串
$authStr = '';
$path = $_SERVER['REQUEST_URI'];
$pos = strpos($path, '?');
if ($pos === false)
{
$authStr = urldecode($path)."\n".$body;
}
else
{
$authStr = urldecode(substr($path, 0, $pos)).substr($path, $pos, strlen($path) - $pos)."\n".$body;
}
// 6.验证签名
$ok = openssl_verify($authStr, $authorization, $pubKey, OPENSSL_ALGO_MD5);
if ($ok == 1)
{
header("Content-Type: application/json");
$data = array("Status"=>"Ok");
echo json_encode($data);
}
else
{
//header("http/1.1 403 Forbidden");
exit();
}
?>
get.php
- 点赞
- 回答
- 收藏
- 复制链接分享
0条回答
为你推荐
- ListObjects始终返回1000个对象的列表。 我们可以列出按日期排序的对象吗?
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 1个回答
- 在PHP中显示名字问题
- username
- mysql
- php
- 4个回答
- The method getSingleResult() is undefined for the type Query
- hibernate
- 0个回答
- url传递中文字符串 乱码问题
- 企业应用
- 0个回答
- mac安装VirtualBox报错Kernel driver not installed (rc=-1908)怎么解决?
- virtualbox
- kernel
- 虚拟机
- mac
- 6个回答
换一换