- weixinsns.
This commit is contained in:
25
business/jxcallback/auth/weixin/weixin.go
Normal file
25
business/jxcallback/auth/weixin/weixin.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package weixin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/weixinsnsapi"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
var (
|
||||
StrStateIsWrong = "state:%s状态不对"
|
||||
)
|
||||
|
||||
func GetUserInfo(code string, state string) (token *weixinsnsapi.UserInfo, err error) {
|
||||
if state == "" {
|
||||
wxapi := weixinsnsapi.New(api.WeixinAPI.GetAppID(), api.WeixinAPI.GetSecret())
|
||||
token, err2 := wxapi.RefreshToken(code)
|
||||
if err = err2; err == nil {
|
||||
return wxapi.GetUserInfo(token.OpenID)
|
||||
}
|
||||
} else {
|
||||
err = fmt.Errorf(StrStateIsWrong, state)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
Reference in New Issue
Block a user