package userrpc import ( "encoding/json" "strconv" "time" "git.tetele.net/tgo/crypter" "github.com/golang/protobuf/proto" ) func GetUserByToken(dbname, token string, url ...string) (map[string]string, error) { conn, err := rpc_server_conn(url...) if err != nil { return map[string]string{}, err } defer conn.Close() req := &UserRequest{proto.String(dbname), proto.String(token), nil} res := &UserResponse{} err = conn.GetByToken(req, res) if err != nil { return map[string]string{}, err } if res.GetUserId() != "" { return map[string]string{ "UserId": res.GetUserId(), "Username": res.GetUsername(), "Nickname": res.GetNickname(), "Mobile": res.GetMobile(), "Email": res.GetEmail(), "Status": res.GetStatus(), "BusinessId": res.GetBusinessId(), "StoreId": res.GetStoreId(), "FansTo": res.GetFansTo(), "IsVip": res.GetIsVip(), "Usercode": res.GetUsercode(), "GroupId": res.GetGroupId(), "Type": res.GetType(), "ThirdId": res.GetThirdId(), "Platform": res.GetPlatform(), "LockFans": res.GetLockFans(), }, nil } return map[string]string{}, nil } /** * 使用用户名查询 */ func GetUserByUsername(dbname, username string, url ...string) (*UserResponse, error) { conn, err := rpc_server_conn(url...) if err != nil { return nil, err } defer conn.Close() req := &UserInfoByUsername{proto.String(dbname), proto.String(username), nil} res := &UserResponse{} err = conn.GetByUsername(req, res) if err != nil { return nil, err } return res, nil } /** * 使用编号查询 */ func GetUserByUsercode(dbname, usercode string, url ...string) (*UserResponse, error) { conn, err := rpc_server_conn(url...) if err != nil { return nil, err } defer conn.Close() req := &UserInfoByUsercode{proto.String(dbname), proto.String(usercode), nil} res := &UserResponse{} err = conn.GetByUsercode(req, res) if err != nil { return nil, err } return res, nil } func Login(dbname, account, password string, url ...string) (map[string]string, error) { conn, err := rpc_server_conn(url...) if err != nil { return map[string]string{}, err } if err != nil { return map[string]string{}, err } defer conn.Close() req := &LoginRequest{proto.String(dbname), proto.String(account), proto.String(password), nil} res := &LoginResponse{} err = conn.Login(req, res) if err != nil { return map[string]string{}, err } if res.GetUserId() != "" { return map[string]string{ "UserId": res.GetUserId(), "Username": res.GetUsername(), "Nickname": res.GetNickname(), "Mobile": res.GetMobile(), "Email": res.GetEmail(), "Status": res.GetStatus(), "BusinessId": res.GetBusinessId(), "StoreId": res.GetStoreId(), "FansTo": res.GetFansTo(), "IsVip": res.GetIsVip(), "Token": res.GetToken(), "Usercode": res.GetUsercode(), "GroupId": res.GetGroupId(), "Type": res.GetType(), }, nil } return map[string]string{}, nil } /** * 查找商户信息 * 2021/04/06 * gz */ func GetById(site_id, dbname, user_id string, url ...string) (map[string]string, error) { conn, err := rpc_server_conn(url...) if err != nil { return nil, err } defer conn.Close() data := GetUserReq{} data.SiteId = site_id data.Dbname = dbname data.UserId = user_id data_json, err := json.Marshal(data) if err != nil { return nil, err } encryData := crypter.DesEn(string(data_json), DES_KEY) now_int64 := time.Now().Unix() now := strconv.FormatInt(now_int64, 10) sign := Sign(encryData, now) req := &Request{ proto.String(encryData), proto.String(now), proto.String(sign), nil} res := &Response{} err = conn.GetById(req, res) if err != nil { return nil, err } return HandleUserRes(res) } /** * 更新用户缓存 * 2021/11/23 * linsen */ func UpdateUserCache(site_id, dbname, user_id string, url ...string) (map[string]string, error) { conn, err := rpc_server_conn(url...) if err != nil { return nil, err } defer conn.Close() data := GetUserReq{} data.SiteId = site_id data.Dbname = dbname data.UserId = user_id data_json, err := json.Marshal(data) if err != nil { return nil, err } encryData := crypter.DesEn(string(data_json), DES_KEY) now_int64 := time.Now().Unix() now := strconv.FormatInt(now_int64, 10) sign := Sign(encryData, now) req := &Request{ proto.String(encryData), proto.String(now), proto.String(sign), nil} res := &Response{} err = conn.UpdateUserCache(req, res) if err != nil { return nil, err } return HandleUserRes(res) }