api.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package im
  2. import (
  3. "context"
  4. "sportfitness/base/global"
  5. im "sportfitness/base/repository/grpc/bsw/im/im"
  6. "git.beswell.com/gframe/application"
  7. "google.golang.org/grpc/metadata"
  8. )
  9. func getClient() im.ApiClient {
  10. conn, err := application.GetServiceGrpcConn("bsw/im")
  11. if err != nil {
  12. panic(err)
  13. }
  14. client := im.NewApiClient(conn)
  15. return client
  16. }
  17. func ctx() context.Context {
  18. md := metadata.Pairs("sys_token", global.SysToken)
  19. return metadata.NewOutgoingContext(context.Background(), md)
  20. }
  21. func SignUpUserCode(params *im.SignUpRequest) (userId int64) {
  22. r, err := getClient().SignUpUserCode(ctx(), params)
  23. if err != nil {
  24. panic(err)
  25. }
  26. userId = r.GetId()
  27. return
  28. }
  29. func GenVerifyImage(height, width int32) (id, imageBase64 string) {
  30. r, err := getClient().GenVerifyImage(ctx(), &im.GenVerifyImageRequest{
  31. Height: int32(height),
  32. Width: int32(width),
  33. })
  34. if err != nil {
  35. panic(err)
  36. }
  37. id = r.CodeId
  38. imageBase64 = r.ImageBase64
  39. return
  40. }
  41. func SignInUserCodePassword(userCode, password, ip, ClientInfo, codeId, verifyCode string) (token string, userId int) {
  42. r, err := getClient().SignInUserCode(ctx(), &im.SignInPasswordRequest{
  43. Credential: userCode,
  44. Password: password,
  45. ExpirationSec: global.TokenExpireSec,
  46. Ip: ip,
  47. ClientInfo: ClientInfo,
  48. CodeId: codeId,
  49. VerifyCode: verifyCode,
  50. })
  51. if err != nil {
  52. panic(err)
  53. }
  54. token = r.Token
  55. userId = int(r.UserId)
  56. return
  57. }
  58. func RegisterServiceList(servicePathList []string) {
  59. request := &im.SaveServiceListRequest{}
  60. for _, p := range servicePathList {
  61. request.List = append(request.List, &im.Service{
  62. Path: p,
  63. Memo: "自动添加",
  64. })
  65. }
  66. _, err := getClient().SubServiceSaveList(ctx(), request)
  67. if err != nil {
  68. panic(err)
  69. }
  70. }
  71. func SignOut(token string) {
  72. request := &im.TokenParam{Token: token}
  73. _, err := getClient().SubSignOut(ctx(), request)
  74. if err != nil {
  75. panic(err)
  76. }
  77. }
  78. func SubSessionCheck(token string) int64 {
  79. request := &im.TokenParam{Token: token}
  80. rs, err := getClient().SubSessionCheck(ctx(), request)
  81. if err != nil {
  82. panic(err)
  83. }
  84. return rs.UserId
  85. }
  86. func SubPermissionListCheck(token string, shopId int64, servicePathList []string) *im.PermissionCheckReply {
  87. rs, err := getClient().SubPermissionListCheck(ctx(), &im.PermissionCheck{
  88. Token: token,
  89. ShopId: shopId,
  90. ServicePathList: servicePathList,
  91. })
  92. if err != nil {
  93. panic(err)
  94. }
  95. return rs
  96. }
  97. func ShopListRequest(name string, status im.Status, sId int64) *im.ShopListReply {
  98. request := &im.ShopListRequest{SysId: 1, Name: name, Status: status, SId: sId}
  99. rs, err := getClient().ShopList(ctx(), request)
  100. if err != nil {
  101. panic(err)
  102. }
  103. return rs
  104. }
  105. func GetShopNavi(userId, shopId int64, parentId int32) *im.UserGetColumnListReply {
  106. request := &im.UserGetColumnListRequest{UserId: userId, ShopId: shopId, ParentId: parentId}
  107. rs, err := getClient().UserGetColumnList(ctx(), request)
  108. if err != nil {
  109. panic(err)
  110. }
  111. return rs
  112. }