代码优化
This commit is contained in:
@@ -38,7 +38,7 @@ class AccountController extends BaseController
|
||||
$params = [
|
||||
'showNormalAccount' => $this->request->param('showNormalAccount', ''),
|
||||
'keyword' => $this->request->param('keyword', ''),
|
||||
'departmentId' => $this->request->param('companyId', ''),
|
||||
'departmentId' => $this->request->param('departmentId', ''),
|
||||
'pageIndex' => !empty($pageIndex) ? $pageIndex : $this->request->param('pageIndex', 0),
|
||||
'pageSize' => !empty($pageSize) ? $pageSize : $this->request->param('pageSize',20)
|
||||
];
|
||||
@@ -59,8 +59,9 @@ class AccountController extends BaseController
|
||||
}
|
||||
|
||||
if($isJob){
|
||||
return json_encode(['code'=>200,'msg'=>'获取公司账号列表成功']);
|
||||
return json_encode(['code'=>200,'msg'=>'获取公司账号列表成功','data'=>$response]);
|
||||
}else{
|
||||
|
||||
return successJson($response);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
@@ -91,7 +92,7 @@ class AccountController extends BaseController
|
||||
$realName = $this->request->param('realName', '');
|
||||
$nickname = $this->request->param('nickname', '');
|
||||
$memo = $this->request->param('memo', '');
|
||||
$companyId = $this->request->param('companyId', 0);
|
||||
$departmentId = $this->request->param('departmentId', 0);
|
||||
|
||||
// 参数验证
|
||||
if (empty($userName)) {
|
||||
@@ -110,7 +111,7 @@ class AccountController extends BaseController
|
||||
if (empty($realName)) {
|
||||
return errorJson('真实姓名不能为空');
|
||||
}
|
||||
if (empty($companyId)) {
|
||||
if (empty($departmentId)) {
|
||||
return errorJson('公司ID不能为空');
|
||||
}
|
||||
|
||||
@@ -121,8 +122,8 @@ class AccountController extends BaseController
|
||||
'realName' => $realName,
|
||||
'nickname' => $nickname,
|
||||
'memo' => $memo,
|
||||
'departmentId' => $companyId,
|
||||
'departmentIdArr' => empty($companyId) ? [914] : [914, $companyId]
|
||||
'departmentId' => $departmentId,
|
||||
'departmentIdArr' => empty($departmentId) ? [914] : [914, $departmentId]
|
||||
];
|
||||
|
||||
// 设置请求头
|
||||
@@ -148,12 +149,16 @@ class AccountController extends BaseController
|
||||
* 获取部门列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getDepartmentList()
|
||||
public function getDepartmentList($isJob = false)
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
return errorJson('缺少授权信息');
|
||||
if($isJob){
|
||||
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
|
||||
}else{
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -173,9 +178,17 @@ class AccountController extends BaseController
|
||||
$this->processDepartments($response);
|
||||
}
|
||||
|
||||
return successJson($response, '获取部门列表成功');
|
||||
if($isJob){
|
||||
return json_encode(['code'=>200,'msg'=>'获取部门列表成功','data'=>$response]);
|
||||
}else{
|
||||
return successJson($response, '获取部门列表成功');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return errorJson('获取部门列表失败:' . $e->getMessage());
|
||||
if($isJob){
|
||||
return json_encode(['code'=>500,'msg'=>'获取部门列表失败:' . $e->getMessage()]);
|
||||
}else{
|
||||
return errorJson('获取部门列表失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,7 +424,7 @@ class AccountController extends BaseController
|
||||
$deleteTime = isset($item['deleteTime']) ? strtotime($item['deleteTime']) : null;
|
||||
|
||||
$data = [
|
||||
'tenantId' => $item['id'],
|
||||
'id' => $item['id'],
|
||||
'accountType' => isset($item['accountType']) ? $item['accountType'] : 0,
|
||||
'status' => isset($item['status']) ? $item['status'] : 0,
|
||||
'tenantId' => isset($item['tenantId']) ? $item['tenantId'] : 0,
|
||||
@@ -425,9 +438,9 @@ class AccountController extends BaseController
|
||||
'creator' => isset($item['creator']) ? $item['creator'] : 0,
|
||||
'creatorUserName' => isset($item['creatorUserName']) ? $item['creatorUserName'] : '',
|
||||
'creatorRealName' => isset($item['creatorRealName']) ? $item['creatorRealName'] : '',
|
||||
'companyId' => isset($item['departmentId']) ? $item['departmentId'] : 0,
|
||||
'departmentId' => isset($item['departmentId']) ? $item['departmentId'] : 0,
|
||||
'departmentName' => isset($item['departmentName']) ? $item['departmentName'] : '',
|
||||
'privilegeIds' => isset($item['privilegeIds']) ? $item['privilegeIds'] : [],
|
||||
'privilegeIds' => isset($item['privilegeIds']) ? json_encode($item['privilegeIds']) : json_encode([]),
|
||||
'alive' => isset($item['alive']) ? $item['alive'] : false,
|
||||
'hasXiakeAccount' => isset($item['hasXiakeAccount']) ? $item['hasXiakeAccount'] : false,
|
||||
'isDeleted' => isset($item['isDeleted']) ? $item['isDeleted'] : false,
|
||||
@@ -435,7 +448,7 @@ class AccountController extends BaseController
|
||||
];
|
||||
|
||||
// 使用tenantId作为唯一性判断
|
||||
$account = CompanyAccountModel::where('tenantId', $item['id'])->find();
|
||||
$account = CompanyAccountModel::where('id', $item['id'])->find();
|
||||
if ($account) {
|
||||
$account->save($data);
|
||||
} else {
|
||||
|
||||
@@ -10,8 +10,13 @@ use Endroid\QrCode\ErrorCorrectionLevel;
|
||||
|
||||
class DeviceController extends BaseController
|
||||
{
|
||||
/************************ 设备管理相关接口 ************************/
|
||||
|
||||
/**
|
||||
* 获取设备列表
|
||||
* @param string $pageIndex 页码
|
||||
* @param string $pageSize 每页数量
|
||||
* @param bool $isJob 是否为定时任务调用
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getlist($pageIndex = '',$pageSize = '',$isJob = false)
|
||||
@@ -79,65 +84,6 @@ class DeviceController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存设备数据到数据库
|
||||
* @param array $item 设备数据
|
||||
*/
|
||||
private function saveDevice($item)
|
||||
{
|
||||
$data = [
|
||||
'id' => isset($item['id']) ? $item['id'] : '',
|
||||
'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,
|
||||
'companyId' => 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('id', $item['id'])->find();
|
||||
|
||||
if ($device) {
|
||||
$device->save($data);
|
||||
} else {
|
||||
|
||||
// autoLike:自动点赞
|
||||
// momentsSync:朋友圈同步
|
||||
// autoCustomerDev:自动开发客户
|
||||
// groupMessageDeliver:群消息推送
|
||||
// autoGroup:自动建群
|
||||
|
||||
$data['taskConfig'] = json_encode([
|
||||
'autoLike' => true,
|
||||
'momentsSync' => true,
|
||||
'autoCustomerDev' => true,
|
||||
'groupMessageDeliver' => true,
|
||||
'autoGroup' => true,
|
||||
]);
|
||||
DeviceModel::create($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成设备二维码
|
||||
* @param int $accountId 账号ID
|
||||
@@ -184,7 +130,68 @@ class DeviceController extends BaseController
|
||||
return errorJson('生成设备二维码失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************ 私有辅助方法 ************************/
|
||||
|
||||
/**
|
||||
* 保存设备数据到数据库
|
||||
* @param array $item 设备数据
|
||||
*/
|
||||
private function saveDevice($item)
|
||||
{
|
||||
$data = [
|
||||
'id' => isset($item['id']) ? $item['id'] : '',
|
||||
'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('id', $item['id'])->find();
|
||||
|
||||
if ($device) {
|
||||
$device->save($data);
|
||||
} else {
|
||||
|
||||
// autoLike:自动点赞
|
||||
// momentsSync:朋友圈同步
|
||||
// autoCustomerDev:自动开发客户
|
||||
// groupMessageDeliver:群消息推送
|
||||
// autoGroup:自动建群
|
||||
|
||||
$data['taskConfig'] = json_encode([
|
||||
'autoLike' => true,
|
||||
'momentsSync' => true,
|
||||
'autoCustomerDev' => true,
|
||||
'groupMessageDeliver' => true,
|
||||
'autoGroup' => true,
|
||||
]);
|
||||
DeviceModel::create($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成二维码图片(base64格式)
|
||||
* @param string $data 二维码数据
|
||||
|
||||
@@ -7,11 +7,16 @@ use think\facade\Request;
|
||||
|
||||
class FriendTaskController extends BaseController
|
||||
{
|
||||
/************************ 好友任务管理相关接口 ************************/
|
||||
|
||||
/**
|
||||
* 获取添加好友记录列表
|
||||
* @param int $pageIndex 页码
|
||||
* @param int $pageSize 每页数量
|
||||
* @param bool $isJob 是否为定时任务调用
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getlist($pageIndex,$pageSize,$isJob = false)
|
||||
public function getlist($pageIndex, $pageSize, $isJob = false)
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
@@ -113,6 +118,8 @@ class FriendTaskController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/************************ 私有辅助方法 ************************/
|
||||
|
||||
/**
|
||||
* 保存添加好友记录到数据库
|
||||
* @param array $item 添加好友记录数据
|
||||
|
||||
@@ -7,7 +7,8 @@ use think\facade\Request;
|
||||
|
||||
class MessageController extends BaseController
|
||||
{
|
||||
|
||||
/************************ 好友消息相关接口 ************************/
|
||||
|
||||
/**
|
||||
* 获取微信好友列表
|
||||
* @return \think\response\Json
|
||||
@@ -114,55 +115,65 @@ class MessageController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 保存消息记录到数据库
|
||||
* @param array $item 消息记录数据
|
||||
* 用户聊天记录
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
private function saveMessage($item)
|
||||
public function getMessageList()
|
||||
{
|
||||
// 检查消息是否已存在
|
||||
$exists = WechatMessageModel::where('id', $item['id']) ->find();
|
||||
|
||||
// 如果消息已存在,直接返回
|
||||
if ($exists) {
|
||||
return;
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
|
||||
// 将毫秒时间戳转换为秒级时间戳
|
||||
$createTime = isset($item['createTime']) ? strtotime($item['createTime']) : null;
|
||||
$deleteTime = !empty($item['isDeleted']) ? strtotime($item['deleteTime']) : null;
|
||||
$wechatTime = isset($item['wechatTime']) ? floor($item['wechatTime'] / 1000) : null;
|
||||
try {
|
||||
// 构建请求参数
|
||||
$params = [
|
||||
'keyword' => $this->request->param('keyword', ''),
|
||||
'msgType' => $this->request->param('msgType', ''),
|
||||
'accountId' => $this->request->param('accountId', ''),
|
||||
'count' => $this->request->param('count', 100),
|
||||
'messageId' => $this->request->param('messageId', ''),
|
||||
'olderData' => $this->request->param('olderData', true),
|
||||
'wechatAccountId' => $this->request->param('wechatAccountId', ''),
|
||||
'wechatFriendId' => $this->request->param('wechatFriendId', ''),
|
||||
'from' => $this->request->param('from', ''),
|
||||
'to' => $this->request->param('to', ''),
|
||||
'searchFrom' => $this->request->param('searchFrom', 'admin')
|
||||
];
|
||||
|
||||
$data = [
|
||||
'id' => $item['id'],
|
||||
'type' => 1,
|
||||
'accountId' => $item['accountId'],
|
||||
'content' => $item['content'],
|
||||
'createTime' => $createTime,
|
||||
'deleteTime' => $deleteTime,
|
||||
'isDeleted' => $item['isDeleted'] ?? false,
|
||||
'isSend' => $item['isSend'] ?? true,
|
||||
'msgId' => $item['msgId'],
|
||||
'msgSubType' => $item['msgSubType'] ?? 0,
|
||||
'msgSvrId' => $item['msgSvrId'] ?? '',
|
||||
'msgType' => $item['msgType'],
|
||||
'origin' => $item['origin'] ?? 0,
|
||||
'recallId' => $item['recallId'] ?? false,
|
||||
'sendStatus' => $item['sendStatus'] ?? 0,
|
||||
'synergyAccountId' => $item['synergyAccountId'] ?? 0,
|
||||
'tenantId' => $item['tenantId'],
|
||||
'wechatAccountId' => $item['wechatAccountId'],
|
||||
'wechatFriendId' => $item['wechatFriendId'],
|
||||
'wechatTime' => $wechatTime
|
||||
];
|
||||
// 参数验证
|
||||
if (empty($params['wechatAccountId'])) {
|
||||
return errorJson('微信账号ID不能为空');
|
||||
}
|
||||
if (empty($params['wechatFriendId'])) {
|
||||
return errorJson('好友ID不能为空');
|
||||
}
|
||||
|
||||
// 创建新记录
|
||||
WechatMessageModel::create($data);
|
||||
// 设置请求头
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization, 'json');
|
||||
|
||||
// 发送请求获取聊天记录
|
||||
$result = requestCurl($this->baseUrl . 'api/FriendMessage/searchMessage', $params, 'GET', $header, 'json');
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 保存数据到数据库
|
||||
if (!empty($response)) {
|
||||
foreach ($response as $item) {
|
||||
$this->saveMessage($item);
|
||||
}
|
||||
}
|
||||
|
||||
return successJson($response);
|
||||
} catch (\Exception $e) {
|
||||
return errorJson('获取聊天记录失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/************************ 群聊消息相关接口 ************************/
|
||||
|
||||
/**
|
||||
* 获取微信群聊列表
|
||||
* @return \think\response\Json
|
||||
@@ -268,8 +279,114 @@ class MessageController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取群聊消息列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getChatroomMessages()
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
// 构建请求参数
|
||||
$params = [
|
||||
'keyword' => $this->request->param('keyword', ''),
|
||||
'msgType' => $this->request->param('msgType', ''),
|
||||
'accountId' => $this->request->param('accountId', ''),
|
||||
'count' => $this->request->param('count', 100),
|
||||
'messageId' => $this->request->param('messageId', ''),
|
||||
'olderData' => $this->request->param('olderData', true),
|
||||
'wechatId' => $this->request->param('wechatId', ''),
|
||||
'wechatAccountId' => $this->request->param('wechatAccountId', ''),
|
||||
'wechatChatroomId' => $this->request->param('wechatChatroomId', ''),
|
||||
'from' => $this->request->param('from', strtotime(date('Y-m-d 00:00:00', strtotime('-1 days')))),
|
||||
'to' => $this->request->param('to', strtotime(date('Y-m-d 00:00:00'))),
|
||||
'searchFrom' => $this->request->param('searchFrom', 'admin')
|
||||
];
|
||||
|
||||
// 参数验证
|
||||
if (empty($params['wechatAccountId'])) {
|
||||
return errorJson('微信账号ID不能为空');
|
||||
}
|
||||
if (empty($params['wechatChatroomId'])) {
|
||||
return errorJson('群聊ID不能为空');
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization, 'json');
|
||||
|
||||
// 发送请求获取群聊消息
|
||||
$result = requestCurl($this->baseUrl . 'api/ChatroomMessage/searchMessage', $params, 'GET', $header, 'json');
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 保存数据到数据库
|
||||
if (!empty($response)) {
|
||||
foreach ($response as $item) {
|
||||
$res = $this->saveChatroomMessage($item);
|
||||
if(!$res){
|
||||
return errorJson('保存群聊消息失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return successJson($response);
|
||||
} catch (\Exception $e) {
|
||||
return errorJson('获取群聊消息失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/************************ 私有辅助方法 ************************/
|
||||
|
||||
/**
|
||||
* 保存消息记录到数据库
|
||||
* @param array $item 消息记录数据
|
||||
*/
|
||||
private function saveMessage($item)
|
||||
{
|
||||
// 检查消息是否已存在
|
||||
$exists = WechatMessageModel::where('id', $item['id']) ->find();
|
||||
|
||||
// 如果消息已存在,直接返回
|
||||
if ($exists) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 将毫秒时间戳转换为秒级时间戳
|
||||
$createTime = isset($item['createTime']) ? strtotime($item['createTime']) : null;
|
||||
$deleteTime = !empty($item['isDeleted']) ? strtotime($item['deleteTime']) : null;
|
||||
$wechatTime = isset($item['wechatTime']) ? floor($item['wechatTime'] / 1000) : null;
|
||||
|
||||
$data = [
|
||||
'id' => $item['id'],
|
||||
'type' => 1,
|
||||
'accountId' => $item['accountId'],
|
||||
'content' => $item['content'],
|
||||
'createTime' => $createTime,
|
||||
'deleteTime' => $deleteTime,
|
||||
'isDeleted' => $item['isDeleted'] ?? false,
|
||||
'isSend' => $item['isSend'] ?? true,
|
||||
'msgId' => $item['msgId'],
|
||||
'msgSubType' => $item['msgSubType'] ?? 0,
|
||||
'msgSvrId' => $item['msgSvrId'] ?? '',
|
||||
'msgType' => $item['msgType'],
|
||||
'origin' => $item['origin'] ?? 0,
|
||||
'recallId' => $item['recallId'] ?? false,
|
||||
'sendStatus' => $item['sendStatus'] ?? 0,
|
||||
'synergyAccountId' => $item['synergyAccountId'] ?? 0,
|
||||
'tenantId' => $item['tenantId'],
|
||||
'wechatAccountId' => $item['wechatAccountId'],
|
||||
'wechatFriendId' => $item['wechatFriendId'],
|
||||
'wechatTime' => $wechatTime
|
||||
];
|
||||
|
||||
// 创建新记录
|
||||
WechatMessageModel::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存群聊消息记录到数据库
|
||||
@@ -354,126 +471,4 @@ class MessageController extends BaseController
|
||||
// 如果没有匹配到格式,则返回原始内容
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户聊天记录
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getMessageList()
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
|
||||
try {
|
||||
// 构建请求参数
|
||||
$params = [
|
||||
'keyword' => $this->request->param('keyword', ''),
|
||||
'msgType' => $this->request->param('msgType', ''),
|
||||
'accountId' => $this->request->param('accountId', ''),
|
||||
'count' => $this->request->param('count', 100),
|
||||
'messageId' => $this->request->param('messageId', ''),
|
||||
'olderData' => $this->request->param('olderData', true),
|
||||
'wechatAccountId' => $this->request->param('wechatAccountId', ''),
|
||||
'wechatFriendId' => $this->request->param('wechatFriendId', ''),
|
||||
'from' => $this->request->param('from', ''),
|
||||
'to' => $this->request->param('to', ''),
|
||||
'searchFrom' => $this->request->param('searchFrom', 'admin')
|
||||
];
|
||||
|
||||
// 参数验证
|
||||
if (empty($params['wechatAccountId'])) {
|
||||
return errorJson('微信账号ID不能为空');
|
||||
}
|
||||
if (empty($params['wechatFriendId'])) {
|
||||
return errorJson('好友ID不能为空');
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization, 'json');
|
||||
|
||||
// 发送请求获取聊天记录
|
||||
$result = requestCurl($this->baseUrl . 'api/FriendMessage/searchMessage', $params, 'GET', $header, 'json');
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 保存数据到数据库
|
||||
if (!empty($response)) {
|
||||
foreach ($response as $item) {
|
||||
$this->saveMessage($item);
|
||||
}
|
||||
}
|
||||
|
||||
return successJson($response);
|
||||
} catch (\Exception $e) {
|
||||
return errorJson('获取聊天记录失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取群聊消息列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getChatroomMessages()
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
|
||||
try {
|
||||
// 构建请求参数
|
||||
$params = [
|
||||
'keyword' => $this->request->param('keyword', ''),
|
||||
'msgType' => $this->request->param('msgType', ''),
|
||||
'accountId' => $this->request->param('accountId', ''),
|
||||
'count' => $this->request->param('count', 100),
|
||||
'messageId' => $this->request->param('messageId', ''),
|
||||
'olderData' => $this->request->param('olderData', true),
|
||||
'wechatId' => $this->request->param('wechatId', ''),
|
||||
'wechatAccountId' => $this->request->param('wechatAccountId', ''),
|
||||
'wechatChatroomId' => $this->request->param('wechatChatroomId', ''),
|
||||
'from' => $this->request->param('from', strtotime(date('Y-m-d 00:00:00', strtotime('-1 days')))),
|
||||
'to' => $this->request->param('to', strtotime(date('Y-m-d 00:00:00'))),
|
||||
'searchFrom' => $this->request->param('searchFrom', 'admin')
|
||||
];
|
||||
|
||||
// 参数验证
|
||||
if (empty($params['wechatAccountId'])) {
|
||||
return errorJson('微信账号ID不能为空');
|
||||
}
|
||||
if (empty($params['wechatChatroomId'])) {
|
||||
return errorJson('群聊ID不能为空');
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization, 'json');
|
||||
|
||||
// 发送请求获取群聊消息
|
||||
$result = requestCurl($this->baseUrl . 'api/ChatroomMessage/searchMessage', $params, 'GET', $header, 'json');
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 保存数据到数据库
|
||||
if (!empty($response)) {
|
||||
foreach ($response as $item) {
|
||||
$res = $this->saveChatroomMessage($item);
|
||||
if(!$res){
|
||||
return errorJson('保存群聊消息失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return successJson($response);
|
||||
} catch (\Exception $e) {
|
||||
return errorJson('获取群聊消息失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,8 @@ use think\facade\Request;
|
||||
|
||||
class MomentsController extends BaseController
|
||||
{
|
||||
/************************ 朋友圈发布相关接口 ************************/
|
||||
|
||||
/**
|
||||
* 发布朋友圈
|
||||
* @return \think\response\Json
|
||||
@@ -99,7 +101,9 @@ class MomentsController extends BaseController
|
||||
return errorJson('发布朋友圈失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************ 朋友圈任务管理相关接口 ************************/
|
||||
|
||||
/**
|
||||
* 获取朋友圈任务列表
|
||||
* @return \think\response\Json
|
||||
|
||||
@@ -13,11 +13,11 @@ class WechatChatroomController extends BaseController
|
||||
* 获取微信群聊列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getlist($pageIndex = '',$pageSize = '',$authorization = '',$isJob = false)
|
||||
public function getlist($pageIndex = '',$pageSize = '',$isJob = false)
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = !empty($authorization) ? $authorization : trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
if($isJob){
|
||||
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
|
||||
}else{
|
||||
|
||||
@@ -7,66 +7,20 @@ use app\api\model\WechatAccountModel;
|
||||
class WechatController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 保存微信账号数据到数据库
|
||||
* @param array $item 微信账号数据
|
||||
* 获取微信账号列表
|
||||
* @param string $pageIndex 页码
|
||||
* @param string $pageSize 每页大小
|
||||
* @param bool $isJob 是否为任务调用
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
private function saveWechatAccount($item)
|
||||
{
|
||||
$data = [
|
||||
'id' => $item['id'],
|
||||
'wechatId' => $item['wechatId'],
|
||||
'deviceAccountId' => $item['deviceAccountId'],
|
||||
'imei' => $item['imei'],
|
||||
'deviceMemo' => $item['deviceMemo'],
|
||||
'accountUserName' => $item['accountUserName'],
|
||||
'accountRealName' => $item['accountRealName'],
|
||||
'accountNickname' => $item['accountNickname'],
|
||||
'keFuAlive' => $item['keFuAlive'],
|
||||
'deviceAlive' => $item['deviceAlive'],
|
||||
'wechatAlive' => $item['wechatAlive'],
|
||||
'yesterdayMsgCount' => $item['yesterdayMsgCount'],
|
||||
'sevenDayMsgCount' => $item['sevenDayMsgCount'],
|
||||
'thirtyDayMsgCount' => $item['thirtyDayMsgCount'],
|
||||
'totalFriend' => $item['totalFriend'],
|
||||
'maleFriend' => $item['maleFriend'],
|
||||
'femaleFriend' => $item['femaleFriend'],
|
||||
'wechatGroupName' => $item['wechatGroupName'],
|
||||
'tenantId' => $item['tenantId'],
|
||||
'nickname' => $item['nickname'],
|
||||
'alias' => $item['alias'],
|
||||
'avatar' => $item['avatar'],
|
||||
'gender' => $item['gender'],
|
||||
'region' => $item['region'],
|
||||
'signature' => $item['signature'],
|
||||
'bindQQ' => $item['bindQQ'],
|
||||
'bindEmail' => $item['bindEmail'],
|
||||
'bindMobile' => $item['bindMobile'],
|
||||
'currentDeviceId' => $item['currentDeviceId'],
|
||||
'isDeleted' => $item['isDeleted'],
|
||||
'deleteTime' => $item['deleteTime'],
|
||||
'groupId' => $item['groupId'],
|
||||
'memo' => $item['memo'],
|
||||
'wechatVersion' => $item['wechatVersion'],
|
||||
'labels' => !empty($item['labels']) ? json_encode($item['labels']) : json_encode([]),
|
||||
'updateTime' => time()
|
||||
];
|
||||
|
||||
$account = WechatAccountModel::where('id', $item['id'])->find();
|
||||
if ($account) {
|
||||
$account->save($data);
|
||||
} else {
|
||||
WechatAccountModel::create($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function getlist($pageIndex = '',$pageSize = '',$isJob = false)
|
||||
public function getlist($pageIndex = '', $pageSize = '', $isJob = false)
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
if($isJob){
|
||||
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
|
||||
}else{
|
||||
if ($isJob) {
|
||||
return json_encode(['code' => 500, 'msg' => '缺少授权信息']);
|
||||
} else {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
}
|
||||
@@ -99,17 +53,75 @@ class WechatController extends BaseController
|
||||
$this->saveWechatAccount($item);
|
||||
}
|
||||
}
|
||||
if($isJob){
|
||||
return json_encode(['code'=>200,'msg'=>'获取微信账号列表成功','data'=>$response]);
|
||||
}else{
|
||||
|
||||
if ($isJob) {
|
||||
return json_encode(['code' => 200, 'msg' => '获取微信账号列表成功', 'data' => $response]);
|
||||
} else {
|
||||
return successJson($response);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
if($isJob){
|
||||
return json_encode(['code'=>500,'msg'=>'获取微信账号列表失败:' . $e->getMessage()]);
|
||||
}else{
|
||||
if ($isJob) {
|
||||
return json_encode(['code' => 500, 'msg' => '获取微信账号列表失败:' . $e->getMessage()]);
|
||||
} else {
|
||||
return errorJson('获取微信账号列表失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存微信账号数据到数据库
|
||||
* @param array $item 微信账号数据
|
||||
*/
|
||||
private function saveWechatAccount($item)
|
||||
{
|
||||
$createTime = isset($item['createTime']) ? strtotime($item['createTime']) : 0;
|
||||
$deleteTime = !empty($item['isDeleted']) ? strtotime($item['deleteTime']) : 0;
|
||||
|
||||
$data = [
|
||||
'id' => $item['id'],
|
||||
'wechatId' => $item['wechatId'],
|
||||
'deviceAccountId' => $item['deviceAccountId'],
|
||||
'imei' => $item['imei'],
|
||||
'deviceMemo' => $item['deviceMemo'],
|
||||
'accountUserName' => $item['accountUserName'],
|
||||
'accountRealName' => $item['accountRealName'],
|
||||
'accountNickname' => $item['accountNickname'],
|
||||
'keFuAlive' => $item['keFuAlive'],
|
||||
'deviceAlive' => $item['deviceAlive'],
|
||||
'wechatAlive' => $item['wechatAlive'],
|
||||
'yesterdayMsgCount' => $item['yesterdayMsgCount'],
|
||||
'sevenDayMsgCount' => $item['sevenDayMsgCount'],
|
||||
'thirtyDayMsgCount' => $item['thirtyDayMsgCount'],
|
||||
'totalFriend' => $item['totalFriend'],
|
||||
'maleFriend' => $item['maleFriend'],
|
||||
'femaleFriend' => $item['femaleFriend'],
|
||||
'wechatGroupName' => $item['wechatGroupName'],
|
||||
'tenantId' => $item['tenantId'],
|
||||
'nickname' => $item['nickname'],
|
||||
'alias' => $item['alias'],
|
||||
'avatar' => $item['avatar'],
|
||||
'gender' => $item['gender'],
|
||||
'region' => $item['region'],
|
||||
'signature' => $item['signature'],
|
||||
'bindQQ' => $item['bindQQ'],
|
||||
'bindEmail' => $item['bindEmail'],
|
||||
'bindMobile' => $item['bindMobile'],
|
||||
'currentDeviceId' => $item['currentDeviceId'],
|
||||
'isDeleted' => $item['isDeleted'],
|
||||
'groupId' => $item['groupId'],
|
||||
'memo' => $item['memo'],
|
||||
'wechatVersion' => $item['wechatVersion'],
|
||||
'labels' => !empty($item['labels']) ? json_encode($item['labels']) : json_encode([]),
|
||||
'createTime' => $createTime,
|
||||
'deleteTime' => $deleteTime,
|
||||
'updateTime' => time()
|
||||
];
|
||||
|
||||
$account = WechatAccountModel::where('id', $item['id'])->find();
|
||||
if ($account) {
|
||||
$account->save($data);
|
||||
} else {
|
||||
WechatAccountModel::create($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,19 +10,23 @@ class WechatFriendController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取微信好友列表数据
|
||||
* @param string $pageIndex 页码
|
||||
* @param string $pageSize 每页大小
|
||||
* @param string $preFriendId 上一个好友ID
|
||||
* @param bool $isJob 是否为任务调用
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getlist($pageIndex = '',$pageSize = '',$preFriendId = '',$isJob = false)
|
||||
public function getlist($pageIndex = '', $pageSize = '', $preFriendId = '', $isJob = false)
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
if($isJob){
|
||||
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
|
||||
}else{
|
||||
return errorJson('缺少授权信息');
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
if ($isJob) {
|
||||
return json_encode(['code' => 500, 'msg' => '缺少授权信息']);
|
||||
} else {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// 构建请求参数
|
||||
@@ -37,19 +41,20 @@ class WechatFriendController extends BaseController
|
||||
'groupId' => null,
|
||||
'isDeleted' => null,
|
||||
'isPass' => null,
|
||||
'keyword' => input('keyword', ''),
|
||||
'keyword' => input('keyword', ''),
|
||||
'labels' => '[]',
|
||||
'pageIndex' => !empty($pageIndex) ? $pageIndex : input('pageIndex', 0),
|
||||
'pageSize' => !empty($pageSize) ? $pageSize : input('pageSize', 20),
|
||||
'preFriendId' => !empty($preFriendId) ? $preFriendId : input('preFriendId', ''),
|
||||
'wechatAccountKeyword' => input('wechatAccountKeyword', '')
|
||||
];
|
||||
|
||||
// 设置请求头
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization);
|
||||
|
||||
// 发送请求获取好友列表
|
||||
$result = requestCurl($this->baseUrl . 'api/WechatFriend/friendlistData', $params, 'POST', $header,'json');
|
||||
$result = requestCurl($this->baseUrl . 'api/WechatFriend/friendlistData', $params, 'POST', $header, 'json');
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 保存数据到数据库
|
||||
@@ -59,17 +64,16 @@ class WechatFriendController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
if($isJob){
|
||||
return json_encode(['code'=>200,'msg'=>'success','data'=>$response]);
|
||||
}else{
|
||||
if ($isJob) {
|
||||
return json_encode(['code' => 200, 'msg' => 'success', 'data' => $response]);
|
||||
} else {
|
||||
return successJson($response);
|
||||
}
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
if($isJob){
|
||||
return json_encode(['code'=>500,'msg'=>'获取微信好友列表失败:' . $e->getMessage()]);
|
||||
}else{
|
||||
if ($isJob) {
|
||||
return json_encode(['code' => 500, 'msg' => '获取微信好友列表失败:' . $e->getMessage()]);
|
||||
} else {
|
||||
return errorJson('获取微信好友列表失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
@@ -117,12 +121,12 @@ class WechatFriendController extends BaseController
|
||||
'country' => $item['country'],
|
||||
'privince' => isset($item['privince']) ? $item['privince'] : '',
|
||||
'city' => isset($item['city']) ? $item['city'] : '',
|
||||
'createTime' =>isset($item['createTime']) ? $item['createTime'] : '',
|
||||
'createTime' => isset($item['createTime']) ? $item['createTime'] : '',
|
||||
'updateTime' => time()
|
||||
];
|
||||
|
||||
// 使用三个字段的组合作为唯一性判断
|
||||
$friend = WechatFriendModel::where('id',$item['id'])->find();
|
||||
// 使用ID作为唯一性判断
|
||||
$friend = WechatFriendModel::where('id', $item['id'])->find();
|
||||
|
||||
if ($friend) {
|
||||
$friend->save($data);
|
||||
|
||||
@@ -7,5 +7,5 @@ use think\Model;
|
||||
class CompanyAccountModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'company_account';
|
||||
protected $table = 's2_company_account';
|
||||
}
|
||||
@@ -6,5 +6,5 @@ use think\Model;
|
||||
|
||||
class CompanyModel extends Model {
|
||||
// 设置表名
|
||||
protected $name = 'company';
|
||||
protected $table = 's2_department';
|
||||
}
|
||||
@@ -6,5 +6,5 @@ use think\Model;
|
||||
|
||||
class DeviceModel extends Model {
|
||||
// 设置表名
|
||||
protected $name = 'device';
|
||||
protected $table = 's2_device';
|
||||
}
|
||||
@@ -7,5 +7,5 @@ use think\Model;
|
||||
class FriendTaskModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'friend_task';
|
||||
protected $table = 's2_friend_task';
|
||||
}
|
||||
@@ -7,5 +7,5 @@ use think\Model;
|
||||
class WechatAccountModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'wechat_account';
|
||||
protected $table = 's2_wechat_account';
|
||||
}
|
||||
@@ -7,5 +7,5 @@ use think\Model;
|
||||
class WechatChatroomMemberModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'wechat_chatroom_member';
|
||||
protected $table = 's2_wechat_chatroom_member';
|
||||
}
|
||||
@@ -7,5 +7,5 @@ use think\Model;
|
||||
class WechatChatroomModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'wechat_chatroom';
|
||||
protected $table = 's2_wechat_chatroom';
|
||||
}
|
||||
@@ -7,5 +7,5 @@ use think\Model;
|
||||
class WechatFriendModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'wechat_friend';
|
||||
protected $table = 's2_wechat_friend';
|
||||
}
|
||||
@@ -7,5 +7,5 @@ use think\Model;
|
||||
class WechatMessageModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'wechat_message';
|
||||
protected $table = 's2_wechat_message';
|
||||
}
|
||||
Reference in New Issue
Block a user