From 35abbdb6fa9314dc2ba652bebb2dcbdcbd68c96f Mon Sep 17 00:00:00 2001 From: Ghost <106998207@qq.com> Date: Tue, 18 Mar 2025 14:56:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=BA=95=E5=B1=82=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/.env | 6 +- .../api/controller/AccountController.php | 96 +++++++++ .../api/controller/DeviceController.php | 183 ++++++++++++++++++ .../api/controller/FriendTaskController.php | 93 +++++++++ .../api/controller/UserController.php | 14 +- .../controller/WechatChatroomController.php | 183 ++++++++++++++++++ .../api/controller/WechatController.php | 20 +- .../api/controller/WechatFriendController.php | 44 ++--- .../common/model/CompanyAccountModel.php | 9 +- .../application/common/model/DeviceModel.php | 60 ------ .../common/model/FriendTaskModel.php | 10 + .../common/model/WechatAccountModel.php | 9 - .../model/WechatChatroomMemberModel.php | 10 + .../common/model/WechatChatroomModel.php | 10 + 14 files changed, 626 insertions(+), 121 deletions(-) create mode 100644 Server/application/api/controller/AccountController.php create mode 100644 Server/application/api/controller/DeviceController.php create mode 100644 Server/application/api/controller/FriendTaskController.php create mode 100644 Server/application/api/controller/WechatChatroomController.php create mode 100644 Server/application/common/model/FriendTaskModel.php create mode 100644 Server/application/common/model/WechatChatroomMemberModel.php create mode 100644 Server/application/common/model/WechatChatroomModel.php diff --git a/Server/.env b/Server/.env index 17cc44b4..cf5b3d6e 100644 --- a/Server/.env +++ b/Server/.env @@ -12,4 +12,8 @@ hostport = 3306 prefix = tk_ [api] -wechat_url = https://s2.siyuguanli.com:9991/ \ No newline at end of file +wechat_url = https://s2.siyuguanli.com:9991/ +guid = 5E2C38F5A275450D935F3ECEC076124E +deviceSocketHost = s2.siyuguanli.com:9992 +username = kr_xf2 +password = kr123456 \ No newline at end of file diff --git a/Server/application/api/controller/AccountController.php b/Server/application/api/controller/AccountController.php new file mode 100644 index 00000000..4666f4dd --- /dev/null +++ b/Server/application/api/controller/AccountController.php @@ -0,0 +1,96 @@ +request->header('authorization', '')); + if (empty($authorization)) { + return errorJson('缺少授权信息'); + } + + try { + // 构建请求参数 + $params = [ + 'showNormalAccount' => $this->request->param('showNormalAccount', ''), + 'keyword' => $this->request->param('keyword', ''), + 'departmentId' => $this->request->param('departmentId', ''), + 'pageIndex' => $this->request->param('pageIndex', 0), + 'pageSize' => $this->request->param('pageSize', 12) + ]; + + // 设置请求头 + $headerData = ['client:system']; + $header = setHeader($headerData, $authorization, 'plain'); + + // 发送请求获取公司账号列表 + $result = requestCurl($this->baseUrl . 'api/Account/myTenantPageAccounts', $params, 'GET', $header); + $response = handleApiResponse($result); + + // 保存数据到数据库 + if (!empty($response['results'])) { + foreach ($response['results'] as $item) { + $this->saveAccount($item); + } + } + + return successJson($response); + } catch (\Exception $e) { + return errorJson('获取公司账号列表失败:' . $e->getMessage()); + } + } + + /** + * 保存账号数据到数据库 + * @param array $item 账号数据 + */ + private function saveAccount($item) + { + // 将日期时间字符串转换为时间戳 + $createTime = isset($item['createTime']) ? strtotime($item['createTime']) : null; + $deleteTime = isset($item['deleteTime']) ? strtotime($item['deleteTime']) : null; + + $data = [ + 'accountId' => $item['id'], + 'accountType' => isset($item['accountType']) ? $item['accountType'] : 0, + 'status' => isset($item['status']) ? $item['status'] : 0, + 'tenantId' => isset($item['tenantId']) ? $item['tenantId'] : 0, + 'userName' => isset($item['userName']) ? $item['userName'] : '', + 'realName' => isset($item['realName']) ? $item['realName'] : '', + 'nickname' => isset($item['nickname']) ? $item['nickname'] : '', + 'avatar' => isset($item['avatar']) ? $item['avatar'] : '', + 'phone' => isset($item['phone']) ? $item['phone'] : '', + 'memo' => isset($item['memo']) ? $item['memo'] : '', + 'createTime' => $createTime, + 'creator' => isset($item['creator']) ? $item['creator'] : 0, + 'creatorUserName' => isset($item['creatorUserName']) ? $item['creatorUserName'] : '', + 'creatorRealName' => isset($item['creatorRealName']) ? $item['creatorRealName'] : '', + 'departmentId' => isset($item['departmentId']) ? $item['departmentId'] : 0, + 'departmentName' => isset($item['departmentName']) ? $item['departmentName'] : '', + 'privilegeIds' => isset($item['privilegeIds']) ? $item['privilegeIds'] : [], + 'alive' => isset($item['alive']) ? $item['alive'] : false, + 'hasXiakeAccount' => isset($item['hasXiakeAccount']) ? $item['hasXiakeAccount'] : false, + 'isDeleted' => isset($item['isDeleted']) ? $item['isDeleted'] : false, + 'deleteTime' => $deleteTime + ]; + + // 使用accountId作为唯一性判断 + $account = CompanyAccountModel::where('accountId', $item['id'])->find(); + + if ($account) { + $account->save($data); + } else { + CompanyAccountModel::create($data); + } + } +} \ No newline at end of file diff --git a/Server/application/api/controller/DeviceController.php b/Server/application/api/controller/DeviceController.php new file mode 100644 index 00000000..d7bdf681 --- /dev/null +++ b/Server/application/api/controller/DeviceController.php @@ -0,0 +1,183 @@ +request->header('authorization', '')); + if (empty($authorization)) { + return errorJson('缺少授权信息'); + } + + try { + // 构建请求参数 + $params = [ + 'accountId' => $this->request->param('accountId', ''), + 'keyword' => $this->request->param('keyword', ''), + 'imei' => $this->request->param('imei', ''), + 'groupId' => $this->request->param('groupId', ''), + 'brand' => $this->request->param('brand', ''), + 'model' => $this->request->param('model', ''), + 'deleteType' => $this->request->param('deleteType', 'unDeleted'), + 'operatingSystem' => $this->request->param('operatingSystem', ''), + 'softwareVersion' => $this->request->param('softwareVersion', ''), + 'phoneAppVersion' => $this->request->param('phoneAppVersion', ''), + 'recorderVersion' => $this->request->param('recorderVersion', ''), + 'contactsVersion' => $this->request->param('contactsVersion', ''), + 'rooted' => $this->request->param('rooted', ''), + 'xPosed' => $this->request->param('xPosed', ''), + 'alive' => $this->request->param('alive', ''), + 'hasWechat' => $this->request->param('hasWechat', ''), + 'departmentId' => $this->request->param('departmentId', ''), + 'pageIndex' => $this->request->param('pageIndex', 0), + 'pageSize' => $this->request->param('pageSize', 20) + ]; + + // 设置请求头 + $headerData = ['client:system']; + $header = setHeader($headerData, $authorization, 'plain'); + + // 发送请求获取设备列表 + $result = requestCurl($this->baseUrl . 'api/device/pageResult', $params, 'GET', $header); + $response = handleApiResponse($result); + + // 保存数据到数据库 + if (!empty($response['results'])) { + foreach ($response['results'] as $item) { + $this->saveDevice($item); + } + } + + return successJson($response); + } catch (\Exception $e) { + return errorJson('获取设备列表失败:' . $e->getMessage()); + } + } + + /** + * 保存设备数据到数据库 + * @param array $item 设备数据 + */ + private function saveDevice($item) + { + $data = [ + 'userName' => isset($item['userName']) ? $item['userName'] : '', + 'nickname' => isset($item['nickname']) ? $item['nickname'] : '', + 'realName' => isset($item['realName']) ? $item['realName'] : '', + 'groupName' => isset($item['groupName']) ? $item['groupName'] : '', + 'wechatAccounts' => isset($item['wechatAccounts']) ? json_encode($item['wechatAccounts']) : json_encode([]), + 'alive' => isset($item['alive']) ? $item['alive'] : false, + 'lastAliveTime' => isset($item['lastAliveTime']) ? $item['lastAliveTime'] : null, + 'tenantId' => isset($item['tenantId']) ? $item['tenantId'] : 0, + 'groupId' => isset($item['groupId']) ? $item['groupId'] : 0, + 'currentAccountId' => isset($item['currentAccountId']) ? $item['currentAccountId'] : 0, + 'imei' => $item['imei'], + 'memo' => isset($item['memo']) ? $item['memo'] : '', + 'createTime' => isset($item['createTime']) ? $item['createTime'] : null, + 'isDeleted' => isset($item['isDeleted']) ? $item['isDeleted'] : false, + 'deletedAndStop' => isset($item['deletedAndStop']) ? $item['deletedAndStop'] : false, + 'deleteTime' => isset($item['deleteTime']) ? $item['deleteTime'] : null, + 'rooted' => isset($item['rooted']) ? $item['rooted'] : false, + 'xPosed' => isset($item['xPosed']) ? $item['xPosed'] : false, + 'brand' => isset($item['brand']) ? $item['brand'] : '', + 'model' => isset($item['model']) ? $item['model'] : '', + 'operatingSystem' => isset($item['operatingSystem']) ? $item['operatingSystem'] : '', + 'softwareVersion' => isset($item['softwareVersion']) ? $item['softwareVersion'] : '', + 'extra' => isset($item['extra']) ? json_encode($item['extra']) : json_encode([]), + 'phone' => isset($item['phone']) ? $item['phone'] : '', + 'lastUpdateTime' => isset($item['lastUpdateTime']) ? $item['lastUpdateTime'] : null + ]; + + // 使用imei作为唯一性判断 + $device = DeviceModel::where('imei', $item['imei'])->find(); + + if ($device) { + $device->save($data); + } else { + DeviceModel::create($data); + } + } + + /** + * 生成设备二维码 + * @param int $accountId 账号ID + * @return \think\response\Json + */ + public function addDevice($accountId = 0) + { + if (empty($accountId)) { + $accountId = $this->request->param('accountId', 5555); + } + + if (empty($accountId)) { + return errorJson('账号ID不能为空'); + } + + try { + // 获取环境配置 + $tenantGuid = Env::get('api.guid', ''); + $deviceSocketHost = Env::get('api.deviceSocketHost', ''); + + if (empty($tenantGuid) || empty($deviceSocketHost)) { + return errorJson('环境配置不完整,请检查api.guid和api.deviceSocketHost配置'); + } + + // 构建设备配置数据 + $data = [ + 'tenantGuid' => $tenantGuid, + 'deviceSocketHost' => $deviceSocketHost, + 'checkVersionUrl' => '', + 'accountId' => intval($accountId) + ]; + + // 将数据转换为JSON + $jsonData = json_encode($data); + + // 生成二维码图片 + $qrCode = $this->generateQrCodeImage($jsonData); + + return successJson([ + 'qrCode' => $qrCode, + 'config' => $data + ]); + } catch (\Exception $e) { + return errorJson('生成设备二维码失败:' . $e->getMessage()); + } + } + + /** + * 生成二维码图片(base64格式) + * @param string $data 二维码数据 + * @return string base64编码的图片 + */ + private function generateQrCodeImage($data) + { + // 使用endroid/qr-code 2.5版本生成二维码 + $qrCode = new QrCode($data); + $qrCode->setSize(300); + $qrCode->setMargin(10); + $qrCode->setWriterByName('png'); + $qrCode->setEncoding('UTF-8'); + + // 使用枚举常量而不是字符串 + $qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH); + + // 直接获取base64内容 + $base64 = 'data:image/png;base64,' . base64_encode($qrCode->writeString()); + + return $base64; + } +} \ No newline at end of file diff --git a/Server/application/api/controller/FriendTaskController.php b/Server/application/api/controller/FriendTaskController.php new file mode 100644 index 00000000..e842145a --- /dev/null +++ b/Server/application/api/controller/FriendTaskController.php @@ -0,0 +1,93 @@ +request->header('authorization', '')); + if (empty($authorization)) { + return errorJson('缺少授权信息'); + } + + try { + // 构建请求参数 + $params = [ + 'keyword' => $this->request->param('keyword', ''), + 'status' => $this->request->param('status', ''), + 'pageIndex' => $this->request->param('pageIndex', 0), + 'pageSize' => $this->request->param('pageSize', 20) + ]; + + // 设置请求头 + $headerData = ['client:system']; + $header = setHeader($headerData, $authorization, 'json'); + + // 发送请求获取添加好友记录列表 + $result = requestCurl($this->baseUrl . 'api/AddFriendByPhoneTask/list', $params, 'GET', $header,'json'); + $response = handleApiResponse($result); + + + // 保存数据到数据库 + if (!empty($response['results'])) { + foreach ($response['results'] as $item) { + $this->saveFriendTask($item); + } + } + + return successJson($response); + } catch (\Exception $e) { + return errorJson('获取添加好友记录列表失败:' . $e->getMessage()); + } + } + + /** + * 保存添加好友记录到数据库 + * @param array $item 添加好友记录数据 + */ + private function saveFriendTask($item) + { + // 将日期时间字符串转换为时间戳 + $createTime = isset($item['createTime']) ? strtotime($item['createTime']) : null; + + $data = [ + 'taskId' => $item['id'], + 'tenantId' => $item['tenantId'], + 'operatorAccountId' => $item['operatorAccountId'], + 'status' => $item['status'], + 'phone' => $item['phone'], + 'msgContent' => $item['msgContent'], + 'wechatAccountId' => $item['wechatAccountId'], + 'createTime' => $createTime, + 'remark' => $item['remark'], + 'extra' => $item['extra'], + 'labels' => $item['labels'], + 'from' => $item['from'], + 'alias' => $item['alias'], + 'wechatId' => $item['wechatId'], + 'wechatAvatar' => $item['wechatAvatar'], + 'wechatNickname' => $item['wechatNickname'], + 'accountNickname' => $item['accountNickname'], + 'accountRealName' => $item['accountRealName'], + 'accountUsername' => $item['accountUsername'] + ]; + + // 使用taskId作为唯一性判断 + $task = FriendTaskModel::where('taskId', $item['id'])->find(); + + if ($task) { + $task->save($data); + } else { + FriendTaskModel::create($data); + } + } +} \ No newline at end of file diff --git a/Server/application/api/controller/UserController.php b/Server/application/api/controller/UserController.php index 550d5850..2be2fa3e 100644 --- a/Server/application/api/controller/UserController.php +++ b/Server/application/api/controller/UserController.php @@ -251,19 +251,11 @@ class UserController extends BaseController } $headerData = ['client:' . self::CLIENT_TYPE]; - $header = setHeader($headerData, $authorization, 'plain'); + $header = setHeader($headerData, $authorization, 'system'); - try { - // 获取当前用户信息 - $currentUser = CompanyAccountModel::where('token', $authorization)->find(); - + try { // 调用外部退出登录接口 - $result = requestCurl($this->baseUrl . 'api/Account/SignOut', [], 'POST', $header); - - if ($currentUser) { - recordUserLog($currentUser['id'], $currentUser['userName'], 'LOGOUT', '退出登录成功', [], 200, '退出成功'); - } - + $result = requestCurl($this->baseUrl . 'api/Account/SignOut', [], 'GET', $header); return successJson([] , '退出成功'); } catch (\Exception $e) { recordUserLog(0, '', 'LOGOUT', '退出登录异常', [], 500, $e->getMessage()); diff --git a/Server/application/api/controller/WechatChatroomController.php b/Server/application/api/controller/WechatChatroomController.php new file mode 100644 index 00000000..5008e8b5 --- /dev/null +++ b/Server/application/api/controller/WechatChatroomController.php @@ -0,0 +1,183 @@ +request->header('authorization', '')); + if (empty($authorization)) { + return errorJson('缺少授权信息'); + } + + try { + // 构建请求参数 + $params = [ + 'keyword' => $this->request->param('keyword', ''), + 'wechatAccountKeyword' => $this->request->param('wechatAccountKeyword', ''), + 'isDeleted' => $this->request->param('isDeleted', ''), + 'allotAccountId' => $this->request->param('allotAccountId', ''), + 'groupId' => $this->request->param('groupId', ''), + 'wechatChatroomId' => $this->request->param('wechatChatroomId', 0), + 'memberKeyword' => $this->request->param('memberKeyword', ''), + 'pageIndex' => $this->request->param('pageIndex', 0), + 'pageSize' => $this->request->param('pageSize', 20) + ]; + + // 设置请求头 + $headerData = ['client:system']; + $header = setHeader($headerData, $authorization, 'plain'); + + // 发送请求获取群聊列表 + $result = requestCurl($this->baseUrl . 'api/WechatChatroom/pagelist', $params, 'GET', $header); + $response = handleApiResponse($result); + + // 保存数据到数据库 + if (!empty($response['results'])) { + foreach ($response['results'] as $item) { + $this->saveChatroom($item); + } + } + + return successJson($response); + } catch (\Exception $e) { + return errorJson('获取微信群聊列表失败:' . $e->getMessage()); + } + } + + /** + * 保存群聊数据到数据库 + * @param array $item 群聊数据 + */ + private function saveChatroom($item) + { + $data = [ + 'wechatAccountId' => $item['wechatAccountId'], + 'wechatAccountAlias' => $item['wechatAccountAlias'], + 'wechatAccountWechatId' => $item['wechatAccountWechatId'], + 'wechatAccountAvatar' => $item['wechatAccountAvatar'], + 'wechatAccountNickname' => $item['wechatAccountNickname'], + 'chatroomId' => $item['chatroomId'], + 'hasMe' => $item['hasMe'], + 'chatroomOwnerNickname' => $item['chatroomOwnerNickname'], + 'chatroomOwnerAvatar' => $item['chatroomOwnerAvatar'], + 'conRemark' => isset($item['conRemark']) ? $item['conRemark'] : '', + 'nickname' => $item['nickname'], + 'pyInitial' => $item['pyInitial'], + 'quanPin' => $item['quanPin'], + 'chatroomAvatar' => $item['chatroomAvatar'], + 'members' => is_array($item['members']) ? json_encode($item['members']) : json_encode([]), + 'isDeleted' => $item['isDeleted'], + 'deleteTime' => $item['deleteTime'], + 'createTime' => $item['createTime'], + 'accountId' => $item['accountId'], + 'accountUserName' => $item['accountUserName'], + 'accountRealName' => $item['accountRealName'], + 'accountNickname' => $item['accountNickname'], + 'groupId' => $item['groupId'] + ]; + + // 使用chatroomId和wechatAccountId的组合作为唯一性判断 + $chatroom = WechatChatroomModel::where([ + ['chatroomId', '=', $item['chatroomId']], + ['wechatAccountId', '=', $item['wechatAccountId']] + ])->find(); + + if ($chatroom) { + $chatroom->save($data); + } else { + WechatChatroomModel::create($data); + } + + // 同时保存群成员数据 + if (!empty($item['members'])) { + foreach ($item['members'] as $member) { + $this->saveChatroomMember($member, $item['chatroomId']); + } + } + } + + /** + * 获取群成员列表 + * @param string $wechatChatroomId 微信群ID + * @return \think\response\Json + */ + public function listChatroomMember($wechatChatroomId = '') + { + // 获取授权token + $authorization = trim($this->request->header('authorization', '')); + if (empty($authorization)) { + return errorJson('缺少授权信息'); + } + + if (empty($wechatChatroomId)) { + return errorJson('群ID不能为空'); + } + + try { + // 构建请求参数 + $params = [ + 'wechatChatroomId' => $wechatChatroomId + ]; + + // 设置请求头 + $headerData = ['client:system']; + $header = setHeader($headerData, $authorization, 'plain'); + + // 发送请求获取群成员列表 + $result = requestCurl($this->baseUrl . 'api/WechatChatroom/listChatroomMember', $params, 'GET', $header); + $response = handleApiResponse($result); + + // 保存数据到数据库 + if (!empty($response['results'])) { + foreach ($response['results'] as $item) { + $this->saveChatroomMember($item, $wechatChatroomId); + } + } + + return successJson($response); + } catch (\Exception $e) { + return errorJson('获取群成员列表失败:' . $e->getMessage()); + } + } + + /** + * 保存群成员数据到数据库 + * @param array $item 群成员数据 + * @param string $wechatChatroomId 微信群ID + */ + private function saveChatroomMember($item, $wechatChatroomId) + { + $data = [ + 'chatroomId' => $wechatChatroomId, + 'wechatId' => $item['wechatId'], + 'nickname' => $item['nickname'], + 'avatar' => $item['avatar'], + 'conRemark' => isset($item['conRemark']) ? $item['conRemark'] : '', + 'alias' => isset($item['alias']) ? $item['alias'] : '', + 'friendType' => isset($item['friendType']) ? $item['friendType'] : false + ]; + + // 使用chatroomId和wechatId的组合作为唯一性判断 + $member = WechatChatroomMemberModel::where([ + ['chatroomId', '=', $wechatChatroomId], + ['wechatId', '=', $item['wechatId']] + ])->find(); + + if ($member) { + $member->save($data); + } else { + WechatChatroomMemberModel::create($data); + } + } +} \ No newline at end of file diff --git a/Server/application/api/controller/WechatController.php b/Server/application/api/controller/WechatController.php index baaef0f6..469a37ee 100644 --- a/Server/application/api/controller/WechatController.php +++ b/Server/application/api/controller/WechatController.php @@ -57,7 +57,7 @@ class WechatController extends BaseController } } - public function getWechatAccountList() + public function getlist() { // 获取授权token $authorization = trim($this->request->header('authorization', '')); @@ -68,15 +68,15 @@ class WechatController extends BaseController try { // 构建请求参数 $params = [ - 'wechatAlive' => input('wechatAlive', ''), - 'keyword' => input('keyword', ''), - 'groupId' => input('groupId', ''), - 'departmentId' => input('departmentId', ''), - 'hasDevice' => input('hasDevice', ''), - 'deviceGroupId' => input('deviceGroupId', ''), - 'containSubDepartment' => input('containSubDepartment', 'false'), - 'pageIndex' => input('pageIndex', 0), - 'pageSize' => input('pageSize', 10) + 'wechatAlive' => $this->request->param('wechatAlive', ''), + 'keyword' => $this->request->param('keyword', ''), + 'groupId' => $this->request->param('groupId', ''), + 'departmentId' => $this->request->param('departmentId', ''), + 'hasDevice' => $this->request->param('hasDevice', ''), + 'deviceGroupId' => $this->request->param('deviceGroupId', ''), + 'containSubDepartment' => $this->request->param('containSubDepartment', 'false'), + 'pageIndex' => $this->request->param('pageIndex', 0), + 'pageSize' => $this->request->param('pageSize', 10) ]; // 设置请求头 diff --git a/Server/application/api/controller/WechatFriendController.php b/Server/application/api/controller/WechatFriendController.php index f8e845d9..4f1ca0bf 100644 --- a/Server/application/api/controller/WechatFriendController.php +++ b/Server/application/api/controller/WechatFriendController.php @@ -11,7 +11,7 @@ class WechatFriendController extends BaseController * 获取微信好友列表数据 * @return \think\response\Json */ - public function friendlistData() + public function getlist() { // 获取授权token $authorization = trim($this->request->header('authorization', '')); @@ -22,24 +22,18 @@ class WechatFriendController extends BaseController try { // 构建请求参数 $params = [ - 'accountKeyword' => input('accountKeyword', ''), - 'addFrom' => input('addFrom', []), + 'accountKeyword' => '', + 'addFrom' => '[]', 'allotAccountId' => input('allotAccountId', ''), - 'containAllLabel' => input('containAllLabel', false), - 'containSubDepartment' => input('containSubDepartment', false), - 'departmentId' => input('departmentId', ''), - 'extendFields' => input('extendFields', []), - 'friendKeyword' => input('friendKeyword', ''), - 'friendPhoneKeyword' => input('friendPhoneKeyword', ''), - 'friendPinYinKeyword' => input('friendPinYinKeyword', ''), - 'friendRegionKeyword' => input('friendRegionKeyword', ''), - 'friendRemarkKeyword' => input('friendRemarkKeyword', ''), - 'gender' => input('gender', ''), - 'groupId' => input('groupId', null), - 'isDeleted' => input('isDeleted', false), - 'isPass' => input('isPass', true), - 'keyword' => input('keyword', ''), - 'labels' => input('labels', []), + 'containSubDepartment' => false, + 'departmentId' => '', + 'extendFields' => '{}', + 'gender' => '', + 'groupId' => null, + 'isDeleted' => null, + 'isPass' => null, + 'keyword' => input('keyword', ''), + 'labels' => '[]', 'pageIndex' => input('pageIndex', 0), 'pageSize' => input('pageSize', 20), 'preFriendId' => input('preFriendId', ''), @@ -48,15 +42,15 @@ class WechatFriendController extends BaseController // 设置请求头 $headerData = ['client:system']; - $header = setHeader($headerData, $authorization, 'plain'); + $header = setHeader($headerData, $authorization); // 发送请求获取好友列表 - $result = requestCurl($this->baseUrl . 'api/WechatFriend/friendlistData', $params, 'GET', $header); + $result = requestCurl($this->baseUrl . 'api/WechatFriend/friendlistData', $params, 'POST', $header,'json'); $response = handleApiResponse($result); // 保存数据到数据库 - if (!empty($response['results'])) { - foreach ($response['results'] as $item) { + if (is_array($response)) { + foreach ($response as $item) { $this->saveFriend($item); } } @@ -106,9 +100,9 @@ class WechatFriendController extends BaseController 'additionalPicture' => $item['additionalPicture'], 'desc' => $item['desc'], 'country' => $item['country'], - 'province' => $item['province'], - 'city' => $item['city'], - 'createTime' => $item['createTime'] + 'province' => isset($item['province']) ? $item['province'] : '', + 'city' => isset($item['city']) ? $item['city'] : '', + 'createTime' =>isset($item['createTime']) ? $item['createTime'] : '', ]; // 使用三个字段的组合作为唯一性判断 diff --git a/Server/application/common/model/CompanyAccountModel.php b/Server/application/common/model/CompanyAccountModel.php index 5f8395c0..1775b8c7 100644 --- a/Server/application/common/model/CompanyAccountModel.php +++ b/Server/application/common/model/CompanyAccountModel.php @@ -1,11 +1,10 @@ order('id', 'DESC') - ->select() as $model) { - $assoc[$model->getAttr('id')] = $model->getAttr('number') - . ($model->isOnline() ? '[在线]' : '[离线]'); - } - } - return $assoc; - } - - /** - * 是否在线 - * - * @return string[] - */ - static public function isOnlineAssoc() { - return [ - static::IS_ONLINE_YES => '在线', - static::IS_ONLINE_NO => '离线', - ]; - } - - /** - * 获取状态 - * - * @return string[] - */ - static public function statusAssoc() { - return [ - static::STATUS_ACTIVE => '正常', - static::STATUS_DISABLE => '停用', - ]; - } - - /** - * 设备是否在线 - * - * @return bool - */ - public function isOnline() { - return $this->getAttr('is_online') == static::IS_ONLINE_YES - AND time() - $this->getAttr('active_time') <= static::ACTIVE_TIME; - } } \ No newline at end of file diff --git a/Server/application/common/model/FriendTaskModel.php b/Server/application/common/model/FriendTaskModel.php new file mode 100644 index 00000000..d51d3468 --- /dev/null +++ b/Server/application/common/model/FriendTaskModel.php @@ -0,0 +1,10 @@ +