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

24 lines
595 B

5 years ago
5 years ago
5 years ago
5 years ago
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. "hudongzhuanjia/utils/define"
  6. )
  7. var Endpoint = mpoauth2.NewEndpoint(define.WxAppId, define.Secret)
  8. func GetToken(code string) (*oauth2.Token, error) {
  9. client := oauth2.Client{
  10. Endpoint: Endpoint,
  11. }
  12. return client.ExchangeToken(code)
  13. }
  14. func GetUserInfo(tk *oauth2.Token) (*mpoauth2.UserInfo, error) {
  15. return mpoauth2.GetUserInfo(tk.AccessToken, tk.OpenId, "", nil)
  16. }
  17. func MiniAuth(code string) (*mpoauth2.Session, error) {
  18. return mpoauth2.GetSession(Endpoint, code)
  19. }