mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
feat:add urlscheme.query (#553)
* add:urlscheme-query * add:urlscheme-query Co-authored-by: caoxianfeng <caoxianfeng@rcrai.com>
This commit is contained in:
70
miniprogram/urlscheme/query.go
Normal file
70
miniprogram/urlscheme/query.go
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
package urlscheme
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/silenceper/wechat/v2/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
querySchemeURL = "https://api.weixin.qq.com/wxa/queryscheme?access_token=%s"
|
||||||
|
)
|
||||||
|
|
||||||
|
// QueryScheme 获取小程序访问scheme
|
||||||
|
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.query.html#参数
|
||||||
|
type QueryScheme struct {
|
||||||
|
// 小程序 scheme 码
|
||||||
|
Scheme string `json:"scheme"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SchemeInfo scheme 配置
|
||||||
|
type SchemeInfo struct {
|
||||||
|
// 小程序 appid。
|
||||||
|
AppID string `json:"appid"`
|
||||||
|
// 小程序页面路径。
|
||||||
|
Path string `json:"path"`
|
||||||
|
// 小程序页面query。
|
||||||
|
Query string `json:"query"`
|
||||||
|
// 创建时间,为 Unix 时间戳。
|
||||||
|
CreateTime int64 `json:"create_time"`
|
||||||
|
// 到期失效时间,为 Unix 时间戳,0 表示永久生效
|
||||||
|
ExpireTime int64 `json:"expire_time"`
|
||||||
|
// 要打开的小程序版本。正式版为"release",体验版为"trial",开发版为"develop"。
|
||||||
|
EnvVersion EnvVersion `json:"env_version"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// resQueryScheme 返回结构体
|
||||||
|
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.query.html#参数
|
||||||
|
type resQueryScheme struct {
|
||||||
|
// 通用错误
|
||||||
|
*util.CommonError
|
||||||
|
// scheme 配置
|
||||||
|
SchemeInfo SchemeInfo `json:"scheme_info"`
|
||||||
|
// 访问该链接的openid,没有用户访问过则为空字符串
|
||||||
|
VisitOpenid string `json:"visit_openid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryScheme 查询小程序 scheme 码
|
||||||
|
func (u *URLScheme) QueryScheme(querySchemeParams QueryScheme) (schemeInfo SchemeInfo, visitOpenid string, err error) {
|
||||||
|
var accessToken string
|
||||||
|
accessToken, err = u.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
urlStr := fmt.Sprintf(querySchemeURL, accessToken)
|
||||||
|
var response []byte
|
||||||
|
response, err = util.PostJSON(urlStr, querySchemeParams)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用通用方法返回错误
|
||||||
|
var res resQueryScheme
|
||||||
|
err = util.DecodeWithError(response, &res, "QueryScheme")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.SchemeInfo, res.VisitOpenid, nil
|
||||||
|
}
|
||||||
@@ -22,12 +22,21 @@ const generateURL = "https://api.weixin.qq.com/wxa/generatescheme"
|
|||||||
// TExpireType 失效类型 (指定时间戳/指定间隔)
|
// TExpireType 失效类型 (指定时间戳/指定间隔)
|
||||||
type TExpireType int
|
type TExpireType int
|
||||||
|
|
||||||
|
// EnvVersion 要打开的小程序版本
|
||||||
|
type EnvVersion string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// ExpireTypeTime 指定时间戳后失效
|
// ExpireTypeTime 指定时间戳后失效
|
||||||
ExpireTypeTime TExpireType = 0
|
ExpireTypeTime TExpireType = 0
|
||||||
|
|
||||||
// ExpireTypeInterval 间隔指定天数后失效
|
// ExpireTypeInterval 间隔指定天数后失效
|
||||||
ExpireTypeInterval TExpireType = 1
|
ExpireTypeInterval TExpireType = 1
|
||||||
|
|
||||||
|
// EnvVersionRelease 正式版为"release"
|
||||||
|
EnvVersionRelease EnvVersion = "release"
|
||||||
|
// EnvVersionTrial 体验版为"trial"
|
||||||
|
EnvVersionTrial EnvVersion = "trial"
|
||||||
|
// EnvVersionDevelop 开发版为"develop"
|
||||||
|
EnvVersionDevelop EnvVersion = "develop"
|
||||||
)
|
)
|
||||||
|
|
||||||
// JumpWxa 跳转到的目标小程序信息
|
// JumpWxa 跳转到的目标小程序信息
|
||||||
@@ -35,7 +44,7 @@ type JumpWxa struct {
|
|||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
Query string `json:"query"`
|
Query string `json:"query"`
|
||||||
// envVersion 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
|
// envVersion 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
|
||||||
EnvVersion string `json:"env_version,omitempty"`
|
EnvVersion EnvVersion `json:"env_version,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// USParams 请求参数
|
// USParams 请求参数
|
||||||
|
|||||||
Reference in New Issue
Block a user