代码提交

This commit is contained in:
wong
2025-09-04 10:49:22 +08:00
parent d3ae45a360
commit 3c68a603af
5 changed files with 661 additions and 162 deletions

View File

@@ -266,7 +266,7 @@ class UserController extends BaseController
* 获取验证码
* @return \think\response\Json
*/
public function getVerifyCode()
public function getVerifyCode($isJson = false)
{
$headerData = ['client:' . self::CLIENT_TYPE];
$header = setHeader($headerData, '', 'plain');
@@ -279,17 +279,19 @@ class UserController extends BaseController
if (is_array($response)) {
// 如果verifyCodeImage和verifySessionId都不为null返回它们
if (!empty($response['verifyCodeImage']) && !empty($response['verifySessionId'])) {
return successJson([
$returnData = [
'verifyCodeImage' => $response['verifyCodeImage'],
'verifySessionId' => $response['verifySessionId']
]);
];
return !empty($isJson) ? json_encode(['code' => 200,'data' => $returnData]) : successJson($returnData);
}
}
// 如果不是预期的格式,返回原始数据
return successJson($response);
return !empty($isJson) ? json_encode(['code' => 500,'data' => $response]) : errorJson('无需验证码');
} catch (\Exception $e) {
return errorJson('获取验证码失败' . $e->getMessage());
$msg = '获取验证码失败'. $e->getMessage();
return !empty($isJson) ? json_encode(['code' => 400,'msg' => $msg]) : errorJson($msg);
}
}

View File

