diff --git a/controller/response.go b/controller/response.go
index ebe4b10..41c985f 100644
--- a/controller/response.go
+++ b/controller/response.go
@@ -27,3 +27,7 @@ type GetuiResponse struct {
Msg string `json:"msg"`
Data map[string]interface{} `json:"data"`
}
+type VisitorExtra struct {
+ VisitorName string `json:"visitorName"`
+ VisitorAvatar string `json:"visitorAvatar"`
+}
diff --git a/controller/visitor.go b/controller/visitor.go
index 98cc9ce..99f8e15 100644
--- a/controller/visitor.go
+++ b/controller/visitor.go
@@ -1,6 +1,7 @@
package controller
import (
+ "encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/taoshihan1991/imaptool/config"
@@ -62,7 +63,7 @@ func PostVisitorLogin(c *gin.Context) {
avator := fmt.Sprintf("/static/images/%d.jpg", rand.Intn(14))
toId := c.PostForm("to_id")
id := c.PostForm("visitor_id")
- extra := c.PostForm("extra")
+
if id == "" {
id = tools.Uuid()
}
@@ -79,6 +80,21 @@ func PostVisitorLogin(c *gin.Context) {
name = "匿名网友"
}
client_ip := c.ClientIP()
+ extra := c.PostForm("extra")
+ extraJson := tools.Base64Decode(extra)
+ //log.Println(extra, extraJson, "aaaaaaaaaaaaa")
+ if extraJson != "" {
+ var extraObj VisitorExtra
+ err := json.Unmarshal([]byte(extraJson), &extraObj)
+ if err == nil {
+ if extraObj.VisitorName != "" {
+ name = extraObj.VisitorName
+ }
+ if extraObj.VisitorAvatar != "" {
+ avator = extraObj.VisitorAvatar
+ }
+ }
+ }
//log.Println(name,avator,c.ClientIP(),toId,id,refer,city,client_ip)
if name == "" || avator == "" || toId == "" || id == "" || refer == "" || city == "" || client_ip == "" {
c.JSON(200, gin.H{
diff --git a/models/visitors.go b/models/visitors.go
index 6252219..3e692b9 100644
--- a/models/visitors.go
+++ b/models/visitors.go
@@ -18,7 +18,7 @@ func CreateVisitor(name, avator, sourceIp, toId, visitorId, refer, city, clientI
old := FindVisitorByVistorId(visitorId)
if old.Name != "" {
//更新状态上线
- UpdateVisitor(visitorId, 1, clientIp, sourceIp, refer, extra)
+ UpdateVisitor(name, avator, visitorId, 1, clientIp, sourceIp, refer, extra)
return
}
v := &Visitor{
@@ -67,13 +67,15 @@ func UpdateVisitorStatus(visitorId string, status uint) {
visitor := Visitor{}
DB.Model(&visitor).Where("visitor_id = ?", visitorId).Update("status", status)
}
-func UpdateVisitor(visitorId string, status uint, clientIp string, sourceIp string, refer, extra string) {
+func UpdateVisitor(name, avator, visitorId string, status uint, clientIp string, sourceIp string, refer, extra string) {
visitor := &Visitor{
Status: status,
ClientIp: clientIp,
SourceIp: sourceIp,
Refer: refer,
Extra: extra,
+ Name: name,
+ Avator: avator,
}
DB.Model(visitor).Where("visitor_id = ?", visitorId).Update(visitor)
}
diff --git a/static/html/index.html b/static/html/index.html
index 65caa45..85f2f6e 100644
--- a/static/html/index.html
+++ b/static/html/index.html
@@ -21,12 +21,16 @@
diff --git a/static/js/chat-main.js b/static/js/chat-main.js
index 0776f1c..6656d79 100644
--- a/static/js/chat-main.js
+++ b/static/js/chat-main.js
@@ -390,6 +390,7 @@ var app=new Vue({
if(extra[key]==""){
extra[key]="无";
}
+ if(key=="visitorAvatar"||key=="visitorName") continue;
var temp={key:key,val:extra[key]}
_this.visitorExtra.push(temp);
}
diff --git a/static/js/chat-page.js b/static/js/chat-page.js
index fddc287..d4bebb4 100644
--- a/static/js/chat-page.js
+++ b/static/js/chat-page.js
@@ -162,6 +162,18 @@ new Vue({
}
let _this=this;
var extra=getQuery("extra");
+ if(extra!=""){
+ var extraJson=JSON.parse(window.atob(extra))
+ for(var key in extraJson){
+ if(extraJson[key]==""){
+ _this.$message({
+ message: "用户扩展信息错误",
+ type: 'error'
+ });
+ return;
+ }
+ }
+ }
//发送消息
$.post("/visitor_login",{visitor_id:visitor_id,refer:REFER,to_id:KEFU_ID,extra:extra},function(res){
if(res.code!=200){
diff --git a/tools/hash.go b/tools/hash.go
index 5eb9dff..c6754f6 100644
--- a/tools/hash.go
+++ b/tools/hash.go
@@ -3,7 +3,9 @@ package tools
import (
"crypto/md5"
"crypto/sha256"
+ "encoding/base64"
"encoding/hex"
+ "strings"
)
//md5加密
@@ -21,3 +23,19 @@ func Sha256(src string) string {
res := hex.EncodeToString(m.Sum(nil))
return res
}
+func Base64Decode(str string) string {
+ reader := strings.NewReader(str)
+ decoder := base64.NewDecoder(base64.RawStdEncoding, reader)
+ // 以流式解码
+ buf := make([]byte, 1024)
+ // 保存解码后的数据
+ dst := ""
+ for {
+ n, err := decoder.Read(buf)
+ dst += string(buf[:n])
+ if n == 0 || err != nil {
+ break
+ }
+ }
+ return dst
+}