代码同步提交
This commit is contained in:
@@ -33,7 +33,11 @@ class WebSocketController extends BaseController
|
||||
*/
|
||||
public function __construct($userData = [])
|
||||
{
|
||||
parent::__construct();
|
||||
//parent::__construct();
|
||||
if (empty($userData)){
|
||||
return;
|
||||
}
|
||||
|
||||
$this->initConnection($userData);
|
||||
}
|
||||
|
||||
@@ -51,7 +55,6 @@ class WebSocketController extends BaseController
|
||||
// 检查缓存中是否存在有效的token
|
||||
$cacheKey = 'websocket_token_' . $userData['userName'];
|
||||
$cachedToken = Cache::get($cacheKey);
|
||||
|
||||
if ($cachedToken) {
|
||||
$this->authorized = $cachedToken;
|
||||
$this->accountId = $userData['accountId'];
|
||||
@@ -61,9 +64,11 @@ class WebSocketController extends BaseController
|
||||
'username' => $userData['userName'],
|
||||
'password' => $userData['password']
|
||||
];
|
||||
|
||||
// 调用登录接口获取token
|
||||
$headerData = ['client:kefu-client'];
|
||||
|
||||
$headerData[] = 'verifysessionid:3f21df29-6d8a-4980-ae8a-bf15ef17955f';
|
||||
$headerData[] = 'verifycode:0k3g';
|
||||
$header = setHeader($headerData, '', 'plain');
|
||||
$result = requestCurl('https://kf.quwanzhi.com:9991/token', $params, 'POST', $header);
|
||||
$result_array = handleApiResponse($result);
|
||||
@@ -877,8 +882,10 @@ class WebSocketController extends BaseController
|
||||
"seq" => time(),
|
||||
"wechatAccountId" => $data['wechatAccountId'],
|
||||
"chatroomName" => $data['chatroomName'],
|
||||
"wechatFriendIds" => $data['wechatFriendIds']
|
||||
// "wechatFriendIds" => $data['wechatFriendIds']
|
||||
"wechatFriendIds" => [17453051,17453058]
|
||||
];
|
||||
|
||||
// 记录请求日志
|
||||
Log::info('创建群聊请求:' . json_encode($params, 256));
|
||||
|
||||
|
||||
@@ -249,4 +249,43 @@ class WechatController extends BaseController
|
||||
WechatAccountModel::create($data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function chatroomCreate($data = [])
|
||||
{
|
||||
|
||||
$authorization = $this->authorization;
|
||||
|
||||
if (empty($authorization)) {
|
||||
return json_encode(['code' => 500, 'msg' => '缺少授权信息']);
|
||||
}
|
||||
|
||||
try {
|
||||
// 设置请求头
|
||||
$headerData = ['Client:system'];
|
||||
$header = setHeader($headerData, $authorization,'json');
|
||||
$params = [
|
||||
"chatroomOperateType" => 7,
|
||||
"extra" => "{chatroomName:{$data['chatroomName']}}",
|
||||
"wechatAccountId" => $data['wechatAccountId'],
|
||||
"wechatChatroomId" => 0,
|
||||
"wechatFriendIds" => $data['wechatFriendIds']
|
||||
];
|
||||
|
||||
// 发送请求获取状态信息
|
||||
$result = requestCurl($this->baseUrl . 'api/WechatChatroom/chatroomOperate', $params, 'POST', $header,'json');
|
||||
$response = handleApiResponse($result);
|
||||
if (!empty($response)) {
|
||||
return json_encode(['code' => 500, 'msg' =>$response]);
|
||||
}else{
|
||||
return json_encode(['code' => 200, 'msg' =>'成功']);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
if (empty($authorization)) { // 只有作为独立API调用时才返回
|
||||
return json_encode(['code' => 500, 'msg' => '获取失败:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -13,10 +13,22 @@ Route::group('v1/', function () {
|
||||
Route::group('wechatFriend/', function () {
|
||||
Route::get('list', 'app\chukebao\controller\WechatFriendController@getList'); // 获取好友列表
|
||||
});
|
||||
//好友相关
|
||||
//群相关
|
||||
Route::group('wechatChatroom/', function () {
|
||||
Route::get('list', 'app\chukebao\controller\WechatChatroomController@getList'); // 获取好友列表
|
||||
});
|
||||
|
||||
//客服相关
|
||||
Route::group('customerService/', function () {
|
||||
Route::get('list', 'app\chukebao\controller\CustomerServiceController@getList'); // 获取好友列表
|
||||
});
|
||||
|
||||
//客服相关
|
||||
Route::group('message/', function () {
|
||||
Route::get('list', 'app\chukebao\controller\MessageController@getList'); // 获取好友列表
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace app\chukebao\controller;
|
||||
|
||||
use library\ResponseHelper;
|
||||
use think\Db;
|
||||
|
||||
class CustomerServiceController extends BaseController
|
||||
{
|
||||
|
||||
public function getList(){
|
||||
$accountId = $this->getUserInfo('s2_accountId');
|
||||
if (empty($accountId)){
|
||||
return ResponseHelper::error('请先登录');
|
||||
}
|
||||
|
||||
$accountIds1= Db::table('s2_wechat_friend')->where(['accountId' => $accountId,'isDeleted' => 0])->group('wechatAccountId')->column('wechatAccountId');
|
||||
$accountIds2 = Db::table('s2_wechat_chatroom')->where(['accountId' => $accountId,'isDeleted' => 0])->group('wechatAccountId')->column('wechatAccountId');
|
||||
// 确保即使有空数组也不会报错,并且去除重复值
|
||||
$accountIds = array_unique(array_merge($accountIds1 ?: [], $accountIds2 ?: []));
|
||||
|
||||
$list = Db::table('s2_wechat_account')
|
||||
->whereIn('id',$accountIds)
|
||||
->order('id desc')
|
||||
->group('id')
|
||||
->select();
|
||||
foreach ($list as $k=>&$v){
|
||||
$v['createTime'] = !empty($v['createTime']) ? date('Y-m-d H:i:s',$v['createTime']) : '';
|
||||
$v['updateTime'] = !empty($v['updateTime']) ? date('Y-m-d H:i:s',$v['updateTime']) : '';
|
||||
$v['labels'] = json_decode($v['labels'],true);
|
||||
unset(
|
||||
$v['accountUserName'],
|
||||
$v['accountRealName'],
|
||||
$v['accountNickname'],
|
||||
);
|
||||
}
|
||||
unset($v);
|
||||
|
||||
return ResponseHelper::success($list);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ use Exception;
|
||||
use library\ResponseHelper;
|
||||
use think\Db;
|
||||
use think\Controller;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* 认证控制器
|
||||
* 处理用户登录和身份验证
|
||||
@@ -27,18 +29,27 @@ class LoginController extends Controller
|
||||
$password = !empty($password) ? $password : $this->request->param('password', '');
|
||||
$verifySessionId =!empty($verifySessionId) ? $verifySessionId : $this->request->param('verifySessionId', '');
|
||||
$verifyCode = !empty($verifyCode) ? $verifyCode : $this->request->param('verifyCode', '');
|
||||
$token = JwtUtil::getRequestToken();
|
||||
$payload = '';
|
||||
if (!empty($token)){
|
||||
$payload = JwtUtil::verifyToken($token);
|
||||
}
|
||||
|
||||
if (empty($username) || empty($password)) {
|
||||
if ((empty($username) || empty($password)) && empty($payload)){
|
||||
return ResponseHelper::error('请输入账号密码');
|
||||
}
|
||||
|
||||
// 验证账号是否存在(支持账号或手机号登录)
|
||||
$user = Db::name('users')
|
||||
->where(function ($query) use ($username) {
|
||||
$query->where('account', $username)->whereOr('phone', $username);
|
||||
})
|
||||
->where('passwordMd5', md5($password))
|
||||
->find();
|
||||
if (empty($payload11)){
|
||||
$user = Db::name('users')
|
||||
->where(function ($query) use ($username) {
|
||||
$query->where('account', $username)->whereOr('phone', $username);
|
||||
})
|
||||
->where('passwordMd5', md5($password))
|
||||
->find();
|
||||
}else{
|
||||
$user = $payload;
|
||||
}
|
||||
|
||||
if (empty($user)) {
|
||||
return ResponseHelper::error('账号不存在或密码错误');
|
||||
@@ -48,15 +59,12 @@ class LoginController extends Controller
|
||||
return ResponseHelper::error('账号已禁用');
|
||||
}
|
||||
|
||||
|
||||
//登录参数
|
||||
$params = [
|
||||
'grant_type' => 'password',
|
||||
'username' => $user['account'],
|
||||
'password' => !empty($user['passwordLocal']) ? localDecrypt($user['passwordLocal']) : $password
|
||||
];
|
||||
|
||||
|
||||
try {
|
||||
// 调用登录接口获取token
|
||||
$headerData = ['client:kefu-client'];
|
||||
@@ -68,20 +76,18 @@ class LoginController extends Controller
|
||||
$result = requestCurl('https://s2.siyuguanli.com:9991/token', $params, 'POST', $header);
|
||||
$result = handleApiResponse($result);
|
||||
if (isset($result['access_token']) && !empty($result['access_token'])) {
|
||||
$userData['kefuData']['token'] = $result;
|
||||
$kefuData['token'] = $result;
|
||||
$headerData = ['client:kefu-client'];
|
||||
$header = setHeader($headerData, $result['access_token']);
|
||||
$result2 = requestCurl('https://s2.siyuguanli.com:9991/api/account/self', [], 'GET', $header, 'json');
|
||||
$self = handleApiResponse($result2);
|
||||
$userData['kefuData']['self'] = $self;
|
||||
|
||||
Db::name('users')->where('id', $user['id'])->update(['passwordLocal' => localEncrypt($password),'updateTime' => time()]);
|
||||
|
||||
$kefuData['self'] = $self;
|
||||
Db::name('users')->where('id', $user['id'])->update(['passwordLocal' => localEncrypt($params['password']),'updateTime' => time()]);
|
||||
}else{
|
||||
return ResponseHelper::error($result['error_description']);
|
||||
}
|
||||
|
||||
unset($user['passwordMd5'],$user['deleteTime'],$user['passwordLocal']);
|
||||
unset($user['passwordMd5'],$user['deleteTime']);
|
||||
$userData['member'] = $user;
|
||||
|
||||
// 生成JWT令牌
|
||||
@@ -89,10 +95,9 @@ class LoginController extends Controller
|
||||
$token = JwtUtil::createToken($user, $expired);
|
||||
$token_expired = time() + $expired;
|
||||
|
||||
|
||||
$userData['token'] = $token;
|
||||
$userData['token_expired'] = $token_expired;
|
||||
|
||||
$userData['kefuData'] = $kefuData;
|
||||
|
||||
return ResponseHelper::success($userData, '登录成功');
|
||||
} catch (Exception $e) {
|
||||
|
||||
72
Server/application/chukebao/controller/MessageController.php
Normal file
72
Server/application/chukebao/controller/MessageController.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace app\chukebao\controller;
|
||||
|
||||
use library\ResponseHelper;
|
||||
use think\Db;
|
||||
|
||||
class MessageController extends BaseController
|
||||
{
|
||||
|
||||
public function getList(){
|
||||
$page = $this->request->param('page', 1);
|
||||
$limit = $this->request->param('limit', 10);
|
||||
$accountId = $this->getUserInfo('s2_accountId');
|
||||
if (empty($accountId)){
|
||||
return ResponseHelper::error('请先登录');
|
||||
}
|
||||
|
||||
$chatroomList = Db::table('s2_wechat_chatroom')->alias('wc')
|
||||
->join(['s2_wechat_message' => 'm'], 'wc.id = m.wechatChatroomId', 'LEFT')
|
||||
->where(['wc.accountId' => $accountId,'m.type' => 2,' wc.isDeleted' => 0])
|
||||
->order('m.id desc')
|
||||
->group('m.wechatChatroomId')
|
||||
->page($page, $limit)
|
||||
->select();
|
||||
$friendIds = Db::table('s2_wechat_friend')
|
||||
->where(['accountId' => $accountId,' isDeleted' => 0])
|
||||
->group('id')
|
||||
->column('id');
|
||||
$friendList = Db::table('s2_wechat_message')
|
||||
->where(['type' => 1])
|
||||
->whereIn('wechatFriendId',$friendIds)
|
||||
->order('id desc')
|
||||
->group('wechatFriendId')
|
||||
->page($page, $limit)
|
||||
->select();
|
||||
|
||||
$list = array_merge($chatroomList,$friendList);
|
||||
|
||||
// 按createTime字段从大到小排序
|
||||
usort($list, function($a, $b) {
|
||||
return $b['createTime'] <=> $a['createTime'];
|
||||
});
|
||||
|
||||
|
||||
foreach ($list as $k=>&$v){
|
||||
$v['createTime'] = !empty($v['createTime']) ? date('Y-m-d H:i:s',$v['createTime']) : '';
|
||||
$v['wechatTime'] = !empty($v['wechatTime']) ? date('Y-m-d H:i:s',$v['wechatTime']) : '';
|
||||
|
||||
if (!empty($v['wechatFriendId'])){
|
||||
$friend = Db::table('s2_wechat_friend')
|
||||
->where(['id'=>$v['wechatFriendId']])
|
||||
->field('id,nickname,avatar')
|
||||
->find();
|
||||
$v['msgInfo'] = $friend;
|
||||
}
|
||||
|
||||
if (!empty($v['wechatChatroomId'])){
|
||||
$chatroom = Db::table('s2_wechat_chatroom')
|
||||
->where(['id'=>$v['wechatChatroomId']])
|
||||
->field('id,nickname,chatroomAvatar as avatar')
|
||||
->find();
|
||||
$v['msgInfo'] = $chatroom;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
unset($v);
|
||||
|
||||
return ResponseHelper::success($list);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,19 @@ class WechatChatroomController extends BaseController
|
||||
if (empty($accountId)){
|
||||
return ResponseHelper::error('请先登录');
|
||||
}
|
||||
$list = Db::table('s2_wechat_chatroom')->where('accountId',$accountId)->order('id desc')->page($page, $limit)->select();
|
||||
return ResponseHelper::success($list);
|
||||
$query = Db::table('s2_wechat_chatroom')
|
||||
->where(['accountId' => $accountId,'isDeleted' => 0])
|
||||
->order('id desc');
|
||||
$list = $query->page($page, $limit)->select();
|
||||
$total = $query->count();
|
||||
|
||||
|
||||
foreach ($list as $k=>&$v){
|
||||
$v['createTime'] = !empty($v['createTime']) ? date('Y-m-d H:i:s',$v['createTime']) : '';
|
||||
$v['updateTime'] = !empty($v['updateTime']) ? date('Y-m-d H:i:s',$v['updateTime']) : '';
|
||||
}
|
||||
unset($v);
|
||||
|
||||
return ResponseHelper::success(['list'=>$list,'total'=>$total]);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,20 @@ class WechatFriendController extends BaseController
|
||||
if (empty($accountId)){
|
||||
return ResponseHelper::error('请先登录');
|
||||
}
|
||||
$list = Db::table('s2_wechat_friend')->where('accountId',$accountId)->order('id desc')->page($page, $limit)->select();
|
||||
return ResponseHelper::success($list);
|
||||
$query = Db::table('s2_wechat_friend')
|
||||
->where(['accountId' => $accountId,'isDeleted' => 0])
|
||||
->order('id desc');
|
||||
$list = $query->page($page, $limit)->select();
|
||||
$total = $query->count();
|
||||
|
||||
|
||||
foreach ($list as $k=>&$v){
|
||||
$v['createTime'] = !empty($v['createTime']) ? date('Y-m-d H:i:s',$v['createTime']) : '';
|
||||
$v['updateTime'] = !empty($v['updateTime']) ? date('Y-m-d H:i:s',$v['updateTime']) : '';
|
||||
$v['passTime'] = !empty($v['passTime']) ? date('Y-m-d H:i:s',$v['passTime']) : '';
|
||||
}
|
||||
unset($v);
|
||||
|
||||
return ResponseHelper::success(['list'=>$list,'total'=>$total]);
|
||||
}
|
||||
}
|
||||
@@ -116,11 +116,7 @@ class PasswordLoginController extends BaseController
|
||||
// 生成JWT令牌
|
||||
$token = JwtUtil::createToken($member, 86400 * 30);
|
||||
$token_expired = time() + 86400 * 30;
|
||||
$kefuData = [
|
||||
'token' => [],
|
||||
'self' => [],
|
||||
];
|
||||
return compact('member', 'token', 'token_expired','deviceTotal','kefuData');
|
||||
return compact('member', 'token', 'token_expired','deviceTotal');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,6 +15,7 @@ use think\facade\Cache;
|
||||
use think\facade\Config;
|
||||
use app\api\controller\MomentsController as Moments;
|
||||
use Workerman\Lib\Timer;
|
||||
use app\api\controller\WechatController;
|
||||
|
||||
/**
|
||||
* 工作台群创建任务
|
||||
@@ -127,8 +128,6 @@ class WorkbenchGroupCreateJob
|
||||
$addGroupUser[] = $user;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($addGroupUser as $key => $val) {
|
||||
//判断第一组用户是否满足创建群的条件
|
||||
$friendIds = Db::name('wechat_friendship')->alias('f')
|
||||
@@ -162,12 +161,11 @@ class WorkbenchGroupCreateJob
|
||||
$toAccountId = Db::name('users')->where('account', $username)->value('s2_accountId');
|
||||
}
|
||||
$webSocket = new WebSocketController(['userName' => $username, 'password' => $password, 'accountId' => $toAccountId]);
|
||||
//$webSocket = new WebSocketController(['userName' => 'wz_03', 'password' => 'key123456', 'accountId' => 5015]);
|
||||
//拉人进群 $webSocket->CmdChatroomInvite(['wechatChatroomId' => 830794, 'wechatFriendIds' => [21168549]]);
|
||||
//修改群名称 $webSocket->CmdChatroomModifyInfo(['wechatChatroomId' => 830794, 'wechatAccountId' => 300745,'chatroomName' => 'test111']);
|
||||
//修改群公告 $webSocket->CmdChatroomModifyInfo(['wechatChatroomId' => 830794, 'wechatAccountId' => 300745,'announce' => 'test111']);
|
||||
//建群 $webSocket->CmdChatroomCreate(['chatroomName' => '聊天测试群', 'wechatFriendIds' => [17453051,17453058],'wechatAccountId' => 300745]);
|
||||
|
||||
|
||||
foreach ($groupedFriends as $wechatAccountId => $friendId) {
|
||||
//列出所有群
|
||||
$group = '';
|
||||
|
||||
@@ -64,9 +64,14 @@
|
||||
# 工作台群发消息
|
||||
*/2 * * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think workbench:groupPush >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/workbench_groupPush.log 2>&1
|
||||
|
||||
# 工作台建群
|
||||
*/5 * * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think workbench:groupCreate >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/workbench_groupCreate.log 2>&1
|
||||
|
||||
# 工作台流量分发
|
||||
0 9 * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think workbench:trafficDistribute >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/traffic_distribute.log 2>&1
|
||||
|
||||
|
||||
|
||||
# 预防性切换好友
|
||||
*/2 * * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think switch:friends >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/switch_friends.log 2>&1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user