From 716c994c1fae94972e64206d981f7ca3f63fa00c Mon Sep 17 00:00:00 2001 From: listen <494177603@qq.com> Date: Wed, 6 Oct 2021 16:24:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0app=E8=8E=B7=E5=8F=96openid?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_openid.client.go | 71 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 app_openid.client.go diff --git a/app_openid.client.go b/app_openid.client.go new file mode 100644 index 0000000..d277c63 --- /dev/null +++ b/app_openid.client.go @@ -0,0 +1,71 @@ +package weixinrpc + +import ( + "encoding/json" + "log" + "strconv" + "time" + + "git.tetele.net/tgo/crypter" + + "github.com/golang/protobuf/proto" +) + +func GetAppOpenid(appid, secret, js_code string, url ...string) (map[string]string, error) { + + conn, err := rpc_server_conn(url...) + if err != nil { + return nil, err + } + defer conn.Close() + + data := MiniAppOpenidReq{} + data.Appid = appid + data.Secret = secret + data.JsCode = js_code + + 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.GetAppOpenid(req, res) + + if err != nil { + return nil, err + } + + //解密 + res_data_de, err := GetOrgData(res) + + if err != nil { + return nil, err + } + + var res_arr map[string]string + + 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 +}