近期公司项目有一个web端对文档编辑的需求偶然看到WPS开放平台做了一个简单的编辑demo
PHP端
public function detail($ids = null){
// $id = 1;
$data = [
'_w_appid' => '你的APPID',
];
$sing = $this->getSign($data);//生成签名
//type 值需要根据文档中文件的格式去定义 我只处理doc、docx所以固定了
$url = 'https://wwo.wps.cn/office/w/' . 文档id . '?_w_appid=' .'你的APPID'. '&_w_signature=' . $sing;
$this->assign('url', $url);
return $this->fetch();
}
/**
* 生成wps要的签名
*/
function getSign($data){
ksort($data); //按照key升序排列
$stringA = '';
foreach ($data as $key => $item) {
$stringA .= $key . '=' . $item; // 整合新的参数数组
}
$stringSignTemp = $stringA . "_w_secretkey=" . '你的Key';//拼接$appKey
$stringSignTemp = hash_hmac('sha1', $stringSignTemp, '你的Key', true);
$sign = base64_encode($stringSignTemp