Merge branch 'develop' into yongpxu-dev

# Conflicts:
#	Server/application/command/SwitchFriendsCommand.php   resolved by develop version
#	Server/application/cunkebao/controller/ContentLibraryController.php   resolved by develop version
#	Server/application/cunkebao/controller/WorkbenchController.php   resolved by develop version
#	Server/application/cunkebao/controller/plan/PlanSceneV1Controller.php   resolved by develop version
#	Server/application/job/WechatMomentsJob.php   resolved by develop version
#	Server/application/job/WorkbenchAutoLikeJob.php   resolved by develop version
#	Server/extend/WeChatDeviceApi/Adapters/ChuKeBao/Adapter.php   resolved by develop version
This commit is contained in:
笔记本里的永平
2025-07-16 11:08:50 +08:00
19 changed files with 1092 additions and 149 deletions

View File

@@ -23,9 +23,15 @@ class AccountController extends BaseController
* @param bool $isInner 是否为定时任务调用
* @return \think\response\Json
*/
public function getlist($pageIndex = '', $pageSize = '', $isInner = false)
public function getlist($data = [], $isInner = false)
{
$pageIndex = !empty($data['pageIndex']) ? $data['pageIndex'] : 0;
$pageSize = !empty($data['pageSize']) ? $data['pageSize'] : 20;
$showNormalAccount = !empty($data['showNormalAccount']) ? $data['showNormalAccount'] : '';
$keyword = !empty($data['keyword']) ? $data['keyword'] : '';
$departmentId = !empty($data['departmentId']) ? $data['departmentId'] : '';
// 获取授权token
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
@@ -39,11 +45,11 @@ class AccountController extends BaseController
try {
// 构建请求参数
$params = [
'showNormalAccount' => $this->request->param('showNormalAccount', ''),
'keyword' => $this->request->param('keyword', ''),
'departmentId' => $this->request->param('departmentId', ''),
'pageIndex' => !empty($pageIndex) ? $pageIndex : $this->request->param('pageIndex', 0),
'pageSize' => !empty($pageSize) ? $pageSize : $this->request->param('pageSize', 20)
'showNormalAccount' => $showNormalAccount,
'keyword' => $keyword,
'departmentId' => $departmentId,
'pageIndex' => $pageIndex,
'pageSize' => $pageSize
];
// 设置请求头

View File

@@ -171,7 +171,7 @@ class AutomaticAssign extends BaseController
* @param int $optFrom 操作来源
* @return \think\response\Json
*/
public function allotWechatFriend($data = [],$isInner = false)
public function allotWechatFriend($data = [],$isInner = false,$errorNum = 0)
{
// 获取授权token
$authorization = trim($this->request->header('authorization', $this->authorization));
@@ -188,23 +188,24 @@ class AutomaticAssign extends BaseController
$wechatFriendId = !empty($data['wechatFriendId']) ? $data['wechatFriendId'] : input('wechatFriendId', 0);
$toAccountId = !empty($data['toAccountId']) ? $data['toAccountId'] : input('toAccountId', 0);
$comment = !empty($data['comment']) ? $data['comment'] : input('comment', '');
$notifyReceiver = !empty($data['notifyReceiver']) ? $data['notifyReceiver'] : input('notifyReceiver', false);
$notifyReceiver = !empty($data['notifyReceiver']) ? $data['notifyReceiver'] : input('notifyReceiver', 'false');
$optFrom = !empty($data['optFrom']) ? $data['optFrom'] : input('optFrom', 4); // 默认操作来源为4
// 参数验证
if (empty($wechatFriendId)) {
return errorJson('微信好友ID不能为空');
return json_encode(['code'=>500,'msg'=>'微信好友ID不能为空']);
}
if (empty($toAccountId)) {
return errorJson('目标账号ID不能为空');
return json_encode(['code'=>500,'msg'=>'目标账号ID不能为空']);
}
// 设置请求头
$headerData = ['client:system'];
$header = setHeader($headerData, $authorization, 'json');
// 发送请求
$url = $this->baseUrl . 'api/WechatFriend/allot?wechatFriendId='.$wechatFriendId.'&notifyReceiver='.$notifyReceiver.'&comment='.$comment.'&toAccountId='.$toAccountId.'&optFrom='.$optFrom;
$result = requestCurl($url, [], 'PUT', $header, 'json');
@@ -226,8 +227,59 @@ class AutomaticAssign extends BaseController
if($isInner){
return json_encode(['code'=>500,'msg'=>'微信好友分配失败:' . $e->getMessage()]);
}else{
Cache::rm('system_authorization_token');
Cache::rm('system_refresh_token');
$errorNum ++;
if ($errorNum <= 3) {
$this->allotWechatFriend($data,$isInner,$errorNum);
}
return json_encode(['code'=>500,'msg'=> $result]);
return errorJson('微信好友分配失败:' . $e->getMessage());
}
}
}
public function multiAllotFriendToAccount($data = [],$errorNum = 0){
// 获取授权token
$authorization = $this->authorization;
if (empty($authorization)) {
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
}
$wechatFriendIds = !empty($data['wechatFriendIds']) ? $data['wechatFriendIds'] : input('wechatFriendIds', []);
$toAccountId = !empty($data['toAccountId']) ? $data['toAccountId'] : input('toAccountId', 0);
$notifyReceiver = !empty($data['notifyReceiver']) ? $data['notifyReceiver'] : input('notifyReceiver', 'false');
// 参数验证
if (empty($wechatFriendIds)) {
return json_encode(['code'=>500,'msg'=>'微信好友ID不能为空']);
}
if (empty($toAccountId)) {
return json_encode(['code'=>500,'msg'=>'目标账号ID不能为空']);
}
// 设置请求头
$headerData = ['client:system'];
$header = setHeader($headerData, $authorization, 'json');
// 发送请求
$url = $this->baseUrl . 'api/WechatFriend/multiAllotFriendToAccount?wechatFriendIds='.$wechatFriendIds.'&toAccountId='.$toAccountId.'&notifyReceiver='.$notifyReceiver;
$result = requestCurl($url, [], 'PUT', $header, 'json');
if (empty($result)) {
return json_encode(['code'=>200,'msg'=>'微信好友分配成功']);
} else {
Cache::rm('system_authorization_token');
Cache::rm('system_refresh_token');
$errorNum ++;
if ($errorNum <= 3) {
$this->multiAllotFriendToAccount($data,$errorNum);
}
return json_encode(['code'=>500,'msg'=> $result]);
}
}
}

