书写前端接口

This commit is contained in:
hoteas
2021-12-12 04:22:30 +08:00
parent 7b85da4c7f
commit 9482404265
5 changed files with 77 additions and 17 deletions
+47
View File
@@ -103,6 +103,53 @@ func main() {
context.Display(0, data)
return false
}
//文件上传接口
if len(context.RouterString) == 1 && context.RouterString[0] == "qrcode" && context.Req.Method == "POST" {
//读取网络文件
ocr := context.Req.FormValue("ocr")
if len(ocr) < 100 {
context.Display(3, "没有上传文件")
return false
}
go func() {
filePath := context.Config.GetString("filePath")
if filePath == "" {
filePath = "file/2006/01/02/"
}
path := time.Now().Format(filePath)
e := os.MkdirAll(context.Config.GetString("tpt")+"/"+path, os.ModeDir)
if e != nil {
return
}
fi, _ := base64.StdEncoding.DecodeString(ocr)
filePath = path + common.Md5(common.ObjToStr(common.RandX(100000, 9999999))) + ".jpg"
ioutil.WriteFile(context.Config.GetString("tpt")+"/"+filePath, fi, 0666)
}()
re1 := tencent.Qrcode(ocr)
data := common.Map{}
data["qrcode"] = common.ObjToMap(re1)
if data["qrcode"] != nil {
lis := data.GetMap("qrcode").GetMap("Response").GetSlice("CodeResults")
textList := common.Slice{}
for k, _ := range lis {
li := lis.GetMap(k).GetString("Url")
if li != "" {
textList = append(textList, li)
}
}
data["qrcode"] = textList
}
fmt.Println(data.ToJsonString())
context.Display(0, data)
return false
}
//文件上传接口
if len(context.RouterString) == 1 && context.RouterString[0] == "file" && context.Req.Method == "POST" {