PHPWOPI主机与WOPI客户端通信
PHP WOPI host and WOPI client comunication
我对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";
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);
和基本的WOPI客户端:
<?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>
我不明白我需要在客户端中设置哪个$wopi_url
?
我只在主机中实现了:
- getFileAction: /files/:name (https://wopi.readthedocs.io/projects/wopirest/en/latest/files/GetFile.html?highlight=getfile)
- getFileInfoAction:/文件/:name/contents (https://wopi.readthedocs.io/projects/wopirest/en/latest/files/CheckFileInfo.html#checkfileinfo)
您需要获取 "discovery XML",然后为您要使用的 "app" 提取 "edit" URL。
此 URL 将包含某些内容作为查询参数,您必须删除或保留这些内容,具体取决于您希望利用的功能。
我对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";
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);
和基本的WOPI客户端:
<?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>
我不明白我需要在客户端中设置哪个$wopi_url
?
我只在主机中实现了:
- getFileAction: /files/:name (https://wopi.readthedocs.io/projects/wopirest/en/latest/files/GetFile.html?highlight=getfile)
- getFileInfoAction:/文件/:name/contents (https://wopi.readthedocs.io/projects/wopirest/en/latest/files/CheckFileInfo.html#checkfileinfo)
您需要获取 "discovery XML",然后为您要使用的 "app" 提取 "edit" URL。
此 URL 将包含某些内容作为查询参数,您必须删除或保留这些内容,具体取决于您希望利用的功能。