package wechat
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"errors"
|
|
"fmt"
|
|
"log"
|
|
|
|
"git.tetele.net/tgo/helper"
|
|
"git.tetele.net/tgo/network"
|
|
)
|
|
|
|
// 获取小程序码
|
|
func GetMiniappQrcode(access_token string, qrcodeParamsMap map[string]interface{}) (string, error) {
|
|
|
|
getCodeUrl := fmt.Sprintf(GET_MINIAPP_QRCODE, access_token)
|
|
|
|
checkPath := true
|
|
envVersion := "release"
|
|
width := 430
|
|
autoColor := false
|
|
isHyaline := false
|
|
|
|
if _, exist := qrcodeParamsMap["check_path"]; exist {
|
|
checkPath = qrcodeParamsMap["check_path"].(bool)
|
|
}
|
|
|
|
if _, exist := qrcodeParamsMap["env_version"]; exist {
|
|
envVersion = helper.ToStr(qrcodeParamsMap["env_version"])
|
|
}
|
|
|
|
if _, exist := qrcodeParamsMap["width"]; exist {
|
|
width = helper.ToInt(qrcodeParamsMap["width"])
|
|
}
|
|
|
|
if _, exist := qrcodeParamsMap["auto_color"]; exist {
|
|
autoColor = qrcodeParamsMap["auto_color"].(bool)
|
|
}
|
|
|
|
if _, exist := qrcodeParamsMap["is_hyaline"]; exist {
|
|
isHyaline = qrcodeParamsMap["is_hyaline"].(bool)
|
|
}
|
|
|
|
requestData := map[string]interface{}{
|
|
"scene": qrcodeParamsMap["scene"],
|
|
"page": qrcodeParamsMap["page"],
|
|
"check_path": checkPath,
|
|
"env_version": envVersion,
|
|
"width": width,
|
|
"auto_color": autoColor,
|
|
"is_hyaline": isHyaline,
|
|
}
|
|
requestDataJson, err := json.Marshal(requestData)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
response, err := PostJson(getCodeUrl, requestDataJson)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
responseData := map[string]interface{}{}
|
|
err = json.Unmarshal(response, &responseData)
|
|
if err != nil {
|
|
// 有错,但能解析
|
|
log.Println(err)
|
|
}
|
|
|
|
if _, exist := responseData["errcode"]; exist && helper.ToInt(responseData["errcode"]) != 0 {
|
|
return "", errors.New(helper.ToStr(responseData["errmsg"]))
|
|
}
|
|
|
|
return "data:image/png;base64," + base64.StdEncoding.EncodeToString(response), nil
|
|
}
|