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

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package wechatoffice
import (
"context"
"fmt"
"net/url"
)
// Oauth2 用户同意授权获取code
// https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html#0
func (c *Client) Oauth2(ctx context.Context, redirectUri, state string) string {
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())
}