123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- /**
- * Created by PhpStorm.
- * User: phperstar
- * Date: 2020/11/6
- * Time: 11:15 AM
- */
- namespace Service;
- use Mall\Framework\Factory;
- class BaseController {
- /**
- * webstock链接保存在那个key下面
- */
- static $webstockAndKey = 'webstockAndKey';
- public function sendOutput($data, $errorcode = 0)
- {
- $errorcode = intval($errorcode);
- if ($errorcode) {
- $sendMessage = [
- 'state' => false,
- 'data' => $data,
- 'errorcode' => $errorcode
- ];
- } else {
- $sendMessage = [
- 'state' => true,
- 'data' => $data,
- 'errorcode' => $errorcode
- ];
- }
- return json_encode($sendMessage, JSON_UNESCAPED_UNICODE);
- }
- // 暂存一下每个webstock链接保存的位置
- public function webstockConnectInfo($fromId, $redisKey)
- {
- // webstock连接和存储关系
- $writeCache = Factory::cache('default')->hset(self::$webstockAndKey, $fromId, $redisKey);
- }
- // 销毁连接
- public function closeWebstock($fromId)
- {
- $data = Factory::cache('default')->hget(self::$webstockAndKey, $fromId);
- if(empty($data)){
- return false;
- }
- $data = explode('|', $data);
- $result = Factory::cache('default')->hdel($data[0], $data[1]);
- $result = Factory::cache('default')->hdel(self::$webstockAndKey, $fromId);
- return $result;
- }
- }
|