mcs.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package routers
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "github.com/liyue201/goqr"
  6. "github.com/nfnt/resize"
  7. "image"
  8. "io/ioutil"
  9. "kpt.xdmy/apiserver/model"
  10. "kpt.xdmy/apiserver/model/http"
  11. )
  12. func McsControl(c *gin.Context) {
  13. mpd := new(model.McsPostDataReq)
  14. if !Bind(c, mpd) {
  15. return
  16. }
  17. resp, err := svc.McsPostHttp(mpd)
  18. eJSON(c, resp, err)
  19. }
  20. func McsAccounts(c *gin.Context) {
  21. sa := []model.McsAccount{
  22. {
  23. DeviceId: "apptest2",
  24. UserID: "PC",
  25. Password: "mcs8",
  26. },
  27. }
  28. resp := &http.Response{
  29. Code: 200,
  30. Data: sa,
  31. }
  32. eJSON(c, resp, nil)
  33. }
  34. //QuickResponse
  35. func QuickResponse(c *gin.Context) {
  36. file, err := c.FormFile("file")
  37. if err != nil {
  38. c.JSON(500, map[string]interface{}{"code": 500, "data": err, "msg": "文件读取错误!"})
  39. return
  40. }
  41. f, err := file.Open()
  42. if err != nil {
  43. c.JSON(500, map[string]interface{}{"code": 500, "data": err, "msg": "文件打开错误!"})
  44. return
  45. }
  46. fmt.Println(file.Filename, file.Size)
  47. img, _, _ := image.Decode(f)
  48. resizeImg := resize.Resize(260, 260, img, resize.Lanczos2)
  49. fmt.Println(file.Filename, file.Size)
  50. qrCodes, err := goqr.Recognize(resizeImg)
  51. if err != nil {
  52. fmt.Printf("Recognize failed: %v\n", err)
  53. return
  54. }
  55. if len(qrCodes) <= 0 {
  56. fmt.Printf("识别失败")
  57. return
  58. }
  59. fmt.Println(string(qrCodes[0].Payload))
  60. c.JSON(200, map[string]interface{}{"code": 200, "data": string(qrCodes[0].Payload), "msg": "ok"})
  61. }
  62. func Test(c *gin.Context) {
  63. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  64. fmt.Println(string(dataByte))
  65. //userlist := make([]map[string]string, 0)
  66. data := []map[string]interface{}{
  67. {"username": "admin", "id": 100, "create_time": "2023-12-01", "txt": "测试信息1123"},
  68. {"username": "epans", "id": 200, "create_time": "2023-12-01", "txt": "测试信息1123"},
  69. {"username": "derek", "id": 300, "create_time": "2023-12-01", "txt": "测试信息1123"},
  70. }
  71. c.JSON(200, map[string]interface{}{"code": 200, "userlist": data, "msg": "ok"})
  72. }
  73. type DingdingT struct {
  74. MsgSignature string `json:"msg_signature"`
  75. TimeStamp string `json:"timeStamp"`
  76. Nonce string `json:"nonce"`
  77. Encrypt string `json:"encrypt"`
  78. }
  79. //func Dingding(c *gin.Context) {
  80. // dataByte, _ := ioutil.ReadAll(c.Request.Body)
  81. // fmt.Println(string(dataByte))
  82. // fsion := gofasion.NewFasion(string(dataByte))
  83. //
  84. // resp := new(DingdingT)
  85. // resp.Encrypt = fsion.Get("encrypt").ValueStr()
  86. // resp.Nonce = c.Query("nonce")
  87. // resp.TimeStamp = c.Query("timestamp")
  88. // resp.MsgSignature = c.Query("signature")
  89. //
  90. // //dingding.
  91. // //c.JSON(200, []byte("success"))
  92. // //body, err := c.GetRawData()
  93. // //if err != nil {
  94. // // panic(err)
  95. // //}
  96. // //
  97. // //// 调用 CallbackParse 函数解析回调事件
  98. // //event, err := dingding.CallbackParse(body, "token", "aes_key")
  99. // //if err != nil {
  100. // // panic(err)
  101. // //}
  102. // //
  103. // //// 根据事件类型执行相应的业务逻辑
  104. // //switch event.Type {
  105. // //case "user_add_org":
  106. // // // 处理用户加入企业事件
  107. // // // ...
  108. // //case "bpms_task_change":
  109. // // // 处理审批任务变更事件
  110. // // // ...
  111. // //default:
  112. // // // 其他类型事件,忽略
  113. // //}
  114. // //:= dingding.NewCrypto()
  115. // // 返回成功响应
  116. // //dingding.Crypto{
  117. // // Token: setting.ServerSetting.DingTalkToken,
  118. // // EncodingAESKey:setting.ServerSetting.DingTalkEncodingAESKey,
  119. // // SuiteKey:""
  120. // //}
  121. // d, _ := json.Marshal(resp)
  122. // c.String(200, string(d))
  123. // //c.JSON(200, resp)
  124. //}