-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
306 changed files
with
28,405 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,40 @@ | ||
# sword | ||
phpSword开发框架 | ||
PHP-Sword 0.0.1 | ||
=============== | ||
|
||
[![Latest Stable Version](https://poser.pugx.org/php-sword/sword/v)](//packagist.org/packages/php-sword/sword) [![Total Downloads](https://poser.pugx.org/php-sword/sword/downloads)](//packagist.org/packages/php-sword/sword) [![PHP Version](https://img.shields.io/badge/php-%3E%3D7.1-8892BF.svg)](http://www.php.net/) [![License](https://poser.pugx.org/php-sword/sword/license)](//packagist.org/packages/php-sword/sword) | ||
|
||
> Sword是一个基于Swoole的Tcp协议框架,同时支持http-api接口,精简、轻量、高度定制自己的业务需求。 | ||
## 主要特性 | ||
|
||
* 采用`PHP7`强类型(严格模式) | ||
* 支持更多的`PSR`规范 | ||
|
||
## 安装 | ||
|
||
~~~ | ||
composer create-project php-sword/sword sword 0.* | ||
~~~ | ||
|
||
如果需要更新框架使用 | ||
~~~ | ||
composer update php-sword/sword | ||
~~~ | ||
|
||
## 文档 | ||
|
||
开发文档: [http://sword.kyour.cn/doc](http://sword.kyour.cn/doc) | ||
|
||
## 参与开发 | ||
|
||
> 直接提交PR或者Issue即可 | ||
## 版权信息 | ||
|
||
Sword遵循Apache2开源协议发布,并提供免费使用。 | ||
|
||
本项目包含的第三方源码和二进制文件之版权信息另行标注。 | ||
|
||
版权所有Copyright © 2020 by Kyour (http://kyour.cn) All rights reserved。 | ||
|
||
更多细节参阅 [LICENSE.txt](LICENSE.txt) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* This file is part of Sword. | ||
* @link http://sword.kyour.cn | ||
* @document http://sword.kyour.cn/doc | ||
* @contact [email protected] | ||
* @license http://github.com/php-sword/sword/blob/master/LICENSE | ||
*/ | ||
|
||
use sword\Redis; | ||
/** | ||
* | ||
*/ | ||
function djson($status, $msg, $data = []){ | ||
return json_encode([ | ||
'status' => $status, | ||
'message' => $msg, | ||
'data' => $data | ||
],JSON_UNESCAPED_UNICODE);; | ||
} | ||
|
||
function session($fd, $data = null){ | ||
if($data == null){ | ||
$ret = Redis::get('sword_user_'.$fd); | ||
return $ret == null?null:unserialize($ret); | ||
} | ||
|
||
Redis::set('sword_user_'.$fd,serialize($data)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?php | ||
namespace app\controller; | ||
|
||
use sword\Redis; | ||
use sword\orm\Db; | ||
use app\packer\CsipPacker; | ||
|
||
class Csip | ||
{ | ||
private $server; | ||
private $fd; | ||
private $csip; | ||
|
||
//入口函数 | ||
public function handle($server, $fd, $csip) | ||
{ | ||
//功能码与方法绑定 | ||
$action = [ | ||
'C01A' => 'login', | ||
'C03B' => 'broadcast', | ||
'C04G' => 'getGroup' | ||
]; | ||
|
||
$this->server = $server; | ||
$this->fd = $fd; | ||
$this->csip = $csip; | ||
|
||
if(isset($action[$csip->funcCode])){ | ||
//取出方法名 | ||
$action_name = $action[$csip->funcCode]; | ||
$this->$action_name($server,$fd,$csip); | ||
}else{ | ||
echo "未定义的功能码:".$csip->funcCode."\n".$csip->encode(); | ||
} | ||
|
||
} | ||
|
||
//登录用户 | ||
public function login() | ||
{ | ||
$ret = new CsipPacker(); | ||
|
||
//定义为广播事件 | ||
$ret->bodyParam['broadcast'] = 1; | ||
|
||
//设置事件名称 -登录返回结果 | ||
$ret->bodyParam['event'] = 'loginCallBack'; | ||
|
||
//查询用户 | ||
$check = Db::queryOne("SELECT uid,realname,phone,avatar,status FROM `jz_user` WHERE `phone` = ? and `password` = ? LIMIT 1", | ||
[$this->csip->bodyParam['uname'],md5($this->csip->bodyParam['pwd'])]); | ||
|
||
if(!$check){ | ||
$ret->bodyData = djson(1, '账号密码错误'); | ||
$this->server->send($this->fd, $ret->encode()); | ||
}else{ | ||
session(config('app.userFd').$check['uid'],$this->fd); | ||
|
||
$rets = Db::execUp("UPDATE jz_im_group_user SET fd=? WHERE uid=?", [$this->fd,$check['uid']]); | ||
|
||
$ret->bodyData = djson(0, '登陆成功'.$rets, $check); | ||
$this->server->send($this->fd, $ret->encode()); | ||
|
||
$this->getGroup(); | ||
// $ret->bodyData = djson(0, session($this->fd)); | ||
|
||
} | ||
|
||
echo "发送数据:".$ret->encode()."\n"; | ||
|
||
} | ||
|
||
//获取分组 | ||
public function getGroup() | ||
{ | ||
$ret = new CsipPacker(); | ||
|
||
//定义为广播事件 | ||
$ret->bodyParam['broadcast'] = 1; | ||
|
||
//设置事件名称 -登录返回结果 | ||
$ret->bodyParam['event'] = 'groupRefresh'; | ||
|
||
if(isset($this->csip->bodyParam['uid'])){ | ||
$check = Db::query("SELECT any_value(g.id) as id,any_value(g.name) as name FROM jz_im_group as g join jz_im_group_user as gu on gu.imId=g.id WHERE gu.uid = ? group by gu.imId",[$this->csip->bodyParam['uid']]); | ||
$this->server->send($this->fd, "ok\r\n"); | ||
$this->fd = session(config('app.userFd').$this->csip->bodyParam['uid']); | ||
}else{ | ||
$check = Db::query("SELECT any_value(g.id) as id,any_value(g.name) as name FROM jz_im_group as g join jz_im_group_user as gu on gu.imId=g.id WHERE gu.fd = ? group by gu.imId",[$this->fd]); | ||
} | ||
if($check == NULL){ | ||
$check = []; | ||
} | ||
$ret->bodyData = djson(0, 'ok', $check); | ||
$this->server->send($this->fd, $ret->encode()); | ||
} | ||
|
||
//广播语音 | ||
public function broadcast() | ||
{ | ||
$conn_list = Db::name('im_group_user') | ||
->where(['uid'=>['<>', $this->csip->bodyParam['uid']], 'imId'=>$this->csip->bodyParam['group_id']]) | ||
->select(); | ||
|
||
//功能码 | ||
$this->csip->funcCode = 'S03B'; | ||
|
||
$data = $this->csip->encode(); | ||
//遍历数组发送数据 | ||
foreach ($conn_list as $k) { | ||
if($this->server->exist($k['fd'])){ | ||
$this->server->send($k['fd'], $data); | ||
} | ||
} | ||
|
||
} | ||
|
||
//使用实例 | ||
public function db() | ||
{ | ||
$data = Db::name('user') | ||
->field('uid,phone') | ||
->where(['uid','<',10]) | ||
->select(); | ||
print_r($data); | ||
|
||
Redis::set('user','private'); | ||
echo Redis::get('user'); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.