@@ -25,6 +25,7 @@ import ( | |||||
"github.com/go-pay/gopay" | "github.com/go-pay/gopay" | ||||
alipay2 "github.com/go-pay/gopay/alipay" | alipay2 "github.com/go-pay/gopay/alipay" | ||||
"github.com/jinzhu/copier" | "github.com/jinzhu/copier" | ||||
"github.com/tidwall/gjson" | |||||
"time" | "time" | ||||
) | ) | ||||
@@ -595,13 +596,29 @@ func BindWxPayAccount(c *gin.Context) { | |||||
return | return | ||||
} | } | ||||
appid := svc.GetSysCfgStr("wechat_appid") | |||||
secret := svc.GetSysCfgStr("wechat_secret") | |||||
wxUrl := fmt.Sprintf("https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code", appid, secret, req.Code) | |||||
wechatResp, err := utils.CurlGet(wxUrl, nil) | |||||
if err != nil { | |||||
e.OutErr(c, 400, e.NewErr(400, "获取微信信息失败")) | |||||
return | |||||
} | |||||
utils.FilePutContents("WithdrawalBinding", utils.SerializeStr(wechatResp)) | |||||
openId := gjson.Get(string(wechatResp), "openid").String() | |||||
wechatToken := gjson.Get(string(wechatResp), "access_token").String() | |||||
wechatInfoUrl := "https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s" | |||||
wechatInfoUrl = fmt.Sprintf(wechatInfoUrl, wechatToken, openId) | |||||
wechatInfoResp, _ := utils.CurlGet(wechatInfoUrl, nil) | |||||
now := time.Now() | now := time.Now() | ||||
newWxUserInfo := model.WxUserInfo{ | newWxUserInfo := model.WxUserInfo{ | ||||
Uid: user.Id, | Uid: user.Id, | ||||
UserId: req.UserId, | |||||
OpenId: req.OpenId, | |||||
AppId: req.AppId, | |||||
Ext: req.Ext, | |||||
OpenId: openId, | |||||
UserId: gjson.Get(string(wechatResp), "unionid").String(), | |||||
UserName: gjson.Get(string(wechatInfoResp), "nickname").String(), | |||||
AppId: appid, | |||||
CreateAt: now.Format("2006-01-02 15:04:05"), | CreateAt: now.Format("2006-01-02 15:04:05"), | ||||
UpdateAt: now.Format("2006-01-02 15:04:05"), | UpdateAt: now.Format("2006-01-02 15:04:05"), | ||||
} | } | ||||
@@ -48,8 +48,5 @@ type BindAlipayAccountReq struct { | |||||
} | } | ||||
type BindWxPayAccountReq struct { | type BindWxPayAccountReq struct { | ||||
UserId string `json:"user_id"` // 微信用户 id | |||||
OpenId string `json:"open_id"` // 微信用户 open_id | |||||
AppId string `json:"app_id"` // 微信应用 appid | |||||
Ext string `json:"ext" ` // 拓展字段 | |||||
Code string `json:"code"` | |||||
} | } |
@@ -16,10 +16,10 @@ func Limiter(c *gin.Context) { | |||||
limit := 500 // 限流次数 | limit := 500 // 限流次数 | ||||
ttl := 2 // 限流过期时间 | ttl := 2 // 限流过期时间 | ||||
ip := utils.GetIP(c.Request) | ip := utils.GetIP(c.Request) | ||||
if ip != "221.4.210.167" { | |||||
e.OutErr(c, e.ERR, "系统维护中~") | |||||
return | |||||
} | |||||
//if ip != "221.4.210.167" { | |||||
// e.OutErr(c, e.ERR, "系统维护中~") | |||||
// return | |||||
//} | |||||
// 读取token或者ip | // 读取token或者ip | ||||
token := c.GetHeader("Authorization") | token := c.GetHeader("Authorization") | ||||
// 判断是否已经超出限额次数 | // 判断是否已经超出限额次数 | ||||
@@ -4618,20 +4618,7 @@ const docTemplate = `{ | |||||
"md.BindWxPayAccountReq": { | "md.BindWxPayAccountReq": { | ||||
"type": "object", | "type": "object", | ||||
"properties": { | "properties": { | ||||
"app_id": { | |||||
"description": "微信应用 appid", | |||||
"type": "string" | |||||
}, | |||||
"ext": { | |||||
"description": "拓展字段", | |||||
"type": "string" | |||||
}, | |||||
"open_id": { | |||||
"description": "微信用户 open_id", | |||||
"type": "string" | |||||
}, | |||||
"user_id": { | |||||
"description": "微信用户 id", | |||||
"code": { | |||||
"type": "string" | "type": "string" | ||||
} | } | ||||
} | } | ||||
@@ -4612,20 +4612,7 @@ | |||||
"md.BindWxPayAccountReq": { | "md.BindWxPayAccountReq": { | ||||
"type": "object", | "type": "object", | ||||
"properties": { | "properties": { | ||||
"app_id": { | |||||
"description": "微信应用 appid", | |||||
"type": "string" | |||||
}, | |||||
"ext": { | |||||
"description": "拓展字段", | |||||
"type": "string" | |||||
}, | |||||
"open_id": { | |||||
"description": "微信用户 open_id", | |||||
"type": "string" | |||||
}, | |||||
"user_id": { | |||||
"description": "微信用户 id", | |||||
"code": { | |||||
"type": "string" | "type": "string" | ||||
} | } | ||||
} | } | ||||
@@ -308,17 +308,7 @@ definitions: | |||||
type: object | type: object | ||||
md.BindWxPayAccountReq: | md.BindWxPayAccountReq: | ||||
properties: | properties: | ||||
app_id: | |||||
description: 微信应用 appid | |||||
type: string | |||||
ext: | |||||
description: 拓展字段 | |||||
type: string | |||||
open_id: | |||||
description: 微信用户 open_id | |||||
type: string | |||||
user_id: | |||||
description: 微信用户 id | |||||
code: | |||||
type: string | type: string | ||||
type: object | type: object | ||||
md.CollegeDetailReq: | md.CollegeDetailReq: | ||||
@@ -10,26 +10,26 @@ redis_addr: '127.0.0.1:6379' | |||||
redis_password: '' | redis_password: '' | ||||
#db: | |||||
# host: '119.23.182.117:3306' | |||||
# name: 'egg' | |||||
# user: 'root' | |||||
# psw: 'Fnuo123com@' | |||||
# show_log: true | |||||
# max_lifetime: 30 | |||||
# max_open_conns: 100 | |||||
# max_idle_conns: 100 | |||||
# path: 'tmp/%s.log' | |||||
db: | db: | ||||
host: 'advertisement-db.rwlb.rds.aliyuncs.com:3306' | |||||
host: '119.23.182.117:3306' | |||||
name: 'egg' | name: 'egg' | ||||
user: 'canal' | |||||
psw: 'DengBiao@1997' | |||||
user: 'root' | |||||
psw: 'Fnuo123com@' | |||||
show_log: true | show_log: true | ||||
max_lifetime: 30 | max_lifetime: 30 | ||||
max_open_conns: 100 | max_open_conns: 100 | ||||
max_idle_conns: 100 | max_idle_conns: 100 | ||||
path: 'tmp/%s.log' | path: 'tmp/%s.log' | ||||
#db: | |||||
# host: 'advertisement-db.rwlb.rds.aliyuncs.com:3306' | |||||
# name: 'egg' | |||||
# user: 'canal' | |||||
# psw: 'DengBiao@1997' | |||||
# show_log: true | |||||
# max_lifetime: 30 | |||||
# max_open_conns: 100 | |||||
# max_idle_conns: 100 | |||||
# path: 'tmp/%s.log' | |||||
#db_back: | #db_back: | ||||
# host: '119.23.182.117:3306' | # host: '119.23.182.117:3306' | ||||