chore: 重写初始提交(清空历史,整理后全量提交)
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | YwxApp [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: ywxapp<admin@ywxapp.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
// app/controller/Unread.php
|
||||
namespace addon\wxchat\controller\api;
|
||||
|
||||
use think\Request;
|
||||
use think\facade\Cache;
|
||||
use GatewayClient\Gateway;
|
||||
|
||||
use ywxapp\controller\FrontendBase as AddonController;
|
||||
|
||||
/**
|
||||
* Unread 类
|
||||
*
|
||||
* @author ywxapp <admin@ywxapp.cn>
|
||||
*/
|
||||
class Unread extends AddonController
|
||||
{
|
||||
|
||||
/**
|
||||
* Summary of noNeedLogin
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedLogin = ['*'];
|
||||
|
||||
/**
|
||||
* Summary of noNeedVerify
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedVerify = ['*'];
|
||||
|
||||
/**
|
||||
* 控制器初始化 initialize
|
||||
* @return void
|
||||
*/
|
||||
protected function initialize()
|
||||
{}
|
||||
|
||||
// 获取未读计数
|
||||
|
||||
public function count(Request $request)
|
||||
{
|
||||
$userId = $request->user->id;
|
||||
|
||||
// 从Redis读取
|
||||
$redis = new \Redis();
|
||||
$redis->connect('127.0.0.1', 6379);
|
||||
$unreadData = $redis->hGetAll("unread:user:{$userId}");
|
||||
|
||||
// 格式化数据
|
||||
$result = [];
|
||||
foreach ($unreadData as $key => $count) {
|
||||
list($type, $id) = explode(':', $key);
|
||||
$result[] = [
|
||||
'contact_type' => $type,
|
||||
'contact_id' => $id,
|
||||
'unread_count' => $count
|
||||
];
|
||||
}
|
||||
|
||||
return json(['code' => 200, 'data' => $result]);
|
||||
}
|
||||
|
||||
// 标记已读
|
||||
|
||||
public function read(Request $request)
|
||||
{
|
||||
$userId = $request->user->id;
|
||||
$contactType = $request->post('contact_type');
|
||||
$contactId = $request->post('contact_id');
|
||||
|
||||
// 通知GatewayWorker
|
||||
Gateway::$registerAddress = '127.0.0.1:1238';
|
||||
Gateway::sendToUid($userId, json_encode([
|
||||
'type' => 'read',
|
||||
'contact_type' => $contactType,
|
||||
'contact_id' => $contactId
|
||||
]));
|
||||
|
||||
return json(['code' => 200, 'msg' => '已标记已读']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user