package routers import ( "fmt" "github.com/gin-gonic/gin" "github.com/liyue201/goqr" "github.com/nfnt/resize" "image" "io/ioutil" "kpt.xdmy/apiserver/model" "kpt.xdmy/apiserver/model/http" ) func McsControl(c *gin.Context) { mpd := new(model.McsPostDataReq) if !Bind(c, mpd) { return } resp, err := svc.McsPostHttp(mpd) eJSON(c, resp, err) } func McsAccounts(c *gin.Context) { sa := []model.McsAccount{ { DeviceId: "apptest2", UserID: "PC", Password: "mcs8", }, } resp := &http.Response{ Code: 200, Data: sa, } eJSON(c, resp, nil) } //QuickResponse func QuickResponse(c *gin.Context) { file, err := c.FormFile("file") if err != nil { c.JSON(500, map[string]interface{}{"code": 500, "data": err, "msg": "文件读取错误!"}) return } f, err := file.Open() if err != nil { c.JSON(500, map[string]interface{}{"code": 500, "data": err, "msg": "文件打开错误!"}) return } fmt.Println(file.Filename, file.Size) img, _, _ := image.Decode(f) resizeImg := resize.Resize(260, 260, img, resize.Lanczos2) fmt.Println(file.Filename, file.Size) qrCodes, err := goqr.Recognize(resizeImg) if err != nil { fmt.Printf("Recognize failed: %v\n", err) return } if len(qrCodes) <= 0 { fmt.Printf("识别失败") return } fmt.Println(string(qrCodes[0].Payload)) c.JSON(200, map[string]interface{}{"code": 200, "data": string(qrCodes[0].Payload), "msg": "ok"}) } func Test(c *gin.Context) { dataByte, _ := ioutil.ReadAll(c.Request.Body) fmt.Println(string(dataByte)) //userlist := make([]map[string]string, 0) data := []map[string]interface{}{ {"username": "admin", "id": 100, "create_time": "2023-12-01", "txt": "测试信息1123"}, {"username": "epans", "id": 200, "create_time": "2023-12-01", "txt": "测试信息1123"}, {"username": "derek", "id": 300, "create_time": "2023-12-01", "txt": "测试信息1123"}, } c.JSON(200, map[string]interface{}{"code": 200, "userlist": data, "msg": "ok"}) } type DingdingT struct { MsgSignature string `json:"msg_signature"` TimeStamp string `json:"timeStamp"` Nonce string `json:"nonce"` Encrypt string `json:"encrypt"` } //func Dingding(c *gin.Context) { // dataByte, _ := ioutil.ReadAll(c.Request.Body) // fmt.Println(string(dataByte)) // fsion := gofasion.NewFasion(string(dataByte)) // // resp := new(DingdingT) // resp.Encrypt = fsion.Get("encrypt").ValueStr() // resp.Nonce = c.Query("nonce") // resp.TimeStamp = c.Query("timestamp") // resp.MsgSignature = c.Query("signature") // // //dingding. // //c.JSON(200, []byte("success")) // //body, err := c.GetRawData() // //if err != nil { // // panic(err) // //} // // // //// 调用 CallbackParse 函数解析回调事件 // //event, err := dingding.CallbackParse(body, "token", "aes_key") // //if err != nil { // // panic(err) // //} // // // //// 根据事件类型执行相应的业务逻辑 // //switch event.Type { // //case "user_add_org": // // // 处理用户加入企业事件 // // // ... // //case "bpms_task_change": // // // 处理审批任务变更事件 // // // ... // //default: // // // 其他类型事件,忽略 // //} // //:= dingding.NewCrypto() // // 返回成功响应 // //dingding.Crypto{ // // Token: setting.ServerSetting.DingTalkToken, // // EncodingAESKey:setting.ServerSetting.DingTalkEncodingAESKey, // // SuiteKey:"" // //} // d, _ := json.Marshal(resp) // c.String(200, string(d)) // //c.JSON(200, resp) //}