|
|
@ -0,0 +1,72 @@ |
|
|
|
package weixinrpc |
|
|
|
|
|
|
|
import ( |
|
|
|
"encoding/json" |
|
|
|
"log" |
|
|
|
"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.GetMiniappCode(req, res) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return "", err |
|
|
|
} |
|
|
|
|
|
|
|
//解密
|
|
|
|
res_data_de, err := GetOrgData(res) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return "", err |
|
|
|
} |
|
|
|
|
|
|
|
var result string |
|
|
|
|
|
|
|
err = json.Unmarshal([]byte(res_data_de), &result) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
log.Println(err, res_data_de) |
|
|
|
return "", err |
|
|
|
} |
|
|
|
|
|
|
|
return result, nil |
|
|
|
} |