| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- package im
- import (
- "context"
- "sportfitness/base/global"
- im "sportfitness/base/repository/grpc/bsw/im/im"
- "google.golang.org/grpc/status"
- "git.beswell.com/gframe/application"
- "google.golang.org/grpc/metadata"
- )
- func handleErr(err error) {
- s, _ := status.FromError(err)
- panic(application.ErrorBusinessF(application.ErrorCode(s.Code()), s.Message()))
- }
- func getClient() im.ApiClient {
- conn, err := application.GetServiceGrpcConn("bsw/im")
- if err != nil {
- panic(err)
- }
- client := im.NewApiClient(conn)
- return client
- }
- func ctx() context.Context {
- md := metadata.Pairs("sys_token", global.SysToken)
- return metadata.NewOutgoingContext(context.Background(), md)
- }
- func SignUpUserCode(params *im.SignUpRequest) (userId int64) {
- r, err := getClient().SignUpUserCode(ctx(), params)
- handleErr(err)
- userId = r.GetId()
- return
- }
- func GenVerifyImage(height, width int32) (id, imageBase64 string) {
- r, err := getClient().GenVerifyImage(ctx(), &im.GenVerifyImageRequest{
- Height: int32(height),
- Width: int32(width),
- })
- handleErr(err)
- id = r.CodeId
- imageBase64 = r.ImageBase64
- return
- }
- func SignInUserCodePassword(userCode, password, ip, ClientInfo, codeId, verifyCode string) (token string, userId int) {
- r, err := getClient().SignInUserCode(ctx(), &im.SignInPasswordRequest{
- Credential: userCode,
- Password: password,
- ExpirationSec: global.TokenExpireSec,
- Ip: ip,
- ClientInfo: ClientInfo,
- CodeId: codeId,
- VerifyCode: verifyCode,
- })
- handleErr(err)
- token = r.Token
- userId = int(r.UserId)
- return
- }
- func RegisterServiceList(servicePathList []string) {
- request := &im.SaveServiceListRequest{}
- for _, p := range servicePathList {
- request.List = append(request.List, &im.Service{
- Path: p,
- Memo: "自动添加",
- })
- }
- _, err := getClient().SubServiceSaveList(ctx(), request)
- if err != nil {
- panic(err)
- }
- }
- func SignOut(token string) {
- request := &im.TokenParam{Token: token}
- _, err := getClient().SubSignOut(ctx(), request)
- handleErr(err)
- }
- func SubSessionCheck(token string) int64 {
- request := &im.TokenParam{Token: token}
- rs, err := getClient().SubSessionCheck(ctx(), request)
- handleErr(err)
- return rs.UserId
- }
- func SubPermissionListCheck(token string, shopId int64, servicePathList []string) *im.PermissionCheckReply {
- rs, err := getClient().SubPermissionListCheck(ctx(), &im.PermissionCheck{
- Token: token,
- ShopId: shopId,
- ServicePathList: servicePathList,
- })
- handleErr(err)
- return rs
- }
- func ShopListRequest(name string, status im.Status, sId int64) *im.ShopListReply {
- request := &im.ShopListRequest{SysId: 1, Name: name, Status: status, SId: sId}
- rs, err := getClient().ShopList(ctx(), request)
- handleErr(err)
- return rs
- }
- func GetShopNavi(userId, shopId int64, parentId int32) *im.UserGetColumnListReply {
- request := &im.UserGetColumnListRequest{UserId: userId, ShopId: shopId, ParentId: parentId}
- rs, err := getClient().UserGetColumnList(ctx(), request)
- handleErr(err)
- return rs
- }
|