初始化

main
gzydong 2020-12-03 11:57:46 +08:00
parent 495a3b8b5b
commit 64fdcfbe98
5 changed files with 44 additions and 33 deletions

View File

@ -2,6 +2,7 @@
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1;
use App\Constants\SocketConstants;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
@ -81,7 +82,7 @@ class GroupController extends CController
// ...消息推送队列 // ...消息推送队列
$this->producer->produce( $this->producer->produce(
new ChatMessageProducer('event_talk', [ new ChatMessageProducer(SocketConstants::EVENT_TALK, [
'sender' => $user_id, //发送者ID 'sender' => $user_id, //发送者ID
'receive' => intval($data['group_id']), //接收者ID 'receive' => intval($data['group_id']), //接收者ID
'source' => 2, //接收者类型 1:好友;2:群组 'source' => 2, //接收者类型 1:好友;2:群组
@ -146,7 +147,7 @@ class GroupController extends CController
// ...消息推送队列 // ...消息推送队列
$this->producer->produce( $this->producer->produce(
new ChatMessageProducer('event_talk', [ new ChatMessageProducer(SocketConstants::EVENT_TALK, [
'sender' => $user_id, //发送者ID 'sender' => $user_id, //发送者ID
'receive' => intval($params['group_id']), //接收者ID 'receive' => intval($params['group_id']), //接收者ID
'source' => 2, //接收者类型 1:好友;2:群组 'source' => 2, //接收者类型 1:好友;2:群组
@ -180,7 +181,7 @@ class GroupController extends CController
// ...消息推送队列 // ...消息推送队列
$this->producer->produce( $this->producer->produce(
new ChatMessageProducer('event_talk', [ new ChatMessageProducer(SocketConstants::EVENT_TALK, [
'sender' => $user_id, //发送者ID 'sender' => $user_id, //发送者ID
'receive' => intval($params['group_id']), //接收者ID 'receive' => intval($params['group_id']), //接收者ID
'source' => 2, //接收者类型 1:好友;2:群组 'source' => 2, //接收者类型 1:好友;2:群组
@ -246,7 +247,7 @@ class GroupController extends CController
// ...消息推送队列 // ...消息推送队列
$this->producer->produce( $this->producer->produce(
new ChatMessageProducer('event_talk', [ new ChatMessageProducer(SocketConstants::EVENT_TALK, [
'sender' => $user_id, //发送者ID 'sender' => $user_id, //发送者ID
'receive' => intval($params['group_id']), //接收者ID 'receive' => intval($params['group_id']), //接收者ID
'source' => 2, //接收者类型 1:好友;2:群组 'source' => 2, //接收者类型 1:好友;2:群组

View File

@ -2,6 +2,7 @@
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1;
use App\Constants\SocketConstants;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
@ -229,7 +230,7 @@ class TalkController extends CController
[$isTrue, $message,] = $this->talkService->revokeRecord($this->uid(), $params['record_id']); [$isTrue, $message,] = $this->talkService->revokeRecord($this->uid(), $params['record_id']);
if ($isTrue) { if ($isTrue) {
$this->producer->produce( $this->producer->produce(
new ChatMessageProducer('event_revoke_talk', [ new ChatMessageProducer(SocketConstants::EVENT_REVOKE_TALK, [
'record_id' => $params['record_id'] 'record_id' => $params['record_id']
]) ])
); );
@ -326,7 +327,7 @@ class TalkController extends CController
// ...消息推送队列 // ...消息推送队列
foreach ($ids as $value) { foreach ($ids as $value) {
$this->producer->produce( $this->producer->produce(
new ChatMessageProducer('event_talk', [ new ChatMessageProducer(SocketConstants::EVENT_TALK, [
'sender' => $user_id, //发送者ID 'sender' => $user_id, //发送者ID
'receive' => intval($value['receive_id']), //接收者ID 'receive' => intval($value['receive_id']), //接收者ID
'source' => intval($value['source']), //接收者类型 1:好友;2:群组 'source' => intval($value['source']), //接收者类型 1:好友;2:群组
@ -526,7 +527,7 @@ class TalkController extends CController
// ...消息推送队列 // ...消息推送队列
$this->producer->produce( $this->producer->produce(
new ChatMessageProducer('event_talk', [ new ChatMessageProducer(SocketConstants::EVENT_TALK, [
'sender' => $user_id, //发送者ID 'sender' => $user_id, //发送者ID
'receive' => intval($params['receive_id']), //接收者ID 'receive' => intval($params['receive_id']), //接收者ID
'source' => intval($params['source']), //接收者类型 1:好友;2:群组 'source' => intval($params['source']), //接收者类型 1:好友;2:群组
@ -571,7 +572,7 @@ class TalkController extends CController
// ...消息推送队列 // ...消息推送队列
$this->producer->produce( $this->producer->produce(
new ChatMessageProducer('event_talk', [ new ChatMessageProducer(SocketConstants::EVENT_TALK, [
'sender' => $user_id, //发送者ID 'sender' => $user_id, //发送者ID
'receive' => intval($params['receive_id']), //接收者ID 'receive' => intval($params['receive_id']), //接收者ID
'source' => intval($params['source']), //接收者类型 1:好友;2:群组 'source' => intval($params['source']), //接收者类型 1:好友;2:群组
@ -586,6 +587,9 @@ class TalkController extends CController
* 发送文件消息 * 发送文件消息
* *
* @RequestMapping(path="send-file", methods="post") * @RequestMapping(path="send-file", methods="post")
*
* @param UploadService $uploadService
* @return ResponseInterface
*/ */
public function sendFile(UploadService $uploadService) public function sendFile(UploadService $uploadService)
{ {
@ -633,7 +637,7 @@ class TalkController extends CController
// ...消息推送队列 // ...消息推送队列
$this->producer->produce( $this->producer->produce(
new ChatMessageProducer('event_talk', [ new ChatMessageProducer(SocketConstants::EVENT_TALK, [
'sender' => $user_id, //发送者ID 'sender' => $user_id, //发送者ID
'receive' => intval($params['receive_id']), //接收者ID 'receive' => intval($params['receive_id']), //接收者ID
'source' => intval($params['source']), //接收者类型 1:好友;2:群组 'source' => intval($params['source']), //接收者类型 1:好友;2:群组
@ -661,7 +665,7 @@ class TalkController extends CController
$user_id = $this->uid(); $user_id = $this->uid();
$emoticon = EmoticonDetail::where('id', $params['emoticon_id'])->where('user_id', $user_id)->first([ $emoticon = EmoticonDetail::where('id', $params['emoticon_id'])->where('user_id', $user_id)->first([
'url','file_suffix','file_size' 'url', 'file_suffix', 'file_size'
]); ]);
if (!$emoticon) { if (!$emoticon) {
@ -688,7 +692,7 @@ class TalkController extends CController
// ...消息推送队列 // ...消息推送队列
$this->producer->produce( $this->producer->produce(
new ChatMessageProducer('event_talk', [ new ChatMessageProducer(SocketConstants::EVENT_TALK, [
'sender' => $user_id, //发送者ID 'sender' => $user_id, //发送者ID
'receive' => intval($params['receive_id']), //接收者ID 'receive' => intval($params['receive_id']), //接收者ID
'source' => intval($params['source']), //接收者类型 1:好友;2:群组 'source' => intval($params['source']), //接收者类型 1:好友;2:群组

View File

@ -2,6 +2,7 @@
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1;
use App\Constants\SocketConstants;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
@ -268,7 +269,7 @@ class UsersController extends CController
//判断对方是否在线。如果在线发送消息通知 //判断对方是否在线。如果在线发送消息通知
if ($this->socketClientService->isOnlineAll((int)$params['friend_id'])) { if ($this->socketClientService->isOnlineAll((int)$params['friend_id'])) {
$this->producer->produce( $this->producer->produce(
new ChatMessageProducer('event_friend_apply', [ new ChatMessageProducer(SocketConstants::EVENT_FRIEND_APPLY, [
'sender' => $user_id, 'sender' => $user_id,
'receive' => (int)$params['friend_id'], 'receive' => (int)$params['friend_id'],
'type' => 1, 'type' => 1,
@ -304,7 +305,7 @@ class UsersController extends CController
if ($this->socketClientService->isOnlineAll((int)$params['friend_id'])) { if ($this->socketClientService->isOnlineAll((int)$params['friend_id'])) {
// 待修改 // 待修改
$this->producer->produce( $this->producer->produce(
new ChatMessageProducer('event_friend_apply', [ new ChatMessageProducer(SocketConstants::EVENT_FRIEND_APPLY, [
'sender' => $user_id, 'sender' => $user_id,
'receive' => (int)$params['friend_id'], 'receive' => (int)$params['friend_id'],
'type' => 1, 'type' => 1,

View File

@ -240,7 +240,7 @@ class TalkService extends BaseService
* @param int $record_id 上一次查询的聊天记录ID * @param int $record_id 上一次查询的聊天记录ID
* @param int $limit 查询数据长度 * @param int $limit 查询数据长度
* @param array $msg_type 消息类型 * @param array $msg_type 消息类型
* @return mixed * @return array
*/ */
public function getChatRecords(int $user_id, int $receive_id, int $source, int $record_id, $limit = 30, $msg_type = []) public function getChatRecords(int $user_id, int $receive_id, int $source, int $record_id, $limit = 30, $msg_type = [])
{ {
@ -417,7 +417,6 @@ class TalkService extends BaseService
* @param int $record_id 转发消息的记录ID * @param int $record_id 转发消息的记录ID
* @param array $receive_ids 接受者数组 例如:[['source' => 1,'id' => 3045],['source' => 1,'id' => 3046],['source' => 1,'id' => 1658]] 二维数组 * @param array $receive_ids 接受者数组 例如:[['source' => 1,'id' => 3045],['source' => 1,'id' => 3046],['source' => 1,'id' => 1658]] 二维数组
* @return array * @return array
* @throws \Exception
*/ */
public function forwardRecords(int $user_id, int $record_id, array $receive_ids) public function forwardRecords(int $user_id, int $record_id, array $receive_ids)
{ {
@ -477,7 +476,7 @@ class TalkService extends BaseService
'save_dir' => $fileInfo->save_dir, 'save_dir' => $fileInfo->save_dir,
'created_at' => date('Y-m-d H:i:s') 'created_at' => date('Y-m-d H:i:s')
])) { ])) {
throw new \Exception('插入文件消息记录失败'); throw new Exception('插入文件消息记录失败');
} }
} else if ($result->msg_type == 5) { } else if ($result->msg_type == 5) {
if (!ChatRecordsCode::create([ if (!ChatRecordsCode::create([
@ -487,7 +486,7 @@ class TalkService extends BaseService
'code' => $codeBlock->code, 'code' => $codeBlock->code,
'created_at' => date('Y-m-d H:i:s') 'created_at' => date('Y-m-d H:i:s')
])) { ])) {
throw new \Exception('插入代码消息记录失败'); throw new Exception('插入代码消息记录失败');
} }
} }
} }
@ -696,17 +695,17 @@ class TalkService extends BaseService
$insert = ChatRecord::create($message); $insert = ChatRecord::create($message);
if (!$insert) { if (!$insert) {
throw new \Exception('插入聊天记录失败...'); throw new Exception('插入聊天记录失败...');
} }
$fileInfo['record_id'] = $insert->id; $fileInfo['record_id'] = $insert->id;
$fileInfo['created_at'] = date('Y-m-d H:i:s'); $fileInfo['created_at'] = date('Y-m-d H:i:s');
if (!ChatRecordsFile::create($fileInfo)) { if (!ChatRecordsFile::create($fileInfo)) {
throw new \Exception('插入聊天记录(文件消息)失败...'); throw new Exception('插入聊天记录(文件消息)失败...');
} }
Db::commit(); Db::commit();
} catch (\Exception $e) { } catch (Exception $e) {
Db::rollBack(); Db::rollBack();
return false; return false;
} }
@ -728,17 +727,17 @@ class TalkService extends BaseService
$message['created_at'] = date('Y-m-d H:i:s'); $message['created_at'] = date('Y-m-d H:i:s');
$insert = ChatRecord::create($message); $insert = ChatRecord::create($message);
if (!$insert) { if (!$insert) {
throw new \Exception('插入聊天记录失败...'); throw new Exception('插入聊天记录失败...');
} }
$codeBlock['record_id'] = $insert->id; $codeBlock['record_id'] = $insert->id;
$codeBlock['created_at'] = date('Y-m-d H:i:s'); $codeBlock['created_at'] = date('Y-m-d H:i:s');
if (!ChatRecordsCode::create($codeBlock)) { if (!ChatRecordsCode::create($codeBlock)) {
throw new \Exception('插入聊天记录(代码消息)失败...'); throw new Exception('插入聊天记录(代码消息)失败...');
} }
Db::commit(); Db::commit();
} catch (\Exception $e) { } catch (Exception $e) {
Db::rollBack(); Db::rollBack();
return false; return false;
} }
@ -760,17 +759,17 @@ class TalkService extends BaseService
$message['created_at'] = date('Y-m-d H:i:s'); $message['created_at'] = date('Y-m-d H:i:s');
$insert = ChatRecord::create($message); $insert = ChatRecord::create($message);
if (!$insert) { if (!$insert) {
throw new \Exception('插入聊天记录失败...'); throw new Exception('插入聊天记录失败...');
} }
$emoticon['record_id'] = $insert->id; $emoticon['record_id'] = $insert->id;
$emoticon['created_at'] = date('Y-m-d H:i:s'); $emoticon['created_at'] = date('Y-m-d H:i:s');
if (!ChatRecordsFile::create($emoticon)) { if (!ChatRecordsFile::create($emoticon)) {
throw new \Exception('插入聊天记录(代码消息)失败...'); throw new Exception('插入聊天记录(代码消息)失败...');
} }
Db::commit(); Db::commit();
} catch (\Exception $e) { } catch (Exception $e) {
Db::rollBack(); Db::rollBack();
return false; return false;
} }
@ -792,17 +791,17 @@ class TalkService extends BaseService
$message['created_at'] = date('Y-m-d H:i:s'); $message['created_at'] = date('Y-m-d H:i:s');
$insert = ChatRecord::create($message); $insert = ChatRecord::create($message);
if (!$insert) { if (!$insert) {
throw new \Exception('插入聊天记录失败...'); throw new Exception('插入聊天记录失败...');
} }
$emoticon['record_id'] = $insert->id; $emoticon['record_id'] = $insert->id;
$emoticon['created_at'] = date('Y-m-d H:i:s'); $emoticon['created_at'] = date('Y-m-d H:i:s');
if (!ChatRecordsFile::create($emoticon)) { if (!ChatRecordsFile::create($emoticon)) {
throw new \Exception('插入聊天记录(代码消息)失败...'); throw new Exception('插入聊天记录(代码消息)失败...');
} }
Db::commit(); Db::commit();
} catch (\Exception $e) { } catch (Exception $e) {
Db::rollBack(); Db::rollBack();
return false; return false;
} }

View File

@ -112,7 +112,9 @@ function response()
/** /**
* 从HTML文本中提取所有图片 * 从HTML文本中提取所有图片
* @param $content *
* @param string $content HTML文本
*
* @return array * @return array
*/ */
function get_html_images($content) function get_html_images($content)
@ -133,8 +135,9 @@ function get_html_images($content)
/** /**
* 获取两个日期相差多少天 * 获取两个日期相差多少天
* *
* @param $day1 * @param string $day1 日期1
* @param $day2 * @param string $day2 日期2
*
* @return float|int * @return float|int
*/ */
function diff_date($day1, $day2) function diff_date($day1, $day2)
@ -153,6 +156,7 @@ function diff_date($day1, $day2)
* 获取媒体文件url * 获取媒体文件url
* *
* @param string $path 文件相对路径 * @param string $path 文件相对路径
*
* @return string * @return string
*/ */
function get_media_url(string $path) function get_media_url(string $path)
@ -166,6 +170,7 @@ function get_media_url(string $path)
* @param string $ext 图片后缀名 * @param string $ext 图片后缀名
* @param int $width 图片宽度 * @param int $width 图片宽度
* @param int $height 图片高度 * @param int $height 图片高度
*
* @return string * @return string
*/ */
function create_image_name(string $ext, int $width, int $height) function create_image_name(string $ext, int $width, int $height)
@ -176,7 +181,8 @@ function create_image_name(string $ext, int $width, int $height)
/** /**
* 替换文本中的url a标签 * 替换文本中的url a标签
* *
* @param string $str * @param string $str 字符串
*
* @return null|string|string[] * @return null|string|string[]
*/ */
function replace_url_link(string $str) function replace_url_link(string $str)