|
|
@@ -25,6 +25,7 @@ import ( |
|
|
|
"github.com/go-pay/gopay" |
|
|
|
alipay2 "github.com/go-pay/gopay/alipay" |
|
|
|
"github.com/jinzhu/copier" |
|
|
|
"github.com/tidwall/gjson" |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
@@ -595,13 +596,29 @@ func BindWxPayAccount(c *gin.Context) { |
|
|
|
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() |
|
|
|
newWxUserInfo := model.WxUserInfo{ |
|
|
|
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"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
} |
|
|
|