客服系统源码接口文档-99客服

客服系统源码接口文档

接口文档返回值统一为json格式,并且一定包含code和msg的值,例如

{"code":0, "msg":"ok"}

当code不为0时,代表发生了错误,错误信息会包含在msg中,例如

{"code":1, "msg":"缺少参数"}

除了code和msg字段,还可能存在data字段,data字段用于传递接口的返回结果

例如 /api/user/get 接口返回的结果为

{"code":0,"msg":"ok","data":{"uid":"XkdDsPpw","bid":"fbad7a64cfd5369s8b918fc24f6e409a","nickname":"\u8bbf\u5ba2XkaDyPpw","avatar":"\/static\/user_avatar.jpg","state":"offline","logout_timestamp":1581679560,"timestamp":1581679560,"account_state":"normal","ip":"223.104.20.109","user_agent":"Mozilla\/5.0 (iPhone; CPU iPhone OS 12_3_1 like Mac OS X) AppleWebKit\/605.1.15 (KHTML, like Gecko) Version\/12.1.1 Mobile\/15E148 Safari\/604.1","city":"\u4e2d\u56fd \u6e56\u5317   420000","refer":"https:\/\/www.99kf.com\/","phone":"","email":"","remark":"","address":"","qq":"","realname":"","others":""}}

访客页面接口

访客页面

说明:生成并存储访客信息,展示访客侧对话页面

地址:/user

类型:GET

参数:

返回值:访客侧对话页面

访客页面获取当前访客的信息

/user/data/get

类型:GET

参数:

返回值:

{
    "code": 0,
    "msg": "ok",
    "data": {
        "user": {
            "nickname": "访客XkYTCPRG",
            "avatar": "\/static\/user_avatar.jpg",
            "uid": "XkYTCPRG",
            "channel": "user-fbad7a64cfd56b198b918fc24f6e409a-586b595443505247"
        },
        "setting": {
            "id": 1,
            "appkey": "c090ffdb6953309ca31c9878e7689e65",
            "ws_address": "wss:\/\/ws.99kf.com:443",
            "appname": "99客服",
            "exp_day": 7,
            "voice": "on",
            "sound": "on",
            "upload_file": "on",
            "upload_img": "on",
            "emoji": "on",
            "verified": 1,
            "paid": 17
        }
    }
}

其中 channel 是一个用户标识,用来全局唯一标记一个用户用于websocket推送。与uid不同,不同商家的访客uid可能会相同,而channel会保证全局唯一。

访客页面分配客服

/user/chatting/find

类型:GET

参数: 无

返回:

{
    "code": 0,
    "msg": "ok",
    "data": {
        "faq": [{
            "qid": 77,
            "question": "什么时候发货"
        },{
            "qid": 78,
            "question": "是否支持货到付款"
        },],
        "kf_id": 8,
        "nickname": "99客服",
        "avatar": "\/\/chat.99kf.com\/upload\/avatars\/201909\/XZBRvDP1\/295d9051bceeaf.png",
        "greeting": "您好,请问有什么可以帮您?"
    }
}

faq字段为常见问题列表。greeting字段为问候语。

访客发送消息给客服

/user/message/send

类型:POST

参数:

content特殊消息格式

返回:

{"code":0,"msg":"ok","data":{"mid":"105142"}}

mid为消息表的主键id

访客页面获取历史消息

/user/message/get

类型:GET

参数:

返回:

{
    "code": 0,
    "msg": "ok",
    "data": [{
        "mid": 105143,
        "from": "XktRnNa",
        "nickname": "访客XktRnNa",
        "avatar": "\/static\/user_avatar.jpg",
        "timestamp": 1581994401,
        "content": "你好",
        "sub_type": "message",
        "author": "user"
    },{
        "mid": 105144,
        "from": "36",
        "nickname": "客服名称",
        "avatar": "\/static\/avatar.jpg",
        "timestamp": 1581994404,
        "content": "你好",
        "sub_type": "message",
        "author": "kefu"
    }]
}

访客获取与某个客服的未读消息数

/user/message/unreadcount

类型:GET

参数:

返回:

{
    "code": 0,
    "msg": "ok",
    "data": 8
}

访客更新未读消息时间戳

/user/message/updateLastReadTime

类型:POST

参数:

返回:

{
    "code": 0,
    "msg": "ok"
}

访客上传文件

/user/upload/file

类型:POST

参数:

返回:

{
    "code": 0,
    "msg": "ok",
    "data": {
        "src": "\/\/chat.99kf.com\/upload\/files\/202002\/183e4b544c206c.txt",
        "name": "测试.txt",
        "size": "4.59 KB"
    }
}

访客上传图片

/user/upload/img

类型:POST

参数:

返回:

{
    "code": 0,
    "msg": "ok",
    "data": {
        "src": "\/\/chat.99kf.com\/upload\/images\/202002\/18536876081523.jpg",
        "name": "tet.jpg",
        "size": "13.65 KB"
    }
}

客服页面接口

客服页面

/kefu/

类型:GET

参数:无

返回:

客服页面

说明:

客服页面为单页面应用,html模版在 appplication/kefu/view/index/下的 index.html mobile.html,分别为PC页面和移动端页面。

客服页面获取该客服聚合数据

/api/data/get

类型:GET

参数:无

返回:

