diff --git a/controller/visitor.go b/controller/visitor.go index 443fa72..6a5fd78 100644 --- a/controller/visitor.go +++ b/controller/visitor.go @@ -2,13 +2,11 @@ package controller import ( "encoding/json" - "fmt" "github.com/gin-gonic/gin" "github.com/taoshihan1991/imaptool/common" "github.com/taoshihan1991/imaptool/models" "github.com/taoshihan1991/imaptool/tools" "github.com/taoshihan1991/imaptool/ws" - "math/rand" "strconv" ) @@ -60,7 +58,14 @@ import ( //} func PostVisitorLogin(c *gin.Context) { ipcity := tools.ParseIp(c.ClientIP()) - avator := fmt.Sprintf("/static/images/%d.jpg", rand.Intn(14)) + avator:="" + userAgent := c.GetHeader("User-Agent") + if tools.IsMobile(userAgent) { + avator = "/static/images/phone.png" + } else { + avator = "/static/images/computer.png" + } + toId := c.PostForm("to_id") id := c.PostForm("visitor_id") diff --git a/static/css/common.css b/static/css/common.css index ab88075..b059e6d 100644 --- a/static/css/common.css +++ b/static/css/common.css @@ -393,7 +393,10 @@ a{color: #07a9fe;text-decoration: none;} } .chatTitle{height: 30px;line-height: 30px;color: #1989fa} -.chatBoxSend{background: #fff;height: 100px;} +.chatBoxSend{ + background: #fff;height: 100px; + position: relative; +} .chatBoxSendBtn{float: right;margin: 12px 4px 0 0;} .footContact{text-align: center;} .footContact a{font-size: 12px;color: #999;text-decoration: none;} diff --git a/static/images/computer.png b/static/images/computer.png new file mode 100644 index 0000000..8cd7fd6 Binary files /dev/null and b/static/images/computer.png differ diff --git a/static/images/phone.png b/static/images/phone.png new file mode 100644 index 0000000..3318a0b Binary files /dev/null and b/static/images/phone.png differ diff --git a/tools/http.go b/tools/http.go index e99101f..bbd8050 100644 --- a/tools/http.go +++ b/tools/http.go @@ -3,6 +3,7 @@ package tools import ( "io/ioutil" "net/http" + "regexp" "strings" ) @@ -50,3 +51,11 @@ func PostHeader(url string, msg []byte, headers map[string]string) (string, erro } return string(body), nil } +func IsMobile(userAgent string) bool { + mobileRe, _ := regexp.Compile("(?i:Mobile|iPod|iPhone|Android|Opera Mini|BlackBerry|webOS|UCWEB|Blazer|PSP)") + str := mobileRe.FindString(userAgent) + if str != "" { + return true + } + return false +} \ No newline at end of file