互动
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.

28 lines
633 B

5 years ago
5 years ago
  1. package wechat
  2. import (
  3. mpoauth2 "github.com/chanxuehong/wechat/mp/oauth2"
  4. "github.com/chanxuehong/wechat/oauth2"
  5. )
  6. var (
  7. Appid = "wx7b0bcf476552c5e9"
  8. Secret = "f6aabdd40ea25272f4442603a7dc8028"
  9. )
  10. var Endpoint = mpoauth2.NewEndpoint(Appid, Secret)
  11. func GetToken(code string) (*oauth2.Token, error) {
  12. client := oauth2.Client{
  13. Endpoint: Endpoint,
  14. }
  15. return client.ExchangeToken(code)
  16. }
  17. func GetUserInfo(tk *oauth2.Token) (*mpoauth2.UserInfo, error) {
  18. return mpoauth2.GetUserInfo(tk.AccessToken, tk.OpenId, "", nil)
  19. }
  20. func MiniAuth(code string) (*mpoauth2.Session, error) {
  21. return mpoauth2.GetSession(Endpoint, code)
  22. }