{
    "code": 0,
    "msg": "ok",
    "data": {
        "chatting": {
            "userXf4BfhN8": {
                "id": "Xf4BfhN8",
                "name": "访客Xf4BfhN8",
                "type": "user",
                "timestamp": 1576927614,
                "unread_count": 0,
                "account_state": "normal",
                "items": [{
                    "from": 8,
                    "name": "99客服",
                    "avatar": "\/\/chat.99kf.com\/upload\/avatars\/201909\/XZBRvDP1\/295d9051bceeaf.png",
                    "content": "这里",
                    "timestamp": 1576930325,
                    "sub_type": "message",
                    "mid": "54300",
                    "author": "kefu"
                }],
                "uid": "Xf4BfhN8",
                "bid": "fbad7a64cfd56b198b918fc24f6e409a",
                "nickname": "访客Xf4BfhN8",
                "avatar": "\/static\/user_avatar.jpg",
                "state": "offline",
                "logout_timestamp": 1576927924,
                "ip": "69.176.89.32",
                "user_agent": "Mozilla\/5.0 (Windows NT 6.1; WOW64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/63.0.3239.132 Safari\/537.36",
                "city": "中国 香港   ",
                "refer": "https:\/\/www.99kf.com\/",
                "phone": "",
                "email": "",
                "remark": "",
                "address": "",
                "qq": "",
                "realname": "",
                "others": ""
            },
            "userXf9nyekH": {
                "id": "Xf9nyekH",
                "name": "访客Xf9nyekH",
                "type": "user",
                "timestamp": 1577019337,
                "unread_count": 0,
                "account_state": "normal",
                "items": [{
                    "from": 8,
                    "name": "99客服",
                    "avatar": "\/\/chat.99kf.com\/upload\/avatars\/201909\/XZBRvDP1\/295d9051bceeaf.png",
                    "content": "![图片](\/\/chat.99kf.com\/upload\/images\/201912\/225dff75e9cc56.png)",
                    "timestamp": 1577022953,
                    "sub_type": "message",
                    "mid": "55238",
                    "author": "kefu"
                }],
                "uid": "Xf9nyekH",
                "bid": "fbad7a64cfd56b198b918fc24f6e409a",
                "nickname": "访客Xf9nyekH",
                "avatar": "\/static\/user_avatar.jpg",
                "state": "offline",
                "logout_timestamp": 1577019626,
                "ip": "171.112.51.62",
                "user_agent": "Mozilla\/5.0 (Windows NT 6.1; WOW64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/70.0.3538.25 Safari\/537.36 Core\/1.70.3722.400 QQBrowser\/10.5.3751.400",
                "city": "中国 湖北 孝感  420900",
                "refer": "https:\/\/www.99kf.com\/",
                "phone": "",
                "email": "",
                "remark": "",
                "address": "",
                "qq": "",
                "realname": "",
                "others": ""
            }
        },
        "kefu": {
            "nickname": "99客服",
            "username": "99kf",
            "avatar": "\/\/chat.99kf.com\/upload\/avatars\/201909\/XZBRvDP1\/295d9051bceeaf.png",
            "kf_id": 8,
            "level": "manager",
            "greeting": "您好,请问有什么可以帮您?",
            "bid": "fbad7a64cfd56b198b918fc24f6e409a"
        },
        "kefu_groups": [{
            "groupid": 0,
            "groupname": "默认分组"
        }],
        "setting": {
            "id": 6,
            "appkey": "c090ffdb6953309ca31c9878e7689e65",
            "ws_address": "wss:\/\/ws.99kf.com:443",
            "appname": "99客服",
            "bid": "fbad7a64cfd56b198b918fc24f6e409a",
            "kf_id": 8,
            "voice": "on",
            "sound": "on",
            "upload_file": "on",
            "upload_img": "on",
            "emoji": "on",
            "dirty_words": null,
            "account_state": "normal",
            "regist_timestamp": 1569729678,
            "exp_timestamp": 4263957900,
            "verified": 1
        }
    }
}

chatting字段为聊天列表字段,chatting.items字段为与对应访客的最后一条消息数据。

kefu_groups字段为客服分组字段。

setting字段为系统设置相关字段。

客服删除与某个访客的会话

/api/chatting/delete

类型:POST

参数:

返回:

{"code":0,"msg":"ok","data":[]}

客服给访客发消息

/api/message/send

类型:POST

参数:

返回:

{"code":0,"msg":"ok","data":{"mid":"105158"}}

获取与某个访客的历史消息

/api/message/get

类型:POST

参数:

返回:

{
    "code": 0,
    "msg": "ok",
    "data": [{
        "mid": 105081,
        "from": "XkkQa5jA",
        "nickname": "访客XkkQa5jA",
        "avatar": "\/static\/user_avatar.jpg",
        "timestamp": 1581846642,
        "content": "测试",
        "sub_type": "message",
        "author": "user"
    }]
}

访客获取与某个访客的未读消息数

/api/message/unreadcount

类型:GET

参数:

返回:

{
    "code": 0,
    "msg": "ok",
    "data": 8
}

更新与某个访客未读消息时间戳

/api/message/updateLastReadTime

类型:POST

参数:

返回:

{
    "code": 0,
    "msg": "ok"
}

客服上传文件

/user/upload/file

类型:POST

参数:

返回:

{
    "code": 0,
    "msg": "ok",
    "data": {
        "src": "\/\/chat.99kf.com\/upload\/files\/202002\/183e4b544c206c.txt",
        "name": "测试.txt",
        "size": "4.59 KB"
    }
}

客服上传图片

/user/upload/img

类型:POST

参数:

返回:

{
    "code": 0,
    "msg": "ok",
    "data": {
        "src": "\/\/chat.99kf.com\/upload\/images\/202002\/18536876081523.jpg",
        "name": "tet.jpg",
        "size": "13.65 KB"
    }
}

购买客服系统源码请点击这里