You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wechatoffice/oauth2.go

20 lines
877 B

2 years ago
package wechatoffice
import (
2 years ago
"context"
2 years ago
"fmt"
"net/url"
)
// Oauth2 用户同意授权获取code
// https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html#0
2 years ago
func (c *Client) Oauth2(ctx context.Context, redirectUri, state string) string {
2 years ago
param := url.Values{}
param.Add("appid", c.GetAppId()) // 公众号的唯一标识
param.Add("redirect_uri", redirectUri) // 授权后重定向的回调链接地址, 请使用 urlEncode 对链接进行处理
param.Add("response_type", "code") // 返回类型
param.Add("scope", "snsapi_userinfo") // 应用授权作用域
param.Add("state", state) // 重定向后会带上state参数开发者可以填写a-zA-Z0-9的参数值最多128字节
return fmt.Sprintf("https://open.weixin.qq.com/connect/oauth2/authorize?%s#wechat_redirect", param.Encode())
}