package聽util import聽( "github.com/qpliu/qrencode-go/qrencode" "image/png" "io" "net/http" ) const聽( ECLevelM聽=聽qrencode.ECLevel(0) ECLevelL聽=聽qrencode.ECLevel(1) ECLevelH聽=聽qrencode.ECLevel(2) ECLevelQ聽=聽qrencode.ECLevel(3) ) func聽NewHttpQr(w聽http.ResponseWriter,聽str聽string)聽error聽{ w.Header().Set("ContentType",聽"image/png") bit,聽_聽:=聽qrencode.Encode(str,聽ECLevelM) img聽:=聽bit.ImageWithMargin(10,聽1) return聽png.Encode(w,聽img) } func聽NewQr(w聽io.Writer,聽str聽string)聽error聽{ bit,聽_聽:=聽qrencode.Encode(str,聽ECLevelM) img聽:=聽bit.ImageWithMargin(10,聽1) return聽png.Encode(w,聽img) }
有疑问加站长微信联系(非本文作者)