通过composer安装
composer require lexiangla/openapi:~v1.0
创建文件 index.php
,使用创建文档接口为企业创建文档
<?php
include './vendor/autoload.php';
$app_key = 'APP_KEY';
$app_secret = 'APP_SECRET';
$staff_id = 'STAFF_ID';
$Lxapi = new \Lexiangla\Openapi\Api($app_key, $app_secret);
// 企业凭证 access_token 需要缓存到服务器中,频繁获取会触发频率限制错误
if ($access_token = cache_get('access_token:'.$app_key)) {
$Lxapi->setAccessToken($access_token);
} else {
$access_token = $Lxapi->getAccessToken();
cache_put('access_token'.$app_key, $access_token, 90);
}
$attributes = [
'title' => '通过乐享api创建的文档标题',
'content' => '<h1>欢迎使用腾讯乐享</h1>',
'is_markdown' => 0,
];
$options = [
'privilege_type' => 2,
'category_id' => null,
'team_id' => null,
'directory_id' => null,
'attachments' => [],
];
$response = $Lxapi->postDoc($staff_id, $attributes, $options);
header('Content-Type: application/json');
echo json_encode($response);
/**
* @param $key
*/
function cache_get($key)
{
// TODO 需要开发者自行实现
}
/**
* @param $key
* @param $value
* @param $minutes
*/
function cache_put($key, $value, $minutes)
{
// TODO 需要开发者自行实现
}
使用上述代码示例,只要替换 $app_key,$app_secret,$staff_id 这些变量为开发者从腾讯乐享获取的值后即可调通。具体参数概念请参考基本概念介绍。
cache_get
和 cache_put
为服务端缓存的读写方法,需要开发者自行实现,否则会触发乐享接口服务的频率限制