From 1d365c1ee65fca71f7da32d61871dec54d0087cc Mon Sep 17 00:00:00 2001 From: listen <494177603@qq.com> Date: Tue, 5 Oct 2021 15:55:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=A0=81=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common.go | 1 - miniapp_qrcode.client.go | 62 +++++++++++++++++++++++++++++++++++ miniapp_qrcode.client_test.go | 16 +++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 miniapp_qrcode.client.go create mode 100644 miniapp_qrcode.client_test.go diff --git a/common.go b/common.go index 510d252..91cdf15 100644 --- a/common.go +++ b/common.go @@ -111,7 +111,6 @@ func rpc_server_conn(url ...string) (*WeixinRpcServiceClient, error) { var wx_rpc_url string if len(url) > 0 && url[0] != "" { wx_rpc_url = url[0] - wx_rpc_url = conf.WEIXIN_RPC_PORT } else { wx_rpc_url = "127.0.0.1:" + conf.WEIXIN_RPC_PORT } diff --git a/miniapp_qrcode.client.go b/miniapp_qrcode.client.go new file mode 100644 index 0000000..5572cae --- /dev/null +++ b/miniapp_qrcode.client.go @@ -0,0 +1,62 @@ +package weixinrpc + +import ( + "encoding/json" + "strconv" + "time" + + "git.tetele.net/tgo/crypter" + + "github.com/golang/protobuf/proto" +) + +func GetMiniAppQrcode(appId, appSecret, page,scene string, url ...string) (string, error) { + + conn, err := rpc_server_conn(url...) + if err != nil { + return "", err + } + defer conn.Close() + + data := map[string]string{} + data["app_id"] = appId + data["app_secret"] = appSecret + data["page"] = page + data["scene"] = scene + + data_json, err := json.Marshal(data) + if err != nil { + return "", 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.GetMiniappQrcode(req, res) + + if err != nil { + return "", err + } + + //解密 + res_data_de, err := GetOrgData(res) + + if err != nil { + return "", err + } + + return res_data_de, nil +} diff --git a/miniapp_qrcode.client_test.go b/miniapp_qrcode.client_test.go new file mode 100644 index 0000000..0a69fa6 --- /dev/null +++ b/miniapp_qrcode.client_test.go @@ -0,0 +1,16 @@ +package weixinrpc + +import ( + "testing" +) + +func Test_GetMiniappCode(t *testing.T){ + appid := "wx3d53ccbaf69f7995" + appSecret := "165983626235636be54a16404e3e70a7" + page := "" + scene := "user_id=2" + qrcode,err := GetMiniAppQrcode(appid,appSecret,page,scene) + + t.Log(qrcode) + t.Log(err) +} \ No newline at end of file