Compare commits
No commits in common. "a8bb15f30919d930e3fc1fa08dcb22532cf53655" and "e126b970318404bf2dee3658700514ada77cb99c" have entirely different histories.
a8bb15f309
...
e126b97031
|
|
@ -20,7 +20,6 @@ const (
|
||||||
userPhoneNumberUrl string = "https://api.weixin.qq.com/wxa/business/getuserphonenumber"
|
userPhoneNumberUrl string = "https://api.weixin.qq.com/wxa/business/getuserphonenumber"
|
||||||
getWxACodeUnLimitUrl string = "https://api.weixin.qq.com/wxa/getwxacodeunlimit"
|
getWxACodeUnLimitUrl string = "https://api.weixin.qq.com/wxa/getwxacodeunlimit"
|
||||||
getWxScheme string = "https://api.weixin.qq.com/wxa/generatescheme"
|
getWxScheme string = "https://api.weixin.qq.com/wxa/generatescheme"
|
||||||
getWxUrlLink string = "https://api.weixin.qq.com/wxa/generate_urllink"
|
|
||||||
code2UserinfoUrl string = "https://api.weixin.qq.com/sns/userinfo"
|
code2UserinfoUrl string = "https://api.weixin.qq.com/sns/userinfo"
|
||||||
oaQrCodeCreateUrl string = "https://api.weixin.qq.com/cgi-bin/qrcode/create"
|
oaQrCodeCreateUrl string = "https://api.weixin.qq.com/cgi-bin/qrcode/create"
|
||||||
userInfoByOpenid string = "https://api.weixin.qq.com/cgi-bin/user/info"
|
userInfoByOpenid string = "https://api.weixin.qq.com/cgi-bin/user/info"
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,13 @@ package weixin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"cmp"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MpSdk struct {
|
type MpSdk struct {
|
||||||
|
|
@ -153,58 +151,3 @@ func (o *MpSdk) GetScheme(params map[string]interface{}) (string, error) {
|
||||||
}
|
}
|
||||||
return g.Get("openlink").String(), nil
|
return g.Get("openlink").String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *MpSdk) GetEncryptUrl(params map[string]any) (string, error) {
|
|
||||||
newParams := map[string]any{
|
|
||||||
"env_version": cmp.Or(cast.ToString(params["env_version"]), "release"),
|
|
||||||
}
|
|
||||||
if path := cast.ToString(params["path"]); path != "" {
|
|
||||||
newParams["path"] = path
|
|
||||||
}
|
|
||||||
if query := cast.ToString(params["query"]); query != "" {
|
|
||||||
newParams["query"] = query
|
|
||||||
}
|
|
||||||
|
|
||||||
_, hasExpireType := params["expire_type"]
|
|
||||||
_, hasExpireTime := params["expire_time"]
|
|
||||||
_, hasExpireInterval := params["expire_interval"]
|
|
||||||
if hasExpireType {
|
|
||||||
newParams["expire_type"] = cast.ToInt(params["expire_type"])
|
|
||||||
} else if hasExpireInterval {
|
|
||||||
newParams["expire_type"] = 1
|
|
||||||
} else if hasExpireTime {
|
|
||||||
newParams["expire_type"] = 0
|
|
||||||
}
|
|
||||||
if hasExpireTime {
|
|
||||||
newParams["expire_time"] = cast.ToInt64(params["expire_time"])
|
|
||||||
}
|
|
||||||
if hasExpireInterval {
|
|
||||||
newParams["expire_interval"] = cast.ToInt(params["expire_interval"])
|
|
||||||
}
|
|
||||||
|
|
||||||
marshal, err := json.Marshal(newParams)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
accessToken, err := o.getAccessToken()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
url := fmt.Sprintf("%s?access_token=%s", getWxUrlLink, accessToken)
|
|
||||||
res, err := http.Post(url, "application/json", bytes.NewBuffer(marshal))
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
defer res.Body.Close()
|
|
||||||
body, err := io.ReadAll(res.Body)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
g := gjson.ParseBytes(body)
|
|
||||||
errcode := g.Get("errcode").Int()
|
|
||||||
if errcode != 0 {
|
|
||||||
return "", fmt.Errorf("%d:%s", errcode, g.Get("errmsg"))
|
|
||||||
}
|
|
||||||
return g.Get("url_link").String(), nil
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue