用户接口远程调用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
3.8 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package userrpc
  2. import (
  3. "encoding/json"
  4. "strconv"
  5. "time"
  6. "git.tetele.net/tgo/crypter"
  7. "github.com/golang/protobuf/proto"
  8. )
  9. func GetUserByToken(dbname, token string, url ...string) (map[string]string, error) {
  10. conn, err := rpc_server_conn(url...)
  11. if err != nil {
  12. return map[string]string{}, err
  13. }
  14. defer conn.Close()
  15. req := &UserRequest{proto.String(dbname), proto.String(token), nil}
  16. res := &UserResponse{}
  17. err = conn.GetByToken(req, res)
  18. if err != nil {
  19. return map[string]string{}, err
  20. }
  21. if res.GetUserId() != "" {
  22. return map[string]string{
  23. "UserId": res.GetUserId(),
  24. "Username": res.GetUsername(),
  25. "Nickname": res.GetNickname(),
  26. "Mobile": res.GetMobile(),
  27. "Email": res.GetEmail(),
  28. "Status": res.GetStatus(),
  29. "BusinessId": res.GetBusinessId(),
  30. "StoreId": res.GetStoreId(),
  31. "FansTo": res.GetFansTo(),
  32. "IsVip": res.GetIsVip(),
  33. "Usercode": res.GetUsercode(),
  34. "GroupId": res.GetGroupId(),
  35. "Type": res.GetType(),
  36. "ThirdId": res.GetThirdId(),
  37. "Platform": res.GetPlatform(),
  38. "LockFans": res.GetLockFans(),
  39. }, nil
  40. }
  41. return map[string]string{}, nil
  42. }
  43. /**
  44. * 使用用户名查询
  45. */
  46. func GetUserByUsername(dbname, username string, url ...string) (*UserResponse, error) {
  47. conn, err := rpc_server_conn(url...)
  48. if err != nil {
  49. return nil, err
  50. }
  51. defer conn.Close()
  52. req := &UserInfoByUsername{proto.String(dbname), proto.String(username), nil}
  53. res := &UserResponse{}
  54. err = conn.GetByUsername(req, res)
  55. if err != nil {
  56. return nil, err
  57. }
  58. return res, nil
  59. }
  60. /**
  61. * 使用编号查询
  62. */
  63. func GetUserByUsercode(dbname, usercode string, url ...string) (*UserResponse, error) {
  64. conn, err := rpc_server_conn(url...)
  65. if err != nil {
  66. return nil, err
  67. }
  68. defer conn.Close()
  69. req := &UserInfoByUsercode{proto.String(dbname), proto.String(usercode), nil}
  70. res := &UserResponse{}
  71. err = conn.GetByUsercode(req, res)
  72. if err != nil {
  73. return nil, err
  74. }
  75. return res, nil
  76. }
  77. func Login(dbname, account, password string, url ...string) (map[string]string, error) {
  78. conn, err := rpc_server_conn(url...)
  79. if err != nil {
  80. return map[string]string{}, err
  81. }
  82. if err != nil {
  83. return map[string]string{}, err
  84. }
  85. defer conn.Close()
  86. req := &LoginRequest{proto.String(dbname), proto.String(account), proto.String(password), nil}
  87. res := &LoginResponse{}
  88. err = conn.Login(req, res)
  89. if err != nil {
  90. return map[string]string{}, err
  91. }
  92. if res.GetUserId() != "" {
  93. return map[string]string{
  94. "UserId": res.GetUserId(),
  95. "Username": res.GetUsername(),
  96. "Nickname": res.GetNickname(),
  97. "Mobile": res.GetMobile(),
  98. "Email": res.GetEmail(),
  99. "Status": res.GetStatus(),
  100. "BusinessId": res.GetBusinessId(),
  101. "StoreId": res.GetStoreId(),
  102. "FansTo": res.GetFansTo(),
  103. "IsVip": res.GetIsVip(),
  104. "Token": res.GetToken(),
  105. "Usercode": res.GetUsercode(),
  106. "GroupId": res.GetGroupId(),
  107. "Type": res.GetType(),
  108. }, nil
  109. }
  110. return map[string]string{}, nil
  111. }
  112. /**
  113. * 查找商户信息
  114. * 2021/04/06
  115. * gz
  116. */
  117. func GetById(site_id, dbname, user_id string, url ...string) (map[string]string, error) {
  118. conn, err := rpc_server_conn(url...)
  119. if err != nil {
  120. return nil, err
  121. }
  122. defer conn.Close()
  123. data := GetUserReq{}
  124. data.SiteId = site_id
  125. data.Dbname = dbname
  126. data.UserId = user_id
  127. data_json, err := json.Marshal(data)
  128. if err != nil {
  129. return nil, err
  130. }
  131. encryData := crypter.DesEn(string(data_json), DES_KEY)
  132. now_int64 := time.Now().Unix()
  133. now := strconv.FormatInt(now_int64, 10)
  134. sign := Sign(encryData, now)
  135. req := &Request{
  136. proto.String(encryData),
  137. proto.String(now),
  138. proto.String(sign),
  139. nil}
  140. res := &Response{}
  141. err = conn.GetById(req, res)
  142. if err != nil {
  143. return nil, err
  144. }
  145. return HandleUserRes(res)
  146. }