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

lorock / d3auth
暂停

forked from chunshand / d3auth
暂停
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
outh_wx.go 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
chunshand 提交于 2018-12-12 15:22 . 更新变量名问题错误
package d3auth
import (
"encoding/json"
"errors" // "fmt"
"regexp"
"strconv"
)
//获取登录地址
func (e *Auth_wx) Get_Rurl(state string) string {
return "https://open.weixin.qq.com/connect/qrconnect?appid=" + e.Conf.Appid + "&redirect_uri=" + e.Conf.Rurl + "&response_type=code&scope=snsapi_login&state=" + state
}
//获取token
func (e *Auth_wx) Get_Token(code string) (*Auth_wx_succ_res, error) {
str, err := HttpPost("https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + e.Conf.Appid + "&secret=" + e.Conf.Appkey + "&code=" + code + "&grant_type=authorization_code")
if err != nil {
return nil, err
}
ismatch, _ := regexp.MatchString("errcode", str)
if ismatch {
p := &Auth_wx_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_wx_succ_res{}
err := json.Unmarshal([]byte(str), p)
if err != nil {
return nil, err
}
return p, nil
}
}
//获取第三方用户信息
func (e *Auth_wx) Get_User_Info(access_token string, openid string) (string, error) {
str, err := HttpGet("https://api.weixin.qq.com/sns/userinfo?access_token=" + access_token + "&openid=" + openid)
if err != nil {
return "", err
}
return string(str), nil
}
//构造方法
func NewAuth_wx(config *Auth_conf) *Auth_wx {
return &Auth_wx{
Conf: config,
}
}
Go
1
https://gitee.com/lorock/d3auth.git
git@gitee.com:lorock/d3auth.git
lorock
d3auth
d3auth
master

搜索帮助