|
|
- 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) {
-
- var user_rpc_url string = "127.0.0.1:7976"
- if len(url) > 0 && url[0] != "" {
- user_rpc_url = url[0]
- }
- conn, _, err := DialUserService("tcp", user_rpc_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(),
- }, nil
- }
-
- return map[string]string{}, nil
- }
-
- /**
- * 使用用户名查询
- */
- func GetUserByUsername(dbname, username string, url ...string) (*UserResponse, error) {
-
- var user_rpc_url string = "127.0.0.1:7976"
- if len(url) > 0 && url[0] != "" {
- user_rpc_url = url[0]
- }
-
- conn, _, err := DialUserService("tcp", user_rpc_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) {
-
- var user_rpc_url string = "127.0.0.1:7976"
- if len(url) > 0 && url[0] != "" {
- user_rpc_url = url[0]
- }
-
- conn, _, err := DialUserService("tcp", user_rpc_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) {
-
- var user_rpc_url string = "127.0.0.1:7976"
- if len(url) > 0 && url[0] != "" {
- user_rpc_url = url[0]
- }
-
- conn, _, err := DialUserService("tcp", user_rpc_url)
- 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)
- }
|