PHP code example of qingclouds / work-wechat-developer
1. Go to this page and download the library: Download qingclouds/work-wechat-developer 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/ */
qingclouds / work-wechat-developer example snippets
$service = new WorkWechat\EventService('corpId','encodingAesKey','token');
try{
// 需要自行urldecode
echo $service->verifyURL('msgSignature',(int)'timestamp','nonce','msgEncrypt');
}catch (\Exception $e){
print $e;
echo '';
}
$service = new WorkWechat\EventService('corpId','encodingAesKey','token');
$xml = file_get_contents("php://input");
try{
// 需要自行urldecode
// 接收到的数据已转为array
$service->decryptMsg('msgSignature',(int)'timestamp','nonce',$xml);
}catch (\Exception $e){
print $e;
echo 'fail';
}
$url = WorkWechat\AuthService::getRedirectUrl('corpId','https://www.baidu.com')
$url = WorkWechat\AuthService::getQrCodeUrl('corpId','agentId','https://www.baidu.com','')
// 已增加本地文件缓存
$service = new WorkWechat\AccessTokenService('corpId','secret');
$accessToken = $service->getToken();
// 刷新access_token
$accessToken = $service->refresh();
$service = new WorkWechat\UserService();
$service->setAccessToken($accessToken);
$service->companyUserByCode('code');
$userService = new WorkWechat\UserService();
$userService->setAccessToken($accessToken);
$userService->detail('userId')
$customerService = new WorkWechat\CustomerService();
$customerService->setAccessToken($accessToken);
$customerService->customerDetail('externalUserid')
$customerService = new WorkWechat\CustomerService();
$customerService->setAccessToken($accessToken);
$customerService->userBehaviorData(['userid','userid',...],['deptmentId',...],1618780712,1649903913)
$departmentService = new WorkWechat\DepartmentService();
$departmentService->setAccessToken($accessToken);
// 获取所有部门
$departmentService->list();
// 获取某个部门及下级部门
$departmentService->list(id);
// 部门详情
$departmentService->detail(id);
// 所有部门及部门下属员工
$departmentService->totalUserList();
// 所有部门及部门下属员工 树形结构
$departmentService->departmentTreeANdTotalUser();
$messageService = new WorkWechat\MessageService('agentId');
$messageService->setAccessToken($accessToken);
$messageService->setMessage('text-message'); // 设置发送的文本消息
$messageService->setSecrecy(1); // 设置消息是否保密 0-否 1-是
$messageService->sendTextMsgToCompanyUser('userId','userId','userId','userId','userId','userId','userId'); // 向多个/一个userId发送此消息
$service = new WorkWechat\TicketService('corpId','secret');
$service->setAccessToken($accessToken);
$service->company();
// 刷新企业jsapi ticket
$service->refreshCompany()
$service = new WorkWechat\TicketService('corpId','secret');
$service->setAccessToken($accessToken);
$service->agent();
// 刷新应用jsapi ticket
$service->refreshCompany()
$service = new WorkWechat\TicketService('corpId','secret');
$service->setAccessToken($accessToken);
$service->openCorpId("corpid");