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

chunshand / d3auth
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
outh_wb.go 1.42 KB
一键复制 编辑 Web IDE 原始数据 按行查看 历史
chunshand 提交于 2018-12-12 15:22 . 更新变量名问题错误
package d3auth
import (
"encoding/json"
"errors"
"regexp"
"strconv"
)
//获取登录地址
func (e *Auth_wb) Get_Rurl(state string) string {
return "https://api.weibo.com/oauth2/authorize?client_id=" + e.Conf.Appid + "&response_type=code&display=page&redirect_uri=" + e.Conf.Rurl + "&state=" + state
}
//获取token
func (e *Auth_wb) Get_Token(code string) (*Auth_wb_succ_res, error) {
str, err := HttpPost("https://api.weibo.com/oauth2/access_token?client_id=" + e.Conf.Appid + "&client_secret=" + e.Conf.Appkey + "&code=" + code + "&grant_type=authorization_code&redirect_uri=" + e.Conf.Rurl)
if err != nil {
return nil, err
}
ismatch, _ := regexp.MatchString("error", str)
if ismatch {
p := &Auth_wb_err_res{}
err := json.Unmarshal([]byte(str), p)
if err != nil {
return nil, err
}
return nil, errors.New("Error:" + strconv.Itoa(p.Error) + " Error_description:" + p.Error_description)
} else {
p := &Auth_wb_succ_res{}
err := json.Unmarshal([]byte(str), p)
if err != nil {
return nil, err
}
return p, nil
}
}
//获取第三方用户信息
func (e *Auth_wb) Get_User_Info(access_token string, openid string) (string, error) {
str, err := HttpGet("https://api.weibo.com/2/users/show.json?access_token=" + access_token + "&uid=" + openid)
if err != nil {
return "", err
}
return string(str), nil
}
//构造方法
func NewAuth_wb(config *Auth_conf) *Auth_wb {
return &Auth_wb{
Conf: config,
}
}
Go
1
https://gitee.com/chunshand/d3auth.git
git@gitee.com:chunshand/d3auth.git
chunshand
d3auth
d3auth
master

搜索帮助

14c37bed 8189591 565d56ea 8189591