PHP code example of zyan / work-wechat
1. Go to this page and download the library: Download zyan/work-wechat library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zyan / work-wechat example snippets
use Zyan\WorkWeChat\WorkWeChat;
//默认配置 可选
$config = [
'cache' => [ //缓存 目前仅支持 file redis
'default' => 'file',
'stores' => [
'file' => [
'driver' => 'file',
'path' => './chache',
],
'redis' => [
'driver' => 'redis',
'host' => '127.0.0.1',
'port' => 6379,
'password' => null
]
]
]
];
$work = WorkWeChat::config($config);
$work->login->getQrcode();
/**
return
Array
(
[qrcode_key] => eb67102ca70843de //二维码的key
[qrcode_url] => https://work.weixin.qq.com/wwqrlogin/qrcode/eb67102ca70843de?login_type=login_admin
)
*/
$work->login->getStatus($qrcode_key)
/**
return
Array
(
[data] => Array
(
[status] => QRCODE_SCAN_NEVER //登录状态
[auth_source] => SOURCE_FROM_WEWORK
[corp_id] => 0
[code_type] => 2
[clientip] => 183.17.231.150
[confirm_clientip] =>
)
)
QRCODE_SCAN_NEVER 等待扫码
QRCODE_SCAN_FAIL 取消操作
QRCODE_SCAN_ING 已扫码,等待确认
QRCODE_SCAN_SUCC 已确认 登录
*/
$isLogin = $work->login->getCookie($auth_code, $qrcode_key);
//返回是否登录成功 true 为成功
//$auth_code 为授权 code 在 QRCODE_SCAN_SUCC时 会返回
//您不需要去处理cookie 因为系统已经帮你处理好了
//默认会将cookie转为array保存file缓存中
$work->corp->getCorp();
//获取部门列表
$work->department->getList();
//获取员工列表
$work->user->getList();
//获取所有应用列表
$work->apps->getList();
//创建内部应用 $visiblePid 可见部门
$work->apps->addOpenApiApp(string $name, string $description, string $logoImage, array $visiblePid = []);
//应用详情
$work->apps->getOpenApiApp(int $appId);
//应用设为开启状态
$work->apps->saveOpenApiApp(int $appId);
//获取可信域名txt文件验证 返回filename txt内容为文件名,需要自已生成txt
$work->apps->getDomainOwnershipVerifyInfo();