增加集成扩展用户信息并修改原用户信息

pull/23/head
陶士涵 4 years ago
parent bc3b89fc0e
commit 66622fc786

@ -27,3 +27,7 @@ type GetuiResponse struct {
Msg string `json:"msg"` Msg string `json:"msg"`
Data map[string]interface{} `json:"data"` Data map[string]interface{} `json:"data"`
} }
type VisitorExtra struct {
VisitorName string `json:"visitorName"`
VisitorAvatar string `json:"visitorAvatar"`
}

@ -1,6 +1,7 @@
package controller package controller
import ( import (
"encoding/json"
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/taoshihan1991/imaptool/config" "github.com/taoshihan1991/imaptool/config"
@ -62,7 +63,7 @@ func PostVisitorLogin(c *gin.Context) {
avator := fmt.Sprintf("/static/images/%d.jpg", rand.Intn(14)) avator := fmt.Sprintf("/static/images/%d.jpg", rand.Intn(14))
toId := c.PostForm("to_id") toId := c.PostForm("to_id")
id := c.PostForm("visitor_id") id := c.PostForm("visitor_id")
extra := c.PostForm("extra")
if id == "" { if id == "" {
id = tools.Uuid() id = tools.Uuid()
} }
@ -79,6 +80,21 @@ func PostVisitorLogin(c *gin.Context) {
name = "匿名网友" name = "匿名网友"
} }
client_ip := c.ClientIP() 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) //log.Println(name,avator,c.ClientIP(),toId,id,refer,city,client_ip)
if name == "" || avator == "" || toId == "" || id == "" || refer == "" || city == "" || client_ip == "" { if name == "" || avator == "" || toId == "" || id == "" || refer == "" || city == "" || client_ip == "" {
c.JSON(200, gin.H{ c.JSON(200, gin.H{

@ -18,7 +18,7 @@ func CreateVisitor(name, avator, sourceIp, toId, visitorId, refer, city, clientI
old := FindVisitorByVistorId(visitorId) old := FindVisitorByVistorId(visitorId)
if old.Name != "" { if old.Name != "" {
//更新状态上线 //更新状态上线
UpdateVisitor(visitorId, 1, clientIp, sourceIp, refer, extra) UpdateVisitor(name, avator, visitorId, 1, clientIp, sourceIp, refer, extra)
return return
} }
v := &Visitor{ v := &Visitor{
@ -67,13 +67,15 @@ func UpdateVisitorStatus(visitorId string, status uint) {
visitor := Visitor{} visitor := Visitor{}
DB.Model(&visitor).Where("visitor_id = ?", visitorId).Update("status", status) 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{ visitor := &Visitor{
Status: status, Status: status,
ClientIp: clientIp, ClientIp: clientIp,
SourceIp: sourceIp, SourceIp: sourceIp,
Refer: refer, Refer: refer,
Extra: extra, Extra: extra,
Name: name,
Avator: avator,
} }
DB.Model(visitor).Where("visitor_id = ?", visitorId).Update(visitor) DB.Model(visitor).Where("visitor_id = ?", visitorId).Update(visitor)
} }

@ -21,12 +21,16 @@
<!--对接客服代码--> <!--对接客服代码-->
<script src="/static/js/gofly-front.js?v=1"></script> <script src="/static/js/gofly-front.js?v=1"></script>
<script> <script>
var refer=document.referrer;
if(refer==""){
refer="无";
}
GOFLY.init({ GOFLY.init({
GOFLY_URL:"", GOFLY_URL:"",
GOFLY_KEFU_ID: "kefu2", GOFLY_KEFU_ID: "kefu2",
GOFLY_BTN_TEXT: "{{.OnlineChat}}", GOFLY_BTN_TEXT: "{{.OnlineChat}}",
GOFLY_LANG:"{{.Lang}}", GOFLY_LANG:"{{.Lang}}",
GOFLY_EXTRA:'{"refer":"'+document.referrer+'"}', GOFLY_EXTRA:'{"refer":"'+refer+'"}',
}) })
</script> </script>
<!--//对接客服代码--> <!--//对接客服代码-->

@ -390,6 +390,7 @@ var app=new Vue({
if(extra[key]==""){ if(extra[key]==""){
extra[key]="无"; extra[key]="无";
} }
if(key=="visitorAvatar"||key=="visitorName") continue;
var temp={key:key,val:extra[key]} var temp={key:key,val:extra[key]}
_this.visitorExtra.push(temp); _this.visitorExtra.push(temp);
} }

@ -162,6 +162,18 @@ new Vue({
} }
let _this=this; let _this=this;
var extra=getQuery("extra"); 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){ $.post("/visitor_login",{visitor_id:visitor_id,refer:REFER,to_id:KEFU_ID,extra:extra},function(res){
if(res.code!=200){ if(res.code!=200){

@ -3,7 +3,9 @@ package tools
import ( import (
"crypto/md5" "crypto/md5"
"crypto/sha256" "crypto/sha256"
"encoding/base64"
"encoding/hex" "encoding/hex"
"strings"
) )
//md5加密 //md5加密
@ -21,3 +23,19 @@ func Sha256(src string) string {
res := hex.EncodeToString(m.Sum(nil)) res := hex.EncodeToString(m.Sum(nil))
return res 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
}

Loading…
Cancel
Save