api.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package im
  2. import (
  3. "context"
  4. "git.beswell.com/gframe/application"
  5. "google.golang.org/grpc/metadata"
  6. "sportfitness/base/global"
  7. pb "sportfitness/base/repository/grpc/bsw/im/im"
  8. )
  9. func getClient() pb.ApiClient {
  10. conn, err := application.GetServiceGrpcConn("bsw/im")
  11. if err != nil {
  12. panic(err)
  13. }
  14. client := pb.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 *pb.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 SignInUserCodePassword(userCode, password, ip, ClientInfo string) (token string, userId int) {
  30. r, err := getClient().SignInUserCode(ctx(), &pb.SignInPasswordRequest{
  31. Credential: userCode,
  32. Password: password,
  33. ExpirationSec: global.TokenExpireSec,
  34. Ip: ip,
  35. ClientInfo: ClientInfo,
  36. })
  37. if err != nil {
  38. panic(err)
  39. }
  40. token = r.Token
  41. userId = int(r.UserId)
  42. return
  43. }