master
huanghai 5 years ago
parent c150878390
commit 951040e7af

@ -572,7 +572,7 @@ func wxLogin(context *gin.Context) {
var code = context.PostForm("code") var code = context.PostForm("code")
//对接微信腾讯给的AK+SK //对接微信腾讯给的AK+SK
appId := "wx3e0449144386938a" appId := "wx3e0449144386938a"
appSecret := "15a37979f34791ca8b920c386afaa0d5" appSecret := "5175be38ddd689d1621df35cc22c192b"
//验证的地址 //验证的地址
var accessTokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token" var accessTokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token"
var accessTokenParams = fmt.Sprintf("appid=%s&secret=%s&code=%s&grant_type=authorization_code", appId, appSecret, code) var accessTokenParams = fmt.Sprintf("appid=%s&secret=%s&code=%s&grant_type=authorization_code", appId, appSecret, code)
@ -586,8 +586,12 @@ func wxLogin(context *gin.Context) {
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if resp.StatusCode == 200 { if resp.StatusCode == 200 {
//将返回结果转为json //将返回结果转为json
openid := gjson.Get(string(body), "openid") result := gjson.Get(string(body), "openid")
context.JSON(http.StatusOK, map[string]interface{}{"success": true, "openid": openid}) if len(result.Str) == 0 {
context.JSON(http.StatusOK, map[string]interface{}{"success": false, "openid": ""})
} else {
context.JSON(http.StatusOK, map[string]interface{}{"success": true, "openid": result.Str})
}
} else { } else {
context.JSON(http.StatusOK, map[string]interface{}{"success": false, "openid": ""}) context.JSON(http.StatusOK, map[string]interface{}{"success": false, "openid": ""})
} }

@ -784,7 +784,7 @@ type swaggerInfo struct {
// SwaggerInfo holds exported Swagger Info so clients can modify it // SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = swaggerInfo{ var SwaggerInfo = swaggerInfo{
Version: "2.0", Version: "2.0",
Host: "127.0.0.1:8000", Host: "10.10.14.187:8000",
BasePath: "", BasePath: "",
Schemes: []string{}, Schemes: []string{},
Title: "东师理想统一认证中心(OAuth2+Sso)", Title: "东师理想统一认证中心(OAuth2+Sso)",

@ -7,7 +7,7 @@
"license": {}, "license": {},
"version": "2.0" "version": "2.0"
}, },
"host": "127.0.0.1:8000", "host": "10.10.14.187:8000",
"paths": { "paths": {
"/oauth2/access_token": { "/oauth2/access_token": {
"post": { "post": {

@ -32,7 +32,7 @@ definitions:
description: 个数 description: 个数
type: object type: object
type: object type: object
host: 127.0.0.1:8000 host: 10.10.14.187:8000
info: info:
contact: {} contact: {}
description: 参考自xxl-sso description: 参考自xxl-sso

@ -67,7 +67,7 @@ func startOAuth2Server() {
// @title 东师理想统一认证中心(OAuth2+Sso) // @title 东师理想统一认证中心(OAuth2+Sso)
// @version 2.0 // @version 2.0
// @description 参考自xxl-sso // @description 参考自xxl-sso
// @host 127.0.0.1:8000 // @host 10.10.14.187:8000
func main() { func main() {
// 发布模式 // 发布模式
//gin.SetMode(gin.ReleaseMode) //gin.SetMode(gin.ReleaseMode)

Loading…
Cancel
Save