wechat

package
v0.0.0-...-408e41c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2019 License: MIT Imports: 16 Imported by: 0

README

如何使用微信网页授权

微信公众号提供测试账号,无需注册申请公众号就可以测试

  1. 登录 https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index

记住 appID 和 appSecret, 并设置 网页授权获取用户基本信息 授权回调页面域名

  1. 配置 wechat provider
  Auth.RegisterProvider(wechat.New(&wechat.Config{
    AppID:        "<appID>",
    AppSecret:    "<appSecret>",
    RedirectURL:  "http://xxxxx.ngrok.io/auth/wechat/callback",
  }))

假如 go run main.go -> 打开的是 localhost:9000 运行 ngrok 代理 ngrok http 900, 记住 url 第一步需要填 xxx.ngrok.io 域名, 不带 http 或 https, 填域名就可以了 第二步中的 RedirectURL

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	AppID            string
	AppSecret        string
	RedirectURL      string
	Scope            string
	AuthorizeHandler func(*auth.Context) (*claims.Claims, error)
}

Config github Config

type UserInfo

type UserInfo struct {
	OpenId   string `json:"openid"`   // 用户的唯一标识
	Nickname string `json:"nickname"` // 用户昵称
	Sex      int    `json:"sex"`      // 用户的性别, 值为1时是男性, 值为2时是女性, 值为0时是未知
	City     string `json:"city"`     // 普通用户个人资料填写的城市
	Province string `json:"province"` // 用户个人资料填写的省份
	Country  string `json:"country"`  // 国家, 如中国为CN

	// 用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),
	// 用户没有头像时该项为空。若用户更换头像,原有头像URL将失效。
	HeadImageURL string `json:"headimgurl,omitempty"`

	// Privilege []string `json:"privilege,omitempty"` // 用户特权信息,json 数组,如微信沃卡用户为(chinaunicom)
	UnionId string `json:"unionid,omitempty"` // 只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。
}

UserInfo wechat user info structure

type WechatProvider

type WechatProvider struct {
	*Config
}

WechatProvider provide login with Wechat 网页授权

func New

func New(config *Config) *WechatProvider

func (WechatProvider) Callback

func (provider WechatProvider) Callback(context *auth.Context)

Callback implement Callback with wechat provider

func (WechatProvider) ConfigAuth

func (provider WechatProvider) ConfigAuth(*auth.Auth)

ConfigAuth config auth

func (WechatProvider) GetName

func (WechatProvider) GetName() string

GetName return provider name

func (WechatProvider) Login

func (provider WechatProvider) Login(context *auth.Context)

Login implemented login with wechat provider

func (WechatProvider) Logout

func (WechatProvider) Logout(context *auth.Context)

Logout implemented logout with wechat provider

func (WechatProvider) Register

func (provider WechatProvider) Register(context *auth.Context)

Register implemented register with wechat provider

func (WechatProvider) ServeHTTP

func (WechatProvider) ServeHTTP(*auth.Context)

ServeHTTP implement ServeHTTP with github provider

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL