用户接口远程调用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

151 lines
3.2 KiB

package user
import (
"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(),
}, 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
}