PHP WOPI主机和WOPI客户端通信
我对WOPI有点困惑。我想实现一个基本的例子,只是为了测试。我制作了一个基本的WOPI主机:PHP WOPI主机和WOPI客户端通信,php,office365,ms-wopi,Php,Office365,Ms Wopi,我对WOPI有点困惑。我想实现一个基本的例子,只是为了测试。我制作了一个基本的WOPI主机: <?php require 'vendor/autoload.php'; use Pux\Mux; use Pux\Executor; class FilesController { // route: /files/:name public function getFileInfoAction($name) { $path = "office/$name";
<?php
require 'vendor/autoload.php';
use Pux\Mux;
use Pux\Executor;
class FilesController {
// route: /files/:name
public function getFileInfoAction($name) {
$path = "office/$name";
if (file_exists($path)) {
$handle = fopen($path, "r");
$size = filesize($path);
$contents = fread($handle, $size);
$SHA256 = base64_encode(hash('sha256', $contents, true));
$json = array(
'BaseFileName' => $name,
'OwnerId' => 'admin',
'Size' => $size,
'SHA256' => $SHA256,
'Version' => '222888822'
);
echo json_encode($json);
} else {
echo json_encode(array());
}
}
// route: /files/:name/contents
public function getFileAction($name) {
$path = "office/$name";
if (file_exists($path)) {
$handle = fopen($path, "r");
$contents = fread($handle, filesize($path));
header("Content-type: application/octet-stream");
echo $contents;
}
}
}
$mux = new Mux;
$mux->get('/files/:name', ['FilesController','getFileInfoAction']);
$mux->get('/files/:name/contents', ['FilesController','getFileAction']);
$path = $_SERVER['PATH_INFO'];
$args = explode("&", $path);
$route = $mux->dispatch( $args[0] );
Executor::execute($route);
您需要获取“发现XML”,然后提取要使用的“应用程序”的“编辑”URL
此URL将包含某些内容作为查询参数,您必须根据希望利用的功能删除或保留这些参数
<?php
$wopi_url= ''; // ??????
$access_token = 'xxx';
$access_token_ttl = 1000 * 60;
?>
<form id="office_form" name="office_form" target="office_frame" action='<?php $wopi_url; ?>' method="post">
<input name="access_token" value='<?php $access_token; ?>' type="hidden" />
<input name="access_token_ttl" value='<?php $access_token_ttl; ?>' type="hidden" />
</form>
<span id="frameholder"></span>
<script type="text/javascript">
var frameholder = document.getElementById("frameholder");
var office_frame = document.createElement("iframe");
office_frame.name = "office_frame";
office_frame.id ="office_frame";
frameholder.appendChild(office_frame);
document.getElementById("office_form").submit();
</script>