当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
18 Star 97 Fork 15

chunshand / d3auth
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
outh_qq.go 2.38 KB
一键复制 编辑 原始数据 按行查看 历史
chunshand 提交于 2019-02-24 10:53 . 修改了2个方法的错误
package d3auth
import (
"encoding/json"
"errors"
"regexp"
"strconv"
)
//获取登录地址
func (e *Auth_qq) Get_Rurl(state string) string {
return "https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=" + e.Conf.Appid + "&redirect_uri=" + e.Conf.Rurl + "&state=" + state
}
//获取token
func (e *Auth_qq) Get_Token(code string) (string, error) {
str, err := HttpGet("https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=" + e.Conf.Appid + "&client_secret=" + e.Conf.Appkey + "&code=" + code + "&redirect_uri=" + e.Conf.Rurl)
if err != nil {
return "", err
}
ismatch, _ := regexp.MatchString("error", str)
if ismatch {
re, _ := regexp.Compile("({.*})")
newres := re.FindStringSubmatch(str)
errstr := newres[0]
p := &Auth_qq_err_res{}
err := json.Unmarshal([]byte(errstr), p)
if err != nil {
return "", err
}
return "", errors.New("Error:" + strconv.Itoa(p.Error) + " Error_description:" + p.Error_description)
} else {
re, _ := regexp.Compile("access_token=(.*)&expires_in")
newres := re.FindStringSubmatch(str)
if len(newres) >= 2 {
return newres[1], nil
}
return "", nil
}
}
//获取第三方id
func (e *Auth_qq) Get_Me(access_token string) (*Auth_qq_me, error) {
str, err := HttpGet("https://graph.qq.com/oauth2.0/me?access_token=" + access_token)
if err != nil {
return nil, err
}
ismatch, _ := regexp.MatchString("error", str)
if ismatch {
re, _ := regexp.Compile("({.*})")
newres := re.FindStringSubmatch(str)
errstr := newres[0]
p := &Auth_qq_err_res{}
err := json.Unmarshal([]byte(errstr), p)
if err != nil {
return nil, err
}
return nil, errors.New("Error:" + strconv.Itoa(p.Error) + " Error_description:" + p.Error_description)
} else {
re, _ := regexp.Compile("({.*})")
newres := re.FindStringSubmatch(str)
errstr := newres[0]
p := &Auth_qq_me{}
err := json.Unmarshal([]byte(errstr), p)
if err != nil {
return nil, err
}
return p, nil
}
}
//获取第三方用户信息
func (e *Auth_qq) Get_User_Info(access_token string, openid string) (string, error) {
str, err := HttpGet("https://graph.qq.com/user/get_user_info?access_token=" + access_token + "&oauth_consumer_key=" + e.Conf.Appid + "&openid=" + openid)
if err != nil {
return "", err
}
return string(str), nil
}
//构造方法
func NewAuth_qq(config *Auth_conf) *Auth_qq {
return &Auth_qq{
Conf: config,
}
}
Go
1
https://gitee.com/chunshand/d3auth.git
git@gitee.com:chunshand/d3auth.git
chunshand
d3auth
d3auth
master

搜索帮助