-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add:urlscheme-query * add:urlscheme-query Co-authored-by: caoxianfeng <caoxianfeng@rcrai.com>
- Loading branch information
1 parent
56350c3
commit d5e7c80
Showing
2 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters