全部
常见问题
产品动态
精选推荐

Pro系统开启游客咨询客服功能的代码修改教程

管理 管理 编辑 删除

涉及大量代码修改,请备份相关被修改文件

逻辑如下

本身客服系统自带游客功能,对代码进行了适当的修改,让游客信息能顺利入库

不可忽视的问题

找大佬继续优化

  1. 游客uid用的时间戳,如果你的已注册会员数量达到10位数,会与已注册会员冲突,而且当并发比较高的时候,比如恰好1秒内有2个游客同时咨询,也会冲突
  2. 为了让游客获取到聊天记录,取消了聊天记录的验证(需要大佬解决),会泄露
  3. 没有对游客聊天记录定时清理

php代码修改

app/controller/api/v2/user/StoreService.php

修改从第46行开始,将   function record  后面的 {}  里面的内容修改为

        [$uidTo, $limit, $toUid, $touristUid] = $request->getMore([
            [['uidTo', 'd'], 0],
            [['limit', 'd'], 10],
            [['toUid', 'd'], 0],
            [['touristUid', 'd'], 0],
        ], true);
        $uid = $request->uid();
        if (!$uid) {
            $uid = $touristUid;
        }
        return app('json')->successful($services->getRecord($uid, $uidTo, $limit, $toUid));

app/websocket/Manager.php

跳到第85行,将    function onOpen  里面的代码修改为

        $fd = $this->websocket->getSender();
        $type = $request->get('type');
        $token = $request->get('token', '');
        $touristUid = $request->get('tourist_uid', '');
        $tourist = !!$touristUid;
        /*if (!$token || !in_array($type, self::USER_TYPE)) {
            return $this->websocket->close();
        }*/
        if ($token === 'undefined' || $token === 'false') {
            $token = '';
        }
        if ($token === '') {
            $tourist = true;
            if (empty($touristUid)) {
                $touristUid = time();
            }
        }
        // 只有用户模式下才能使用游客模式
        if ($type !== self::USER_TYPE[1] && $tourist) {
            return $this->websocket->close();
        }

        $types = self::USER_TYPE;
        $this->nowRoom->type(array_flip($types)[$type]);
        try {
            $data = $this->exec($type, 'login', [$fd, $request->get('form_type', null), ['token' => $token, 'tourist' => $tourist], $this->response])->getData();
        } catch (\Throwable $e) {
            return $this->websocket->close();
        }
        if ($tourist) {
            $data['status'] = 200;
            $data['data']['uid'] = $touristUid;
        }
        if ($data['status'] != 200 || !($data['data']['uid'] ?? null)) {
            return $this->websocket->close();
        }
        $this->resetPingTimeout($this->pingInterval + $this->pingTimeout);
        $uid = $data['data']['uid'];
        $type = array_search($type, self::USER_TYPE);
        $this->login($type, $uid, $fd);
        $this->nowRoom->add((string)$fd, $uid, 0, $tourist ? 1 : 0);
        $this->send($fd, $this->response->message('ping', ['now' => time()]));
        return $this->send($fd, $this->response->success($data['data']));

app/websocket/BaseHandler.php

找到第61行,将    abstract public function login(array $data = [], Response $response);  修改为
   abstract public function login($data, Response $response);

找到第126行,将    $data['is_tourist'] = $data['is_tourist'] ?? 0;  修改为
   $data['is_tourist'] = $isTourist ? 1 : 0;

app/websocket/handler/目录下的四个文件,依次修改

找到    public function login(array $data = [], Response $response)  修改为
   public function login($data, Response $response)

并且在 {  后面添加以下代码

        if (!is_array($data)) {
            $data = [];
        }

route/api.php

搜索 v2.user.StoreService/record  ,将整行代码移动到下方 授权不通过,不会抛出异常继续执行  的 {}  里面

前端Vue代码修改

所有代码目录以 view/uniapp  为根目录

api/user.js

找到    function getChatRecord  ,将 {}  的代码修改为

	return request.get("v2/user/service/record", data, {
		noAuth: true
	});

libs/new_chat.js

找到第82行到101行,将代码修改为

	onStart: function(token, form_type, tourist_uid) {
		let wssUrl = `${VUE_APP_WS_URL}`
		this.ws = uni.connectSocket({
			// #ifdef H5
			url: wss(wssUrl + '?type=user&token=' + token + '&form_type=' + form_type + '&tourist_uid=' + tourist_uid),
			// #endif
			// #ifdef MP || APP-PLUS
			url: wssUrl + '?type=user&token=' + token + '&form_type=' + form_type + '&tourist_uid=' + tourist_uid,
			// #endif
			header: {
				'content-type': 'application/json'
			},
			method: 'GET',
			success: (res) => {}
		});
		this.ws.onOpen(this.onSocketOpen.bind(this))
		this.ws.onError(this.onError.bind(this));
		this.ws.onMessage(this.onMessage.bind(this))
		this.ws.onClose(this.onClose.bind(this));
	}

pages/customer_list/chat.vue

代码修改较多,直接贴整个script代码段,请将   的内容修改成以下代码


最后使用HBuilder重新打包前端

地瓜叶 最后编辑于2022-10-27 11:37:14

快捷回复
回复({{post_count}}) {{!is_user ? '我的回复' :'全部回复'}}
回复从新到旧

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}} 作者 管理员 企业

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest==1? '取消推荐': '推荐'}}
{{item.floor}}#
{{item.user_info.title}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
{{item.like_count}}
{{item.showReply ? '取消回复' : '回复'}}
删除
回复
回复

{{itemc.user_info.nickname}}

{{itemc.user_name}}

作者 管理员 企业

回复 {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}   {{itemc.ip_address}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回复' : '回复'}}
删除
回复
回复
查看更多
回复
回复
1609
{{like_count}}
{{collect_count}}
添加回复 ({{post_count}})

相关推荐

地瓜叶 作者
暂无简介

回答

0

发布

0

经验

713

快速安全登录

使用微信扫码登录
{{item.label}} {{item.label}} {{item.label}} 板块推荐 常见问题 产品动态 精选推荐 首页头条 首页动态 首页推荐
加精
取 消 确 定
回复
回复
问题:
问题自动获取的帖子内容,不准确时需要手动修改. [获取答案]
答案:
提交
bug 需求 取 消 确 定

快速安全登录

使用微信扫码登录

手机登录

{{codeText}}
{{isQrcode ? '手机登录' : '扫码登录'}}
CRMEB客服

CRMEB咨询热线 咨询热线

400-8888-794

微信扫码咨询

CRMEB开源商城下载 开源下载 CRMEB官方论坛 帮助文档
返回顶部 返回顶部
CRMEB客服