From 7ecafe3fea2041e2d24fc4ad97405845488f00db Mon Sep 17 00:00:00 2001 From: listen <494177603@qq.com> Date: Wed, 7 Jul 2021 15:03:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=85=AC?= =?UTF-8?q?=E4=BC=97=E5=8F=B7=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mp_userinfo.client.go | 78 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 mp_userinfo.client.go diff --git a/mp_userinfo.client.go b/mp_userinfo.client.go new file mode 100644 index 0000000..e09a1cd --- /dev/null +++ b/mp_userinfo.client.go @@ -0,0 +1,78 @@ +package weixinrpc + +import ( +"encoding/json" +"log" +"strconv" +"time" +"git.tetele.net/tgo/crypter" +"github.com/golang/protobuf/proto" +) + +func GetMpUserInfo(accessToken,openId string,url ...string) (*MpUserInfoRes, error) { + + conn, err := rpc_server_conn(url...) + if err != nil { + return nil, err + } + defer conn.Close() + + data := MpUserInfoReq{} + data.AccessToken = accessToken + data.Openid = openId + data.Lang = "zh_CN" + + 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.GetMpUserInfo(req, res) + + if err != nil { + return nil, err + } + + return HandleMpUserInfo(res) + +} + +/** + * 处理返回结果 + */ +func HandleMpUserInfo(res *Response) (*MpUserInfoRes, error) { + + //解密 + res_data_de, err := GetOrgData(res) + + if err != nil { + return nil, err + } + + var res_arr MpUserInfoRes + + err = json.Unmarshal([]byte(res_data_de), &res_arr) + + if err != nil { + log.Println(err, res_data_de) + return nil, err + } + + return &res_arr, nil +}