微信底层代码提交
This commit is contained in:
@@ -12,4 +12,8 @@ hostport = 3306
|
||||
prefix = tk_
|
||||
|
||||
[api]
|
||||
wechat_url = https://s2.siyuguanli.com:9991/
|
||||
wechat_url = https://s2.siyuguanli.com:9991/
|
||||
guid = 5E2C38F5A275450D935F3ECEC076124E
|
||||
deviceSocketHost = s2.siyuguanli.com:9992
|
||||
username = kr_xf2
|
||||
password = kr123456
|
||||
96
Server/application/api/controller/AccountController.php
Normal file
96
Server/application/api/controller/AccountController.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\model\CompanyAccountModel;
|
||||
use think\facade\Request;
|
||||
|
||||
class AccountController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取公司账号列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getlist()
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
183
Server/application/api/controller/DeviceController.php
Normal file
183
Server/application/api/controller/DeviceController.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\model\DeviceModel;
|
||||
use think\facade\Request;
|
||||
use think\facade\Env;
|
||||
use Endroid\QrCode\QrCode;
|
||||
use Endroid\QrCode\ErrorCorrectionLevel;
|
||||
|
||||
class DeviceController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取设备列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getlist()
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->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;
|
||||
}
|
||||
}
|
||||
93
Server/application/api/controller/FriendTaskController.php
Normal file
93
Server/application/api/controller/FriendTaskController.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\model\FriendTaskModel;
|
||||
use think\facade\Request;
|
||||
|
||||
class FriendTaskController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取添加好友记录列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getlist()
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
|
||||
183
Server/application/api/controller/WechatChatroomController.php
Normal file
183
Server/application/api/controller/WechatChatroomController.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\model\WechatChatroomModel;
|
||||
use app\common\model\WechatChatroomMemberModel;
|
||||
use think\facade\Request;
|
||||
|
||||
class WechatChatroomController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取微信群聊列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getlist()
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
];
|
||||
|
||||
// 设置请求头
|
||||
|
||||
@@ -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'] : '',
|
||||
];
|
||||
|
||||
// 使用三个字段的组合作为唯一性判断
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use think\Model;
|
||||
|
||||
class CompanyAccountModel extends Model {
|
||||
|
||||
}
|
||||
class CompanyAccountModel extends Model
|
||||
{
|
||||
|
||||
}
|
||||
@@ -6,64 +6,4 @@ use think\Model;
|
||||
|
||||
class DeviceModel extends Model {
|
||||
|
||||
const ACTIVE_TIME = 60;
|
||||
|
||||
const IS_ONLINE_NO = 0;
|
||||
const IS_ONLINE_YES = 10;
|
||||
|
||||
const STATUS_ACTIVE = 0;
|
||||
const STATUS_DISABLE = 99;
|
||||
|
||||
/**
|
||||
* 获取关联数组
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static public function assoc() {
|
||||
static $assoc = NULL;
|
||||
if (is_null($assoc)) {
|
||||
$assoc = [];
|
||||
foreach (static::where(1)
|
||||
->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;
|
||||
}
|
||||
}
|
||||
10
Server/application/common/model/FriendTaskModel.php
Normal file
10
Server/application/common/model/FriendTaskModel.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class FriendTaskModel extends Model
|
||||
{
|
||||
|
||||
}
|
||||
@@ -6,14 +6,5 @@ use think\Model;
|
||||
|
||||
class WechatAccountModel extends Model
|
||||
{
|
||||
protected $table = 'wechat_account';
|
||||
protected $pk = 'id';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
// 数据表字段采用驼峰式命名
|
||||
protected $convertNameToCamel = true;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class WechatChatroomMemberModel extends Model
|
||||
{
|
||||
|
||||
}
|
||||
10
Server/application/common/model/WechatChatroomModel.php
Normal file
10
Server/application/common/model/WechatChatroomModel.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class WechatChatroomModel extends Model
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user