Skip to content

Commit

Permalink
swoole添加ssl证书支持
Browse files Browse the repository at this point in the history
  • Loading branch information
icharle committed Sep 15, 2018
1 parent 57f8636 commit 28de8dc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/node_modules
/public/hot
/public/storage
/storage/*.key
/storage/ssl/*.key
/storage/ssl/*.pem
/vendor
/.idea
/.vscode
Expand Down
6 changes: 5 additions & 1 deletion app/Console/Commands/Swoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ public function handle()
*/
private function start()
{
$this->ws = new swoole_websocket_server("0.0.0.0", 9502);
$this->ws = new swoole_websocket_server("0.0.0.0", 9502, SWOOLE_PROCESS, SWOOLE_SOCK_TCP | SWOOLE_SSL);
$this->ws->set(array(
'ssl_cert_file' => storage_path().'/ssl/fullchain.pem',
'ssl_key_file' => storage_path().'/ssl/fullchain.key',
));
//监听WebSocket连接打开事件
$this->ws->on('open', function ($ws, $request) {
$site = $request->get['site']; // 得到用户ID
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function GetQrcode($site)
{
$wechat = new Wxtool();
$scene = uniqid() . mt_rand(100000, 999999); // 场景值(随机生成)
$img = $wechat->GetQrcode($scene, 'pages/other/main');
$img = $wechat->GetQrcode($scene, 'pages/scan/main');
LoginInfo::create(['scene' => $scene, 'site_id' => $site]);
$arr = array('scene' => $scene, 'image' => $img);
return $arr;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function store(CheckSiteRequest $request)
{
$data = $request->all();
$userInfo = Auth::guard('api')->user();
SiteInfo::create(['sitename' => $data['sitename'], 'sitelogo' => $data['sitelogo'], 'sitedesc' => $data['sitedesc'], 'openId_id' => $userInfo['openId']]);
SiteInfo::create(['site' => uniqid(),'sitename' => $data['sitename'], 'sitelogo' => $data['sitelogo'], 'sitedesc' => $data['sitedesc'], 'openId_id' => $userInfo['openId']]);
return response()->json([
'status' => 200,
'message' => 'Save success'
Expand Down

0 comments on commit 28de8dc

Please sign in to comment.