package controller import ( "fmt" "github.com/gin-gonic/gin" "github.com/skip2/go-qrcode" "kefu/models" "kefu/tools" "kefu/types" ) func GetQrcode(c *gin.Context) { str := c.Query("str") var png []byte png, err := qrcode.Encode(str, qrcode.High, 512) if err != nil { c.JSON(200, gin.H{ "code": types.ApiCode.FAILED, "msg": types.ApiCode.GetMessage(types.ApiCode.INVALID), "result": err.Error(), }) return } c.Writer.Header().Set("Content-Type", "image/png") c.Writer.Write(png) } func PostDynicQrcode(c *gin.Context) { entId, _ := c.Get("ent_id") kefuName, _ := c.Get("kefu_name") domain := c.PostForm("domain") dynicQrType := c.PostForm("dynicQrType") resetFlag := c.PostForm("resetFlag") uniqId := tools.Uuid() result := fmt.Sprintf("%s/%s?ent_id=%s&kefu_id=%s", domain, dynicQrType, entId, kefuName) //清除旧的,插入新的关联表 args := []interface{}{ entId, kefuName, } if resetFlag == "reset" { models.DelQrcode("ent_id = ? and kefu_name = ?", args...) } models.CreateQrcode(entId.(string), uniqId, result, kefuName.(string)) c.JSON(200, gin.H{ "code": 200, "msg": "ok", "result": gin.H{ "info": result, "uuid": uniqId, }, }) } func GetCheckQrcode(c *gin.Context) { uuid := c.Query("uuid") qr := models.FindQrcode("uuid = ?", uuid) if qr.Url == "" { c.JSON(200, gin.H{ "code": 400, "msg": "二维码不存在或者已经失效", }) return } c.Redirect(302, qr.Url) }