2 回答

TA贡献1788条经验 获得超4个赞
你解决问题了吗?下面的简单代码对我有用
$fp = fopen('/your path where you store the zip file/'.$filename, 'w+');
if ($fp == FALSE){
print "File not opened<br>";
exit;
}
fwrite($fp, $response);
fclose($fp);
$response是 API 响应的正文,它将是 $filename从标头中获取的不可读格式的 zip 文件名。

TA贡献1735条经验 获得超5个赞
似乎 Json Encoded 并且您必须在 php 脚本中使用 json 对其进行解码,因此: json_decode(string,array) string = 您收集的编码响应。array = True 如果你想要结果数据的数组。
2- 使用 header('Content-Type: application/json') (此标头在发送或接收响应之前最有用)
3 -错误处理:json_last_error() json_last_error_msg()
try {
$header = $resultInfo->getHeader('Content-Disposition');
if (!empty($header)) {
if (strpos($header, 'filename') !== false) {
$filename = substr($header, strpos($header, 'filename'));
$str = explode('=', $filename);
$body = $resultInfo->getBody();
$fp = fopen(storage_path("csv/{$str[1]}"), 'w');
##uncomment below line if response not valid may help you.
# header('Content-Type: application/json');
$dbody = json_decode($body,true);
fwrite($fp, $dbody);
fclose($fp);
}
}
} catch (\Exception $e) {
echo $e->getMessage();
}
希望能有所帮助
- 2 回答
- 0 关注
- 110 浏览
添加回答
举报