@@ -141,11 +141,16 @@ Route::group('v1/', function () {
Route::get('friendRequestTaskStats', 'app\cunkebao\controller\StatsController@getFriendRequestTaskStats');
Route::get('userInfoStats', 'app\cunkebao\controller\StatsController@userInfoStats');
});
})->middleware(['jwt']);
// 客服登录
Route::group('v1/kefu', function () {
Route::post('login', 'app\cunkebao\controller\KeFuLoginController@index'); // 获取好友列表
});
Route::group('v1/api/scenarios', function () {
Route::any('', 'app\cunkebao\controller\plan\PostExternalApiV1Controller@index');

View File

@@ -0,0 +1,78 @@
<?php
namespace app\cunkebao\controller;
use app\common\controller\BaseController;
use Exception;
use library\ResponseHelper;
use app\api\controller\UserController;
/**
* 认证控制器
* 处理用户登录和身份验证
*/
class KeFuLoginController extends BaseController
{
/**
* 用户登录
*
* @return \think\response\Json
*/
public function index($username = '', $password = '',$verifySessionId = '',$verifyCode = '')
{
$username = !empty($username) ? $username : $this->request->param('username', '');
$password = !empty($password) ? $password : $this->request->param('password', '');
$verifySessionId =!empty($verifySessionId) ? $verifySessionId : $this->request->param('verifySessionId', '');
$verifyCode = !empty($verifyCode) ? $verifyCode : $this->request->param('verifyCode', '');
if (empty($username) || empty($password)) {
return ResponseHelper::error('请输入账号密码');
}
//登录参数
$params = [
'grant_type' => 'password',
'username' => $username,
'password' => $password
];
if (!empty($verifySessionId) && !empty($verifyCode)){
$params[] = 'verifysessionid:' . $verifySessionId;
$params[] = 'verifycode:' . $verifyCode;
}
//获取验证码
// $UserController = new UserController();
// $verifyCode = $UserController->getVerifyCode(true);
// $verifyCode = json_decode($verifyCode, true);
// if ($verifyCode['code'] != 200) {
// exit_data($verifyCode);
// }
try {
// 调用登录接口获取token
$headerData = ['client:kefu-client'];
$header = setHeader($headerData, '', 'plain');
$result = requestCurl('https://s2.siyuguanli.com:9991/token', $params, 'POST', $header);
$token = handleApiResponse($result);
$userData['kefuData']['token'] = $token;
if (isset($token['access_token']) && !empty($token['access_token'])) {
$headerData = ['client:kefu-client'];
$header = setHeader($headerData, $token['access_token']);
$result = requestCurl('https://s2.siyuguanli.com:9991/api/account/self', [], 'GET', $header, 'json');
$self = handleApiResponse($result);
$userData['kefuData']['self'] = $self;
}
return ResponseHelper::success($userData, '登录成功');
} catch (Exception $e) {
return ResponseHelper::error($e->getMessage(), $e->getCode());
}
}
}

View File

@@ -58,7 +58,7 @@ class WorkbenchGroupPushJob
{
try {
// 获取所有工作台
$workbenches = Workbench::where(['status' => 1, 'type' => 3, 'isDel' => 0])->order('id desc')->select();
$workbenches = Workbench::where(['status' => 1, 'type' => 3, 'isDel' => 0,'id' => 178])->order('id desc')->select();
foreach ($workbenches as $workbench) {
// 获取工作台配置
$config = WorkbenchGroupPush::where('workbenchId', $workbench->id)->find();
@@ -87,7 +87,7 @@ class WorkbenchGroupPushJob
}
// 发微信消息
// 发微信个人消息
public function sendMsgToGroup($workbench, $config, $msgConf)
{
// 消息拼接 msgType(1:文本 3:图片 43:视频 47:动图表情包gif、其他表情包 49:小程序/其他:图文、文件)
@@ -117,7 +117,6 @@ class WorkbenchGroupPushJob
}
// 建立WebSocket
$wsController = new WebSocketController(['userName' => $username, 'password' => $password, 'accountId' => $toAccountId]);
foreach ($msgConf as $content) {
$sendData = [];
$sqlData = [];
@@ -294,82 +293,72 @@ class WorkbenchGroupPushJob
return false;
}
$limit = ($config['pushType'] == 1) ? 10 : 1;
$order = ($config['pushOrder'] == 1) ? 'ci.sendTime desc, ci.id asc' : 'ci.sendTime desc, ci.id desc';
// 基础查询构建器
$baseQuery = function() use ($workbench, $contentids) {
return Db::name('content_library')->alias('cl')
->join('content_item ci', 'ci.libraryId = cl.id')
->where(['cl.isDel' => 0, 'ci.isDel' => 0])
->where('ci.sendTime <= ' . (time() + 60))
->whereIn('cl.id', $contentids)
->field('ci.id,ci.libraryId,ci.contentType,ci.title,ci.content,ci.resUrls,ci.urls,ci.comment,ci.sendTime');
};
// 获取未发送的内容
$unsentContent = $baseQuery()
->join('workbench_group_push_item wgpi', 'wgpi.contentId = ci.id and wgpi.workbenchId = ' . $workbench->id, 'left')
->where('wgpi.id', 'null')
->order($order)
->limit($limit)
->select();
if (!empty($unsentContent)) {
return $unsentContent;
if ($config['pushType'] == 1) {
$limit = 10;
} else {
$limit = 1;
}
// 如果不允许循环发送,直接返回空
if ($config['isLoop'] != 1) {
return [];
//推送顺序
if ($config['pushOrder'] == 1) {
$order = 'ci.sendTime desc, ci.id asc';
} else {
$order = 'ci.sendTime desc, ci.id desc';
}
// 循环发送逻辑:检查是否需要标记循环完成
$this->checkAndResetLoop($workbench->id, $contentids);
// 获取下一个要发送的内容从内容库中查询排除isLoop为0的数据
$isPushIds = Db::name('workbench_group_push_item')
->where(['workbenchId' => $workbench->id,'isLoop' => 0])
->column('contentId');
$nextContent = $baseQuery()
->whereNotIn('ci.id', $isPushIds)
->group('ci.id')
->order('ci.id asc')
->limit($limit)
->select();
return $nextContent;
}
/**
* 检查循环状态
* @param int $workbenchId
* @param array $contentids
*/
private function checkAndResetLoop($workbenchId, $contentids)
{
// 统计总内容数
$totalCount = Db::name('content_library')->alias('cl')
// 基础查询
$query = Db::name('content_library')->alias('cl')
->join('content_item ci', 'ci.libraryId = cl.id')
->join('workbench_group_push_item wgpi', 'wgpi.contentId = ci.id and wgpi.workbenchId = ' . $workbench->id, 'left')
->where(['cl.isDel' => 0, 'ci.isDel' => 0])
->where('ci.sendTime <= ' . (time() + 60))
->whereIn('cl.id', $contentids)
->count();
->field([
'ci.id',
'ci.libraryId',
'ci.contentType',
'ci.title',
'ci.content',
'ci.resUrls',
'ci.urls',
'ci.comment',
'ci.sendTime'
]);
// 复制 query
$query2 = clone $query;
$query3 = clone $query;
// 根据accountType处理不同的发送逻辑
if ($config['isLoop'] == 1) {
// 可以循环发送
// 1. 优先获取未发送的内容
$unsentContent = $query->where('wgpi.id', 'null')
->order($order)
->limit(0, $limit)
->select();
exit_data($unsentContent);
if (!empty($unsentContent)) {
return $unsentContent;
}
$lastSendData = Db::name('workbench_group_push_item')->where('workbenchId', $workbench->id)->order('id desc')->find();
$fastSendData = Db::name('workbench_group_push_item')->where('workbenchId', $workbench->id)->order('id asc')->find();
// 统计已发送内容数排除isLoop为0的数据
$sentCount = Db::name('workbench_group_push_item')
->alias('wgpi')
->join('content_item ci', 'ci.id = wgpi.contentId')
->join('content_library cl', 'cl.id = ci.libraryId')
->where('wgpi.workbenchId', $workbenchId)
->where('wgpi.isLoop', 0)
->whereIn('cl.id', $contentids)
->count('DISTINCT wgpi.contentId');
$sentContent = $query2->where('wgpi.contentId', '<', $lastSendData['contentId'])->order('wgpi.id ASC')->group('wgpi.contentId')->limit(0, $limit)->select();
// 记录循环状态
if ($sentCount >= $totalCount) {
Db::name('workbench_group_push_item')
->where(['workbenchId' => $workbenchId, 'isLoop' => 0])
->update(['isLoop' => 1]);
if (empty($sentContent)) {
$sentContent = $query3->where('wgpi.contentId', '=', $fastSendData['contentId'])->order('wgpi.id ASC')->group('wgpi.contentId')->limit(0, $limit)->select();
}
return $sentContent;
} else {
// 不能循环发送,只获取未发送的内容
$list = $query->where('wgpi.id', 'null')
->order($order)
->limit(0, $limit)
->select();
exit_data($list);
return $list;
}
}
@@ -422,4 +411,4 @@ class WorkbenchGroupPushJob
return false;
}
}
}