master
huanghai 5 years ago
parent c150878390
commit 951040e7af

@ -572,7 +572,7 @@ func wxLogin(context *gin.Context) {
var code = context.PostForm("code")
//对接微信腾讯给的AK+SK
appId := "wx3e0449144386938a"
appSecret := "15a37979f34791ca8b920c386afaa0d5"
appSecret := "5175be38ddd689d1621df35cc22c192b"
//验证的地址
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)
@ -586,8 +586,12 @@ func wxLogin(context *gin.Context) {
body, err := ioutil.ReadAll(resp.Body)
if resp.StatusCode == 200 {
//将返回结果转为json
openid := gjson.Get(string(body), "openid")
context.JSON(http.StatusOK, map[string]interface{}{"success": true, "openid": openid})
result := gjson.Get(string(body), "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 {
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
var SwaggerInfo = swaggerInfo{
Version: "2.0",
Host: "127.0.0.1:8000",
Host: "10.10.14.187:8000",
BasePath: "",
Schemes: []string{},
Title: "东师理想统一认证中心(OAuth2+Sso)",

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

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

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

Loading…
Cancel
Save