Browse Source

增加查询第三方账号接口

master v0.2.7
guzeng 3 years ago
parent
commit
d2d3128094
5 changed files with 111 additions and 3 deletions
  1. +11
    -2
      common.go
  2. +93
    -0
      third.client.go
  3. +2
    -1
      third.client_test.go
  4. +4
    -0
      user.pb.go
  5. +1
    -0
      user.proto

+ 11
- 2
common.go View File

@ -7,8 +7,7 @@ type Req struct {
Dbname string
}
type BindThirdReq struct {
Req
type Third struct {
Userid string
Platform string
Openid string
@ -18,6 +17,16 @@ type BindThirdReq struct {
Mobile string
}
type BindThirdReq struct {
Req
Third
}
type GetThirdReq struct {
Req
Userid string
Platform string
}
type Res struct {
Errcode int
Errmsg string


+ 93
- 0
third.client.go View File

@ -2,6 +2,7 @@ package userrpc
import (
"encoding/json"
"errors"
"strconv"
"time"
@ -62,3 +63,95 @@ func BindThird(site_id, dbname, platform, user_id, openid, openname, unionid, av
return HandleRes(res)
}
/**
* 查找第三方平台openid
* 2021/04/06
* gz
*/
func GetThird(site_id, dbname, platform, user_id string, url ...string) (*Third, error) {
conn, err := rpc_server_conn(url...)
if err != nil {
return nil, err
}
defer conn.Close()
data := GetThirdReq{}
data.SiteId = site_id
data.Dbname = dbname
data.Platform = platform
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.GetThird(req, res)
if err != nil {
return nil, err
}
return HandleGetThirdRes(res)
}
/**
* 处理返回结果
*/
func HandleGetThirdRes(res *Response) (*Third, error) {
res_data := res.GetData()
if res_data == "" {
return nil, errors.New("未收到收据")
}
time_int64, err := strconv.ParseInt(res.GetTime(), 10, 64)
if err != nil {
return nil, err
}
now_int64 := time.Now().Unix()
if now_int64-time_int64 > 10 || time_int64-now_int64 > 10 {
//时间误差前后10秒,返回
return nil, errors.New("返回时间错误")
}
check_sign := CheckSign(res.GetSign(), res_data, res.GetTime())
if !check_sign {
return nil, errors.New("返回数据签名错误")
}
//解密
res_data_de := crypter.DesDe(res_data, DES_KEY)
var res_arr Third
err = json.Unmarshal([]byte(res_data_de), &res_arr)
if err != nil {
return nil, err
}
return &res_arr, nil
}

+ 2
- 1
third.client_test.go View File

@ -12,7 +12,8 @@ func Test_BindThird(t *testing.T) {
openid := "CasfoieFsdfsdfiDiodf_df"
openname := "测试中"
avatar := "https://ssss.ttt.ddd/sfsd"
res, err := BindThird(site_id, dbname, platform, user_id, openid, openname, "", avatar)
mobile := "1234456456"
res, err := BindThird(site_id, dbname, platform, user_id, openid, openname, "", avatar, mobile)
t.Log(res)
t.Log(err)


+ 4
- 0
user.pb.go View File

@ -451,6 +451,7 @@ type UserService interface {
GetByUsername(in *UserInfoByUsername, out *UserResponse) error
GetByUsercode(in *UserInfoByUsercode, out *UserResponse) error
BindThird(in *Request, out *Response) error
GetThird(in *Request, out *Response) error
}
// AcceptUserServiceClient accepts connections on the listener and serves requests
@ -537,6 +538,9 @@ func (c *UserServiceClient) GetByUsercode(in *UserInfoByUsercode, out *UserRespo
func (c *UserServiceClient) BindThird(in *Request, out *Response) error {
return c.Call("UserService.BindThird", in, out)
}
func (c *UserServiceClient) GetThird(in *Request, out *Response) error {
return c.Call("UserService.GetThird", in, out)
}
// DialUserService connects to an UserService at the specified network address.
func DialUserService(network, addr string) (*UserServiceClient, *rpc.Client, error) {


+ 1
- 0
user.proto View File

@ -82,4 +82,5 @@ service UserService {
rpc getByUsername (UserInfoByUsername) returns (UserResponse); // 使username查询用户
rpc getByUsercode (UserInfoByUsercode) returns (UserResponse); // 使usercode查询用户
rpc bindThird (Request) returns (Response); //
rpc getThird(Request) returns (Response); //
}

Loading…
Cancel
Save