初始化

main
gzydong 2020-12-02 17:15:32 +08:00
parent 09b09bbc14
commit 495a3b8b5b
8 changed files with 87 additions and 108 deletions

View File

@ -1,10 +0,0 @@
<?php
namespace App\Helper;
class JsonHelper
{
}

View File

@ -126,7 +126,6 @@ class GroupService extends BaseService
Db::beginTransaction();
try {
UsersGroup::where('id', $group_id)->update(['status' => 1]);
UsersGroupMember::where('group_id', $group_id)->update(['status' => 1]);
Db::commit();
@ -217,8 +216,6 @@ class GroupService extends BaseService
Db::commit();
} catch (\Exception $e) {
Db::rollBack();
logger()->error($e);
return [false, 0];
}

View File

@ -2,7 +2,12 @@
namespace App\Service;
/**
* 聊天室房间服务
*
* Class SocketRoomService
* @package App\Service
*/
class SocketRoomService
{
const ROOM = 'ws:room';

View File

@ -1,6 +1,5 @@
<?php
namespace App\Service;
use App\Model\FileSplitUpload;
@ -15,6 +14,9 @@ use Hyperf\HttpMessage\Upload\UploadedFile;
*/
class SplitUploadService
{
/**
* 文件拆分的大小
*/
const SPLIT_SIZE = 2 * 1024 * 1024;
/**
@ -23,6 +25,8 @@ class SplitUploadService
* @param int $user_id 用户ID
* @param string $fileName 上传的文件名
* @param string $fileSize 上传文件大小
*
* @return array|bool
*/
public function create(int $user_id, string $fileName, string $fileSize)
{
@ -46,11 +50,15 @@ class SplitUploadService
}
/**
* @param int $user_id
* 保存拆分上传的文件
*
* @param int $user_id 用户ID
* @param UploadedFile $file 文件信息
* @param string $hashName 上传临时问价hash名
* @param int $split_index 当前拆分文件索引
* @param int $fileSize 文件大小
*
* @return bool
*/
public function upload(int $user_id, UploadedFile $file, string $hashName, int $split_index, int $fileSize)
{
@ -95,16 +103,29 @@ class SplitUploadService
/**
* 文件合并
*
* @param int $user_id 用户ID
* @param string $hash_name 上传临时问价hash名
*
* @return array|bool
*/
public function merge(int $user_id, string $hash_name)
{
$fileInfo = FileSplitUpload::select(['id', 'original_name', 'split_num', 'file_ext', 'file_size'])->where('user_id', $user_id)->where('hash_name', $hash_name)->where('file_type', 1)->first();
$fileInfo = FileSplitUpload::select(['id', 'original_name', 'split_num', 'file_ext', 'file_size'])
->where('user_id', $user_id)
->where('hash_name', $hash_name)
->where('file_type', 1)
->first();
if (!$fileInfo) {
return false;
}
$files = FileSplitUpload::where('user_id', $user_id)->where('hash_name', $hash_name)->where('file_type', 2)->orderBy('split_index', 'asc')->get(['split_index', 'save_dir'])->toArray();
$files = FileSplitUpload::where('user_id', $user_id)
->where('hash_name', $hash_name)
->where('file_type', 2)
->orderBy('split_index', 'asc')
->get(['split_index', 'save_dir'])->toArray();
if (!$files) {
return false;
}
@ -113,16 +134,20 @@ class SplitUploadService
return false;
}
$dir = config('filesystems.disks.uploads.root');
$fileMerge = "tmp/{$hash_name}/{$fileInfo->original_name}.tmp";
$uploadService = make(UploadService::class);
$merge_save_parh = $uploadService->driver($fileMerge);
// 文件合并
$merge_save_path = $uploadService->driver($fileMerge);
foreach ($files as $file) {
file_put_contents($merge_save_parh, file_get_contents($uploadService->driver($file['save_dir'])), FILE_APPEND);
file_put_contents($merge_save_path, file_get_contents($uploadService->driver($file['save_dir'])), FILE_APPEND);
}
FileSplitUpload::select(['id', 'original_name', 'split_num', 'file_ext', 'file_size'])->where('user_id', $user_id)->where('hash_name', $hash_name)->where('file_type', 1)->update(['save_dir' => $fileMerge]);
FileSplitUpload::select(['id', 'original_name', 'split_num', 'file_ext', 'file_size'])
->where('user_id', $user_id)->where('hash_name', $hash_name)
->where('file_type', 1)
->update(['save_dir' => $fileMerge]);
return [
'path' => $fileMerge,
'tmp_file_name' => "{$fileInfo->original_name}.tmp",

View File

@ -509,7 +509,8 @@ class TalkService extends BaseService
* @param int $source 消息来源 1:好友消息 2:群聊消息
* @param array $records_ids 转发消息的记录ID
* @param array $receive_ids 接受者数组 例如:[['source' => 1,'id' => 3045],['source' => 1,'id' => 3046],['source' => 1,'id' => 1658]] 二维数组
* @return array
*
* @return array|bool
*/
public function mergeForwardRecords(int $user_id, int $receive_id, int $source, $records_ids, array $receive_ids)
{
@ -556,26 +557,28 @@ class TalkService extends BaseService
$jsonText = [];
foreach ($rows as $row) {
if ($row->msg_type == 1) {
switch ($row->msg_type) {
case 1:
$jsonText[] = [
'nickname' => $row->nickname,
'text' => mb_substr(str_replace(PHP_EOL, "", $row->content), 0, 30)
];
} else if ($row->msg_type == 2) {
break;
case 2:
$jsonText[] = [
'nickname' => $row->nickname,
'text' => '【文件消息】'
];
} else if ($row->msg_type == 5) {
break;
case 3:
$jsonText[] = [
'nickname' => $row->nickname,
'text' => '【代码消息】'
];
break;
}
}
$jsonText = json_encode($jsonText);
$insRecordIds = [];
Db::beginTransaction();
try {
@ -602,7 +605,7 @@ class TalkService extends BaseService
'record_id' => $res->id,
'user_id' => $user_id,
'records_id' => implode(',', $records_ids),
'text' => $jsonText,
'text' => json_encode($jsonText),
'created_at' => date('Y-m-d H:i:s'),
])) {
throw new Exception('插入转发消息失败');

View File

@ -55,7 +55,7 @@ class UserService extends BaseService
{
Db::beginTransaction();
try {
$data['password'] = create_password($data['password']);
$data['password'] = Hash::make($data['password']);
$data['created_at'] = date('Y-m-d H:i:s');
$result = User::create($data);

View File

@ -1,5 +1,11 @@
<?php
/*
|--------------------------------------------------------------------------
| Common function method
|--------------------------------------------------------------------------
*/
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Hyperf\Logger\LoggerFactory;
@ -13,6 +19,8 @@ use Hyperf\Redis\Redis;
/**
* 容器实例
*
* @return \Psr\Container\ContainerInterface
*/
function container()
{
@ -21,6 +29,8 @@ function container()
/**
* Redis 客户端实例
*
* @return Redis|mixed
*/
function redis()
{
@ -37,7 +47,6 @@ function server()
return container()->get(ServerFactory::class)->getServer()->getServer();
}
/**
* websocket frame 实例
*/
@ -82,7 +91,9 @@ function logger(string $name = 'APP')
}
/**
* http 请求实例
* Http 请求实例
*
* @return mixed|ServerRequestInterface
*/
function request()
{
@ -91,23 +102,14 @@ function request()
/**
* 请求响应
*
* @return ResponseInterface|mixed
*/
function response()
{
return container()->get(ResponseInterface::class);
}
/**
* 获取加密后的密码字符
*
* @param string $password
* @return bool|false|null|string
*/
function create_password(string $password)
{
return password_hash($password, PASSWORD_DEFAULT);
}
/**
* 从HTML文本中提取所有图片
* @param $content
@ -147,7 +149,6 @@ function diff_date($day1, $day2)
return ceil(($second1 - $second2) / 86400);
}
/**
* 获取媒体文件url
*
@ -188,9 +189,11 @@ function replace_url_link(string $str)
/**
* 二维数组排序
*
* @param array $array 数组
* @param string $field 排序字段
* @param int $sort 排序方式
*
* @return array
*/
function arraysSort(array $array, $field, $sort = SORT_DESC)
@ -199,12 +202,12 @@ function arraysSort(array $array, $field, $sort = SORT_DESC)
return $array;
}
/**
* 判断0或正整数
*
* @param string $int 验证字符串
* @param bool $isZero 判断是否可为0
*
* @return bool
*/
function check_int($int, $isZero = false)
@ -213,6 +216,13 @@ function check_int($int, $isZero = false)
return is_numeric($int) && preg_match($reg, $int);
}
/**
* 解析英文逗号',' 拼接的 ID 字符串
*
* @param string $ids 字符串(例如; "1,2,3,4,5,6")
*
* @return array
*/
function parse_ids($ids)
{
return array_unique(explode(',', trim($ids)));

View File

@ -1,51 +0,0 @@
<?php
require './vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
$config = [
'host' => 'smtp.163.com',
'port' => 465,
'username' => '18798276809@163.com',
'password' => 'RYD18798276809',
'from' => [
'address' => '18798276809@163.com',
'name' => 'Lumen IM 在线聊天',
],
'encryption' => 'ssl',
];
$mail = new PHPMailer(true);
try {
//Server settings
$mail->CharSet = 'UTF-8'; //设定邮件编码默认ISO-8859-1如果发中文此项必须设置否则乱码
$mail->IsSMTP(); // 设定使用SMTP服务
$mail->SMTPDebug = 0; // 关闭SMTP调试功能
$mail->SMTPAuth = true; // 启用 SMTP 验证功能
$mail->SMTPAutoTLS = false;
$mail->Host = $config['host']; // Set the SMTP server to send through
$mail->Port = intval($config['port']); // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
$mail->Username = $config['username']; // SMTP username
$mail->Password = $config['password']; // SMTP password
$mail->SMTPSecure = $config['encryption']; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
//Recipients
$mail->setFrom($config['from']['address'], $config['from']['name']);
$mail->addAddress('837215079@qq.com'); // Name is optional
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}