94 lines
3.6 KiB
PHP
Executable File
94 lines
3.6 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\command;
|
|
|
|
use app\common\service\wechat\WechatWorkService;
|
|
use think\console\Command;
|
|
use think\console\Input;
|
|
use think\console\Output;
|
|
|
|
/**
|
|
* 检查企业微信API权限
|
|
*/
|
|
class QywxCheckPermissions extends Command
|
|
{
|
|
protected function configure()
|
|
{
|
|
$this->setName('qywx:check-permissions')
|
|
->setDescription('检查企业微信API权限配置');
|
|
}
|
|
|
|
protected function execute(Input $input, Output $output)
|
|
{
|
|
$output->writeln('开始检查企业微信API权限...');
|
|
$output->writeln('');
|
|
|
|
try {
|
|
$service = new WechatWorkService();
|
|
|
|
// 检查应用权限
|
|
$output->writeln('1. 检查应用配置...');
|
|
$permissionCheck = $service->checkAppPermissions();
|
|
|
|
if ($permissionCheck['success']) {
|
|
$output->writeln(' ✓ 应用配置正常');
|
|
$output->writeln(' 应用ID: ' . ($permissionCheck['data']['agentid'] ?? 'N/A'));
|
|
$output->writeln(' 应用名称: ' . ($permissionCheck['data']['name'] ?? 'N/A'));
|
|
} else {
|
|
$output->writeln(' ✗ 应用配置异常: ' . $permissionCheck['message']);
|
|
}
|
|
$output->writeln('');
|
|
|
|
// 测试获取部门成员
|
|
$output->writeln('2. 测试获取部门成员...');
|
|
$userList = $service->getDepartmentUserList(1, false);
|
|
if (!empty($userList)) {
|
|
$output->writeln(' ✓ 成功获取 ' . count($userList) . ' 个成员');
|
|
$testUser = $userList[0] ?? null;
|
|
if ($testUser) {
|
|
$output->writeln(' 测试用户: ' . ($testUser['name'] ?? '') . ' (' . ($testUser['userid'] ?? '') . ')');
|
|
}
|
|
} else {
|
|
$output->writeln(' ✗ 未能获取成员列表');
|
|
}
|
|
$output->writeln('');
|
|
|
|
// 测试获取客户列表(这里会暴露权限问题)
|
|
if (!empty($userList)) {
|
|
$output->writeln('3. 测试获取客户列表权限...');
|
|
$testUser = $userList[0];
|
|
$customerList = $service->getExternalContactList($testUser['userid']);
|
|
|
|
if ($customerList === false) {
|
|
$output->writeln(' ✗ 客户联系API权限未开启(错误码48002)');
|
|
$output->writeln('');
|
|
$output->writeln('解决方案:');
|
|
$output->writeln('1. 登录企业微信管理后台');
|
|
$output->writeln('2. 进入"应用管理"');
|
|
$output->writeln('3. 找到您的应用');
|
|
$output->writeln('4. 开启以下权限:');
|
|
$output->writeln(' - 客户联系 - 获取客户列表');
|
|
$output->writeln(' - 客户联系 - 获取客户详情');
|
|
$output->writeln('5. 将服务器IP添加到可信IP白名单');
|
|
} elseif (is_array($customerList)) {
|
|
$output->writeln(' ✓ 客户联系API权限正常');
|
|
$output->writeln(' 该成员的客户数量: ' . count($customerList));
|
|
} else {
|
|
$output->writeln(' ? 未知响应类型');
|
|
}
|
|
}
|
|
$output->writeln('');
|
|
$output->writeln('检查完成!');
|
|
|
|
} catch (\Throwable $e) {
|
|
$output->writeln('');
|
|
$output->writeln('✗ 检查过程出错: ' . $e->getMessage());
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|