Browse Source

新增获取小程序码方法

master v0.4.4
listen 3 years ago
parent
commit
1d365c1ee6
3 changed files with 78 additions and 1 deletions
  1. +0
    -1
      common.go
  2. +62
    -0
      miniapp_qrcode.client.go
  3. +16
    -0
      miniapp_qrcode.client_test.go

+ 0
- 1
common.go View File

@ -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
}


+ 62
- 0
miniapp_qrcode.client.go View File

@ -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
}

+ 16
- 0
miniapp_qrcode.client_test.go View File

@ -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)
}

Loading…
Cancel
Save