Files
jx-callback/business/auth2/authprovider/alipay/alipay.go
suyl 820abd00d6 aa
2021-05-06 16:17:44 +08:00

57 lines
1.6 KiB
Go

package alipay
import (
"encoding/json"
"git.rosy.net.cn/baseapi/platformapi/alipayapi"
"git.rosy.net.cn/jx-callback/business/auth2"
"git.rosy.net.cn/jx-callback/business/auth2/authprovider"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
)
const (
AuthType = "alipaycode"
)
type Auther struct {
authprovider.DefAuther
}
var (
AutherObj *Auther
)
func init() {
AutherObj = new(Auther)
auth2.RegisterAuther(AuthType, AutherObj)
}
func (a *Auther) VerifySecret(dummy, code string) (authBindEx *auth2.AuthBindEx, err error) {
globals.SugarLogger.Debugf("VerifySecret dummy:%s, code:%s", dummy, code)
tokenInfo, err := api.AliPayAPI.SystemAuthToken(alipayapi.GrantTypeCode, code, "")
if err == nil {
//userInfo, err2 := api.AliPayAPI.UserInfoShare(tokenInfo.AccessToken)
//if err = err2; err == nil {
//if authBindEx, err = a.UnionFindAuthBind(AuthType, api.AliPayAPI.GetAppID(), nil, userInfo.UserID, "", userInfo); err == nil {
// authBindEx.UserHint = &auth2.UserBasic{
// Name: userInfo.NickName,
// Avatar: userInfo.Avatar,
// }
//}
//}
authBindEx = &auth2.AuthBindEx{}
authBindEx.Type = AuthType
authBindEx.TypeID = globals.AliKey
authBindEx.AuthID = tokenInfo.UserID
authBindEx.AuthID2 = tokenInfo.AlipayUserID
authBindEx.Status = model.YES
if data, err2 := json.Marshal(tokenInfo); err2 == nil {
authBindEx.DetailData = string(data)
}
authBindEx.AuthSecret = tokenInfo.AccessToken
authBindEx.AuthSecret2 = tokenInfo.RefreshToken
}
return authBindEx, err
}