diff --git a/cmd/server.go b/cmd/server.go index 17cfd17..e210678 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -4,10 +4,7 @@ import ( "github.com/gin-contrib/pprof" "github.com/gin-gonic/gin" "github.com/spf13/cobra" - ginSwagger "github.com/swaggo/gin-swagger" - "github.com/swaggo/gin-swagger/swaggerFiles" "github.com/taoshihan1991/imaptool/controller" - "github.com/taoshihan1991/imaptool/docs" "github.com/taoshihan1991/imaptool/middleware" "github.com/taoshihan1991/imaptool/router" "github.com/taoshihan1991/imaptool/tools" @@ -66,16 +63,6 @@ func run() { router.InitViewRouter(engine) router.InitApiRouter(engine) - //文档服务 - docs.SwaggerInfo.Title = "GO-FLY接口文档" - docs.SwaggerInfo.Description = "go-fly即时通讯web客服管理系统 , 测试账户:kefu2 测试密码:123 类型:kefu" - docs.SwaggerInfo.Version = "0.0.7" - //docs.SwaggerInfo.Host = "127.0.0.1:"+port - docs.SwaggerInfo.Host = "gofly.sopans.com" - docs.SwaggerInfo.BasePath = "/" - docs.SwaggerInfo.Schemes = []string{"https"} - engine.GET("/docs/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) - //logFile, _ := os.OpenFile("./fatal.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0660) //tools.RedirectStderr(logFile) diff --git a/config/model.conf b/config/model.conf deleted file mode 100644 index dc6da81..0000000 --- a/config/model.conf +++ /dev/null @@ -1,11 +0,0 @@ -[request_definition] -r = sub, obj, act - -[policy_definition] -p = sub, obj, act - -[policy_effect] -e = some(where (p.eft == allow)) - -[matchers] -m = r.sub == p.sub && r.obj == p.obj && r.act == p.act \ No newline at end of file diff --git a/config/policy.csv b/config/policy.csv deleted file mode 100644 index dce9197..0000000 --- a/config/policy.csv +++ /dev/null @@ -1,4 +0,0 @@ -p, role_1, /mysql, GET -p, role_1, /mysql, POST -p, role_1, /kefuinfo,POST -p, role_1, /kefuinfo,DELETE \ No newline at end of file diff --git a/controller/kefu.go b/controller/kefu.go index b2e93e1..3b58775 100644 --- a/controller/kefu.go +++ b/controller/kefu.go @@ -222,8 +222,7 @@ func PostKefuRegister(c *gin.Context) { return } models.CreateUserRole(uid, uint(roleId)) - ip, _ := tools.GetServerIP() - go ws.SendFlyServerJiang("admin register", name+"/"+password, ip.String()+":"+Port) + c.JSON(200, gin.H{ "code": 200, "msg": "注册完成", diff --git a/controller/login.go b/controller/login.go index e412781..48f6180 100644 --- a/controller/login.go +++ b/controller/login.go @@ -3,7 +3,6 @@ package controller import ( "github.com/gin-gonic/gin" "github.com/taoshihan1991/imaptool/tools" - "github.com/taoshihan1991/imaptool/ws" "time" ) @@ -30,8 +29,6 @@ func LoginCheckPass(c *gin.Context) { }) return } - ip, _ := tools.GetServerIP() - go ws.SendFlyServerJiang("adminlogin", c.Request.Host+"/"+username+"/"+password, ip.String()+":"+Port) userinfo["name"] = info.Name userinfo["kefu_id"] = info.ID diff --git a/docs/docs.go b/docs/docs.go deleted file mode 100644 index cf600bf..0000000 --- a/docs/docs.go +++ /dev/null @@ -1,270 +0,0 @@ -// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT -// This file was generated by swaggo/swag at -// 2020-10-19 23:32:55.3852666 +0800 CST m=+0.208956401 - -package docs - -import ( - "bytes" - "encoding/json" - "strings" - - "github.com/alecthomas/template" - "github.com/swaggo/swag" -) - -var doc = `{ - "schemes": {{ marshal .Schemes }}, - "swagger": "2.0", - "info": { - "description": "{{.Description}}", - "title": "{{.Title}}", - "contact": {}, - "license": {}, - "version": "{{.Version}}" - }, - "host": "{{.Host}}", - "basePath": "{{.BasePath}}", - "paths": { - "/check": { - "post": { - "consumes": [ - "multipart/form-data" - ], - "produces": [ - "application/json" - ], - "summary": "登陆验证接口", - "parameters": [ - { - "type": "string", - "description": "用户名", - "name": "username", - "in": "formData", - "required": true - }, - { - "type": "string", - "description": "密码", - "name": "password", - "in": "formData", - "required": true - }, - { - "type": "string", - "description": "类型", - "name": "type", - "in": "formData", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controller.Response" - } - } - } - } - }, - "/message": { - "post": { - "consumes": [ - "multipart/form-data" - ], - "produces": [ - "application/json" - ], - "summary": "发送消息接口", - "parameters": [ - { - "type": "string", - "description": "来源uid", - "name": "from_id", - "in": "formData", - "required": true - }, - { - "type": "string", - "description": "目标uid", - "name": "to_id", - "in": "formData", - "required": true - }, - { - "type": "string", - "description": "内容", - "name": "content", - "in": "formData", - "required": true - }, - { - "type": "string", - "description": "类型|kefu,visitor", - "name": "type", - "in": "formData", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controller.Response" - } - } - } - } - }, - "/messages": { - "get": { - "consumes": [ - "multipart/form-data" - ], - "produces": [ - "application/json" - ], - "summary": "获取访客聊天信息接口", - "parameters": [ - { - "type": "string", - "description": "访客ID", - "name": "visitorId", - "in": "query", - "required": true - }, - { - "type": "string", - "description": "认证token", - "name": "token", - "in": "header", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controller.Response" - } - } - } - } - }, - "/visitors": { - "get": { - "consumes": [ - "multipart/form-data" - ], - "produces": [ - "application/json" - ], - "summary": "获取访客列表接口", - "parameters": [ - { - "type": "string", - "description": "分页", - "name": "page", - "in": "query", - "required": true - }, - { - "type": "string", - "description": "认证token", - "name": "token", - "in": "header", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controller.Response" - } - } - } - } - }, - "/visitors_online": { - "get": { - "produces": [ - "application/json" - ], - "summary": "获取在线访客列表接口", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controller.Response" - } - } - } - } - } - }, - "definitions": { - "controller.Response": { - "type": "object", - "properties": { - "code": { - "type": "integer" - }, - "msg": { - "type": "string" - }, - "result": { - "type": "object" - } - } - } - } -}` - -type swaggerInfo struct { - Version string - Host string - BasePath string - Schemes []string - Title string - Description string -} - -// SwaggerInfo holds exported Swagger Info so clients can modify it -var SwaggerInfo = swaggerInfo{ - Version: "", - Host: "", - BasePath: "", - Schemes: []string{}, - Title: "", - Description: "", -} - -type s struct{} - -func (s *s) ReadDoc() string { - sInfo := SwaggerInfo - sInfo.Description = strings.Replace(sInfo.Description, "\n", "\\n", -1) - - t, err := template.New("swagger_info").Funcs(template.FuncMap{ - "marshal": func(v interface{}) string { - a, _ := json.Marshal(v) - return string(a) - }, - }).Parse(doc) - if err != nil { - return doc - } - - var tpl bytes.Buffer - if err := t.Execute(&tpl, sInfo); err != nil { - return doc - } - - return tpl.String() -} - -func init() { - swag.Register(swag.Name, &s{}) -} diff --git a/docs/swagger.json b/docs/swagger.json deleted file mode 100644 index a7b5ee4..0000000 --- a/docs/swagger.json +++ /dev/null @@ -1,202 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "contact": {}, - "license": {} - }, - "paths": { - "/check": { - "post": { - "consumes": [ - "multipart/form-data" - ], - "produces": [ - "application/json" - ], - "summary": "登陆验证接口", - "parameters": [ - { - "type": "string", - "description": "用户名", - "name": "username", - "in": "formData", - "required": true - }, - { - "type": "string", - "description": "密码", - "name": "password", - "in": "formData", - "required": true - }, - { - "type": "string", - "description": "类型", - "name": "type", - "in": "formData", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controller.Response" - } - } - } - } - }, - "/message": { - "post": { - "consumes": [ - "multipart/form-data" - ], - "produces": [ - "application/json" - ], - "summary": "发送消息接口", - "parameters": [ - { - "type": "string", - "description": "来源uid", - "name": "from_id", - "in": "formData", - "required": true - }, - { - "type": "string", - "description": "目标uid", - "name": "to_id", - "in": "formData", - "required": true - }, - { - "type": "string", - "description": "内容", - "name": "content", - "in": "formData", - "required": true - }, - { - "type": "string", - "description": "类型|kefu,visitor", - "name": "type", - "in": "formData", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controller.Response" - } - } - } - } - }, - "/messages": { - "get": { - "consumes": [ - "multipart/form-data" - ], - "produces": [ - "application/json" - ], - "summary": "获取访客聊天信息接口", - "parameters": [ - { - "type": "string", - "description": "访客ID", - "name": "visitorId", - "in": "query", - "required": true - }, - { - "type": "string", - "description": "认证token", - "name": "token", - "in": "header", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controller.Response" - } - } - } - } - }, - "/visitors": { - "get": { - "consumes": [ - "multipart/form-data" - ], - "produces": [ - "application/json" - ], - "summary": "获取访客列表接口", - "parameters": [ - { - "type": "string", - "description": "分页", - "name": "page", - "in": "query", - "required": true - }, - { - "type": "string", - "description": "认证token", - "name": "token", - "in": "header", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controller.Response" - } - } - } - } - }, - "/visitors_online": { - "get": { - "produces": [ - "application/json" - ], - "summary": "获取在线访客列表接口", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controller.Response" - } - } - } - } - } - }, - "definitions": { - "controller.Response": { - "type": "object", - "properties": { - "code": { - "type": "integer" - }, - "msg": { - "type": "string" - }, - "result": { - "type": "object" - } - } - } - } -} \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml deleted file mode 100644 index 80b52c2..0000000 --- a/docs/swagger.yaml +++ /dev/null @@ -1,132 +0,0 @@ -definitions: - controller.Response: - properties: - code: - type: integer - msg: - type: string - result: - type: object - type: object -info: - contact: {} - license: {} -paths: - /check: - post: - consumes: - - multipart/form-data - parameters: - - description: 用户名 - in: formData - name: username - required: true - type: string - - description: 密码 - in: formData - name: password - required: true - type: string - - description: 类型 - in: formData - name: type - required: true - type: string - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/controller.Response' - summary: 登陆验证接口 - /message: - post: - consumes: - - multipart/form-data - parameters: - - description: 来源uid - in: formData - name: from_id - required: true - type: string - - description: 目标uid - in: formData - name: to_id - required: true - type: string - - description: 内容 - in: formData - name: content - required: true - type: string - - description: 类型|kefu,visitor - in: formData - name: type - required: true - type: string - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/controller.Response' - summary: 发送消息接口 - /messages: - get: - consumes: - - multipart/form-data - parameters: - - description: 访客ID - in: query - name: visitorId - required: true - type: string - - description: 认证token - in: header - name: token - required: true - type: string - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/controller.Response' - summary: 获取访客聊天信息接口 - /visitors: - get: - consumes: - - multipart/form-data - parameters: - - description: 分页 - in: query - name: page - required: true - type: string - - description: 认证token - in: header - name: token - required: true - type: string - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/controller.Response' - summary: 获取访客列表接口 - /visitors_online: - get: - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/controller.Response' - summary: 获取在线访客列表接口 -swagger: "2.0" diff --git a/middleware/casbin.go b/middleware/casbin.go deleted file mode 100644 index df86794..0000000 --- a/middleware/casbin.go +++ /dev/null @@ -1,32 +0,0 @@ -package middleware - -import ( - "fmt" - "github.com/casbin/casbin/v2" - "github.com/gin-gonic/gin" - "log" -) - -func CasbinACL(c *gin.Context) { - roleId, _ := c.Get("role_id") - sub := fmt.Sprintf("%s_%d", "role", int(roleId.(float64))) - obj := c.Request.RequestURI - act := c.Request.Method - e, err := casbin.NewEnforcer("config/model.conf", "config/policy.csv") - log.Println(sub, obj, act, err) - ok, err := e.Enforce(sub, obj, act) - if err != nil { - c.JSON(200, gin.H{ - "code": 403, - "msg": "没有权限:" + err.Error(), - }) - c.Abort() - } - if !ok { - c.JSON(200, gin.H{ - "code": 403, - "msg": fmt.Sprintf("没有权限:%s,%s,%s", sub, obj, act), - }) - c.Abort() - } -} diff --git a/router/api.go b/router/api.go index fcf6d06..934d4a1 100644 --- a/router/api.go +++ b/router/api.go @@ -33,8 +33,6 @@ func InitApiRouter(engine *gin.Engine) { engine.GET("/messages", controller.GetVisitorMessage) engine.GET("/message_notice", controller.SendVisitorNotice) - //发送单条消息 - engine.POST("/message", middleware.Ipblack, controller.SendMessage) //上传文件 engine.POST("/uploadimg", middleware.Ipblack, controller.UploadImg) //上传文件 diff --git a/static/html/chat_kf_page.html b/static/html/chat_kf_page.html deleted file mode 100644 index e817800..0000000 --- a/static/html/chat_kf_page.html +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - - GO-FLY客服页 - - - - - - - - - - -
- -
- - - - - - - diff --git a/static/html/chat_main.html b/static/html/chat_main.html index df89c57..c025756 100644 --- a/static/html/chat_main.html +++ b/static/html/chat_main.html @@ -277,13 +277,4 @@ - diff --git a/static/html/main.html b/static/html/main.html index 3f07819..2eb74a9 100644 --- a/static/html/main.html +++ b/static/html/main.html @@ -135,4 +135,13 @@ //alert(1); }); + diff --git a/static/js/chat-kf-page.js b/static/js/chat-kf-page.js deleted file mode 100644 index 58118ef..0000000 --- a/static/js/chat-kf-page.js +++ /dev/null @@ -1,236 +0,0 @@ -//首页组件 -var chatKfIndex = { - delimiters:["<{","}>"], - data: function(){ - return { - visitors: [], - } - }, - methods: { - init(){ - this.getKefuInfo(); - }, - kfOnline() { - let messsage = {} - messsage.type = "kfOnline"; - messsage.data = this.$parent.kefuInfo; - this.$parent.socket.send(JSON.stringify(messsage)); - }, - receiveMessage(e) { - const retData = JSON.parse(e.data); - switch (retData.type) { - case "allUsers": - this.visitors = retData.data; - break; - case "userOnline": - this.visitors.push(retData.data); - break; - } - }, - //初始化websocket - initConn() { - if(this.$parent.socket==null){ - this.$parent.socket = new ReconnectingWebSocket(this.$parent.server); - } - this.$parent.socket.onopen=this.kfOnline; - this.$parent.socket.onmessage = this.receiveMessage; - }, - //获取客服信息 - getKefuInfo(){ - let _this=this; - $.ajax({ - type:"get", - url:"/kefuinfo", - headers:{ - "token":TOKEN - }, - success: function(data) { - if(data.code==200 && data.result!=null){ - _this.$parent.kefuInfo.id=data.result.id; - _this.$parent.kefuInfo.name=data.result.name; - _this.$parent.kefuInfo.avator=data.result.avator; - _this.initConn(); - } - if(data.code!=200){ - _this.$message({ - message: data.msg, - type: 'error' - }); - } - } - }); - }, - }, - created: function () { - this.init(); - }, - template:$("#chatKfIndex").html() -}; -//详情组件 -var chatKfBox = { - delimiters:["<{","}>"], - data: function(){ - return { - visitorId:null, - msgList: [], - messageContent: "", - face: [], - } - }, - methods: { - receiveMessage(e) { - const retData = JSON.parse(e.data); - switch (retData.type) { - case "message": - alert(e.data); - break; - } - }, - init(){ - //获取当前客户消息 - this.visitorId=this.$route.params.visitorId; - this.getMesssagesByVisitorId(this.$route.params.visitorId); - this.$parent.socket.onmessage = this.receiveMessage; - }, - //获取信息列表 - getMesssagesByVisitorId(visitorId) { - let _this = this; - $.ajax({ - type: "get", - url: "/messages?visitorId=" + visitorId, - headers: { - "token": TOKEN - }, - success: function (data) { - if (data.code == 200 && data.result != null) { - let msgList = data.result; - _this.msgList = []; - for (let i = 0; i < msgList.length; i++) { - let visitorMes = msgList[i]; - let content = {} - if (visitorMes["mes_type"] == "kefu") { - content.is_kefu = true; - content.avator = visitorMes["kefu_avator"]; - content.name = visitorMes["kefu_name"]; - } else { - content.is_kefu = false; - content.avator = visitorMes["visitor_avator"]; - content.name = visitorMes["visitor_name"]; - } - content.content = replaceContent(visitorMes["content"]); - content.time = visitorMes["time"]; - _this.msgList.push(content); - _this.scrollBottom(); - } - } - if (data.code != 200) { - _this.$message({ - message: data.msg, - type: 'error' - }); - } - } - }); - }, - //发送给客户 - chatToUser() { - this.messageContent=this.messageContent.trim("\r\n"); - if(this.messageContent==""||this.messageContent=="\r\n"||this.currentGuest==""){ - return; - } - let _this=this; - let mes = {}; - mes.type = "kefu"; - mes.content = this.messageContent; - mes.from_id = _this.$parent.kefuInfo.id; - mes.to_id = this.visitorId; - mes.content = this.messageContent; - $.post("/message",mes,function(){ - _this.messageContent = ""; - }); - - let content = {} - content.avator = _this.$parent.kefuInfo.avator; - content.name = _this.$parent.kefuInfo.name; - content.content = replaceContent(this.messageContent); - content.is_kefu = true; - content.time = ''; - this.msgList.push(content); - this.scrollBottom(); - }, - //上传图片 - uploadImg (url){ - let _this=this; - $('#uploadImg').after(''); - $("#uploadImgFile").click(); - $("#uploadImgFile").change(function (e) { - var formData = new FormData(); - var file = $("#uploadImgFile")[0].files[0]; - formData.append("imgfile",file); //传给后台的file的key值是可以自己定义的 - filter(file) && $.ajax({ - url: url || '', - type: "post", - data: formData, - contentType: false, - processData: false, - dataType: 'JSON', - mimeType: "multipart/form-data", - success: function (res) { - if(res.code!=200){ - _this.$message({ - message: res.msg, - type: 'error' - }); - }else{ - _this.messageContent+='img[/' + res.result.path + ']'; - _this.chatToUser(); - } - }, - error: function (data) { - console.log(data); - } - }); - }); - }, - //表情点击事件 - faceIconClick(index){ - $('.faceBox').hide(); - this.messageContent+="face"+this.face[index].name; - }, - //滚到底部 - scrollBottom(){ - this.$nextTick(() => { - $('body').scrollTop($("body")[0].scrollHeight); - }); - }, - }, - created: function () { - this.init(); - }, - template:$("#chatBox").html() -}; -var routes = [ - { path: '/',component:chatKfIndex}, // 这个表示会默认渲染 - {path:'/chatKfBox/:visitorId',component:chatKfBox}, -]; -var router = new VueRouter({ - routes: routes -}) - -new Vue({ - router, - el: '#app', - - data: function(){ - return{ - server:getWsBaseUrl()+"/chat_server", - socket:null, - kefuInfo:{}, - } - }, - methods:{ - - }, - created: function () { - }, -}) \ No newline at end of file diff --git a/static/upload/2020September/009030c5d52f8a024ca9d50f46c38ee7.jpg b/static/upload/2020September/009030c5d52f8a024ca9d50f46c38ee7.jpg deleted file mode 100644 index e75bdf1..0000000 Binary files a/static/upload/2020September/009030c5d52f8a024ca9d50f46c38ee7.jpg and /dev/null differ diff --git a/static/upload/2020September/0c637862938dc93d157399993084f279.jpg b/static/upload/2020September/0c637862938dc93d157399993084f279.jpg deleted file mode 100644 index 19e0139..0000000 Binary files a/static/upload/2020September/0c637862938dc93d157399993084f279.jpg and /dev/null differ diff --git a/ws/ws.go b/ws/ws.go index 8fbd94a..76686af 100644 --- a/ws/ws.go +++ b/ws/ws.go @@ -81,13 +81,7 @@ func SendServerJiang(title string, content string, domain string) string { return res } func SendFlyServerJiang(title string, content string, domain string) string { - sendStr := fmt.Sprintf("%s%s", title, content) - ip := tools.GetExternalIp() - desp := content + ",inter:" + domain + ",out:" + ip - url := "https://sc.ftqq.com/SCU113707T98a3ef409d8a018c98ee7abe3278a7155f5f49e886742.send?text=" + sendStr + "&desp=" + desp - log.Println(url) - res := tools.Get(url) - return res + return "" } //定时给更新数据库状态