View File

@@ -3,6 +3,7 @@
namespace app\api\controller;
use app\api\model\WechatMessageModel;
use think\Db;
use think\facade\Request;
class MessageController extends BaseController
@@ -386,6 +387,51 @@ class MessageController extends BaseController
'wechatTime' => $wechatTime
];
//已被删除
if ($item['msgType'] == 10000 && strpos($item['content'],'开启了朋友验证') !== false) {
Db::table('s2_wechat_friend')->where('id',$item['wechatFriendId'])->update(['isDeleted'=> 1,'deleteTime' => $wechatTime]);
}else{
//优先分配在线客服
$friend = Db::table('s2_wechat_friend')->where('id',$item['wechatFriendId'])->find();
if (!empty($friend)){
$accountId = $item['accountId'];
$accountData = Db::table('s2_company_account')->where('id',$accountId)->find();
if (!empty($accountData)){
$account = new AccountController();
$account->getlist(['pageIndex' => 0,'pageSize' => 100,'departmentId' => $accountData['departmentId']]);
$accountIds = Db::table('s2_company_account')->where(['id' => $accountId,'alive' => 1])->column('id');
if (!empty($accountIds)){
if (!in_array($friend['accountId'],$accountData)){
// 执行切换好友命令
$randomKey = array_rand($accountIds, 1);
$toAccountId = $accountIds[$randomKey];
$toAccountData = Db::table('s2_company_account')->where('id',$toAccountId)->find();
$automaticAssign = new AutomaticAssign();
$automaticAssign->allotWechatFriend([
'wechatFriendId' => $friend['id'],
'toAccountId' => $toAccountId
], true);
Db::table('s2_wechat_friend')
->where('id',$friend['id'])
->update([
'accountId' => $toAccountId,
'accountUserName' => $toAccountData['userName'],
'accountRealName' => $toAccountData['realName'],
'accountNickname' => $toAccountData['nickname'],
]);
}
}
}
}
}
// 创建新记录
WechatMessageModel::create($data);
}

View File

@@ -62,11 +62,11 @@ class WebSocketController extends BaseController
'username' => $userData['userName'],
'password' => $userData['password']
];
// 调用登录接口获取token
$headerData = ['client:kefu-client'];
$headerData = ['client:kefu-client'];
$header = setHeader($headerData, '', 'plain');
$result = requestCurl('https://kf.quwanzhi.com:9991/token', $params, 'POST', $header);
$result = requestCurl('https://kf.quwanzhi.com:9991/token', $params, 'POST', $header);
$result_array = handleApiResponse($result);
if (isset($result_array['access_token']) && !empty($result_array['access_token'])) {

View File

@@ -72,7 +72,11 @@ class WechatChatroomController extends BaseController
return successJson($response);
}
} catch (\Exception $e) {
return errorJson('获取微信群聊列表失败:' . $e->getMessage());
if($isInner){
return json_encode(['code'=>200,'msg'=>'获取微信群聊列表失败' . $e->getMessage()]);
}else{
return errorJson('获取微信群聊列表失败:' . $e->getMessage());
}
}
}