common.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package sso
  2. import (
  3. "fmt"
  4. "log"
  5. "syno-common/server/request"
  6. "time"
  7. )
  8. const apiKey = "XVlBzgbaiCMRAjWw"
  9. const apiSecret = "hTHctcuAxhxKQFDa"
  10. type BaseResp struct {
  11. Code int `json:"code"`
  12. Msg string `json:"msg"`
  13. Ok bool `json:"ok"`
  14. Data map[string]interface{} `json:"data"`
  15. }
  16. func (r *BaseResp) ToString() string {
  17. return fmt.Sprintf("{Code: %v,Msg: %v,Ok: %v,Data: %v}", r.Code, r.Msg, r.Ok, r.Data)
  18. }
  19. // LoginByAccount
  20. // 直接向授权中心获取token,无赖之举,syno没有能检查token的接口,起码现在不知道
  21. func LoginByAccount(account string) BaseResp {
  22. req := request.NewRequest("http://10.10.0.1:20003", time.Second*10)
  23. data := map[string]interface{}{
  24. "user_name": account,
  25. "app_id": "",
  26. }
  27. resp := BaseResp{
  28. Ok: false,
  29. Msg: "request fail",
  30. }
  31. option := request.Option{
  32. Url: "/client/login",
  33. Resp: &resp,
  34. Accept: "",
  35. ApiKey: apiKey,
  36. ApiSecret: apiSecret,
  37. }
  38. _, err := req.DoPostJson(data, option)
  39. if err != nil {
  40. log.Fatalln(err)
  41. }
  42. log.Printf("resp: %v", resp)
  43. return resp
  44. }