@@ -3,6 +3,7 @@ package hdl | |||
import ( | |||
"applet/app/db" | |||
"applet/app/e" | |||
alipay "applet/app/lib/gopay" | |||
"applet/app/md" | |||
"applet/app/svc" | |||
"applet/app/utils" | |||
@@ -17,6 +18,7 @@ import ( | |||
"errors" | |||
"fmt" | |||
"github.com/gin-gonic/gin" | |||
"github.com/go-pay/gopay" | |||
"github.com/jinzhu/copier" | |||
"time" | |||
) | |||
@@ -389,6 +391,41 @@ func GetWithdrawCondition(c *gin.Context) { | |||
e.OutSuc(c, resp, nil) | |||
} | |||
// LaunchBindAlipayAccount | |||
// @Summary 蛋蛋星球-钱包-发起绑定支付宝获得URL | |||
// @Tags 钱包 | |||
// @Description 发起绑定支付宝获得URL | |||
// @Accept json | |||
// @Produce json | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Param req body md.LaunchBindAlipayAccountReq true "具体参数" | |||
// @Success 200 {string} "Url" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/v1/wallet/withdraw/launchBindAlipay [POST] | |||
func LaunchBindAlipayAccount(c *gin.Context) { | |||
var req md.LaunchBindAlipayAccountReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = svc.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
var alipayStruct *alipay.InitAlipayStruct | |||
client, err := alipay.InitAlipay(alipayStruct) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
appId := client.AppId | |||
redirectUri := req.RedirectUri | |||
scope := "auth_user" | |||
url := fmt.Sprintf("https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=" + appId + "&scope=" + scope + "&redirect_uri=" + redirectUri) | |||
e.OutSuc(c, url, nil) | |||
} | |||
// BindAlipayAccount | |||
// @Summary 蛋蛋星球-钱包-绑定支付宝 | |||
// @Tags 钱包 | |||
@@ -411,36 +448,46 @@ func BindAlipayAccount(c *gin.Context) { | |||
} | |||
user := svc.GetUser(c) | |||
alipayUserInfoDb := implement.NewAlipayUserInfoDb(db.Db) | |||
alipayUserInfo, err := alipayUserInfoDb.GetAlipayUserInfo(user.Id) | |||
var alipayStruct *alipay.InitAlipayStruct | |||
client, err := alipay.InitAlipay(alipayStruct) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
if alipayUserInfo != nil { | |||
e.OutErr(c, e.ERR, errors.New("用户已绑定支付宝").Error()) | |||
var bm gopay.BodyMap | |||
bm = bm.Set("grant_type", "authorization_code") | |||
bm = bm.Set("code", req.AuthCode) | |||
systemOauthToken, err := client.SystemOauthToken(c, bm) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
info, err := client.UserInfoShare(c, systemOauthToken.Response.AccessToken) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
now := time.Now() | |||
newAlipayUserInfo := model.AlipayUserInfo{ | |||
m := model.AlipayUserInfo{ | |||
Uid: user.Id, | |||
UserId: req.UserId, | |||
OpenId: req.OpenId, | |||
AppId: req.AppId, | |||
Ext: req.Ext, | |||
UserId: info.Response.UserId, | |||
OpenId: info.Response.OpenId, | |||
AppId: client.AppId, | |||
UserName: info.Response.NickName, | |||
Ext: "", | |||
CreateAt: now.Format("2006-01-02 15:04:05"), | |||
UpdateAt: now.Format("2006-01-02 15:04:05"), | |||
} | |||
affected, err := alipayUserInfoDb.AlipayUserInfoInsert(&newAlipayUserInfo) | |||
infoDb := implement.NewAlipayUserInfoDb(db.Db) | |||
_, err = infoDb.AlipayUserInfoInsert(&m) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if affected <= 0 { | |||
e.OutErr(c, e.ERR, errors.New("绑定失败")) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
} | |||
@@ -40,11 +40,12 @@ type GetWithdrawConditionResp struct { | |||
NotWithdrawReason string `json:"not_withdraw_reason"` // 不能提现原因 | |||
} | |||
type LaunchBindAlipayAccountReq struct { | |||
RedirectUri string `json:"redirect_uri"` // 回调页面,是经过转义的 URL 链接(url 必须以 HTTP 或者 HTTPS 开头) | |||
} | |||
type BindAlipayAccountReq struct { | |||
UserId string `json:"user_id"` // 支付宝用户id | |||
OpenId string `json:"open_id"` // 支付宝用户open_id | |||
AppId string `json:"app_id"` // 支付宝商户应用appid | |||
Ext string `json:"ext"` // 拓展字段 | |||
AuthCode string `json:"auth_code"` // 支付宝回调的临时授权码 | |||
} | |||
type BindWxPayAccountReq struct { | |||
@@ -135,10 +135,11 @@ func route(r *gin.RouterGroup) { | |||
rWallet.GET("/amountFlow", hdl.GetAmountFlow) // 余额流水 | |||
rWithdraw := rWallet.Group("/withdraw") | |||
{ | |||
rWithdraw.GET("/index", hdl.WithdrawGetAmount) | |||
rWithdraw.POST("/apply", hdl.WithdrawApply) | |||
rWithdraw.GET("/condition", hdl.GetWithdrawCondition) | |||
rWithdraw.POST("/bindAlipay", hdl.BindAlipayAccount) | |||
rWithdraw.GET("/index", hdl.WithdrawGetAmount) // 查询余额 | |||
rWithdraw.POST("/apply", hdl.WithdrawApply) // 发起提现申请 | |||
rWithdraw.GET("/condition", hdl.GetWithdrawCondition) // 获取提现条件 | |||
rWithdraw.POST("/launchBindAlipay", hdl.LaunchBindAlipayAccount) // 支付宝发起绑定请求获得 url | |||
rWithdraw.POST("/bindAlipay", hdl.BindAlipayAccount) // 绑定支付宝 | |||
rWithdraw.POST("/bindWxPay", hdl.BindWxPayAccount) | |||
} | |||
} | |||
@@ -2913,6 +2913,53 @@ const docTemplate = `{ | |||
} | |||
} | |||
}, | |||
"/api/v1/wallet/withdraw/launchBindAlipay": { | |||
"post": { | |||
"description": "发起绑定支付宝获得URL", | |||
"consumes": [ | |||
"application/json" | |||
], | |||
"produces": [ | |||
"application/json" | |||
], | |||
"tags": [ | |||
"钱包" | |||
], | |||
"summary": "蛋蛋星球-钱包-发起绑定支付宝获得URL", | |||
"parameters": [ | |||
{ | |||
"type": "string", | |||
"description": "验证参数Bearer和token空格拼接", | |||
"name": "Authorization", | |||
"in": "header", | |||
"required": true | |||
}, | |||
{ | |||
"description": "具体参数", | |||
"name": "req", | |||
"in": "body", | |||
"required": true, | |||
"schema": { | |||
"$ref": "#/definitions/md.LaunchBindAlipayAccountReq" | |||
} | |||
} | |||
], | |||
"responses": { | |||
"200": { | |||
"description": "Url", | |||
"schema": { | |||
"type": "string" | |||
} | |||
}, | |||
"400": { | |||
"description": "具体错误", | |||
"schema": { | |||
"$ref": "#/definitions/md.Response" | |||
} | |||
} | |||
} | |||
} | |||
}, | |||
"/api/v1/wechatLogin": { | |||
"post": { | |||
"description": "微信登陆", | |||
@@ -3177,20 +3224,8 @@ const docTemplate = `{ | |||
"md.BindAlipayAccountReq": { | |||
"type": "object", | |||
"properties": { | |||
"app_id": { | |||
"description": "支付宝商户应用appid", | |||
"type": "string" | |||
}, | |||
"ext": { | |||
"description": "拓展字段", | |||
"type": "string" | |||
}, | |||
"open_id": { | |||
"description": "支付宝用户open_id", | |||
"type": "string" | |||
}, | |||
"user_id": { | |||
"description": "支付宝用户id", | |||
"auth_code": { | |||
"description": "支付宝回调的临时授权码", | |||
"type": "string" | |||
} | |||
} | |||
@@ -4038,6 +4073,15 @@ const docTemplate = `{ | |||
} | |||
} | |||
}, | |||
"md.LaunchBindAlipayAccountReq": { | |||
"type": "object", | |||
"properties": { | |||
"redirect_uri": { | |||
"description": "回调页面,是经过转义的 URL 链接(url 必须以 HTTP 或者 HTTPS 开头)", | |||
"type": "string" | |||
} | |||
} | |||
}, | |||
"md.LoginReq": { | |||
"type": "object", | |||
"required": [ | |||
@@ -2907,6 +2907,53 @@ | |||
} | |||
} | |||
}, | |||
"/api/v1/wallet/withdraw/launchBindAlipay": { | |||
"post": { | |||
"description": "发起绑定支付宝获得URL", | |||
"consumes": [ | |||
"application/json" | |||
], | |||
"produces": [ | |||
"application/json" | |||
], | |||
"tags": [ | |||
"钱包" | |||
], | |||
"summary": "蛋蛋星球-钱包-发起绑定支付宝获得URL", | |||
"parameters": [ | |||
{ | |||
"type": "string", | |||
"description": "验证参数Bearer和token空格拼接", | |||
"name": "Authorization", | |||
"in": "header", | |||
"required": true | |||
}, | |||
{ | |||
"description": "具体参数", | |||
"name": "req", | |||
"in": "body", | |||
"required": true, | |||
"schema": { | |||
"$ref": "#/definitions/md.LaunchBindAlipayAccountReq" | |||
} | |||
} | |||
], | |||
"responses": { | |||
"200": { | |||
"description": "Url", | |||
"schema": { | |||
"type": "string" | |||
} | |||
}, | |||
"400": { | |||
"description": "具体错误", | |||
"schema": { | |||
"$ref": "#/definitions/md.Response" | |||
} | |||
} | |||
} | |||
} | |||
}, | |||
"/api/v1/wechatLogin": { | |||
"post": { | |||
"description": "微信登陆", | |||
@@ -3171,20 +3218,8 @@ | |||
"md.BindAlipayAccountReq": { | |||
"type": "object", | |||
"properties": { | |||
"app_id": { | |||
"description": "支付宝商户应用appid", | |||
"type": "string" | |||
}, | |||
"ext": { | |||
"description": "拓展字段", | |||
"type": "string" | |||
}, | |||
"open_id": { | |||
"description": "支付宝用户open_id", | |||
"type": "string" | |||
}, | |||
"user_id": { | |||
"description": "支付宝用户id", | |||
"auth_code": { | |||
"description": "支付宝回调的临时授权码", | |||
"type": "string" | |||
} | |||
} | |||
@@ -4032,6 +4067,15 @@ | |||
} | |||
} | |||
}, | |||
"md.LaunchBindAlipayAccountReq": { | |||
"type": "object", | |||
"properties": { | |||
"redirect_uri": { | |||
"description": "回调页面,是经过转义的 URL 链接(url 必须以 HTTP 或者 HTTPS 开头)", | |||
"type": "string" | |||
} | |||
} | |||
}, | |||
"md.LoginReq": { | |||
"type": "object", | |||
"required": [ | |||
@@ -155,17 +155,8 @@ definitions: | |||
type: object | |||
md.BindAlipayAccountReq: | |||
properties: | |||
app_id: | |||
description: 支付宝商户应用appid | |||
type: string | |||
ext: | |||
description: 拓展字段 | |||
type: string | |||
open_id: | |||
description: 支付宝用户open_id | |||
type: string | |||
user_id: | |||
description: 支付宝用户id | |||
auth_code: | |||
description: 支付宝回调的临时授权码 | |||
type: string | |||
type: object | |||
md.BindWxPayAccountReq: | |||
@@ -751,6 +742,12 @@ definitions: | |||
description: 能否签到 | |||
type: boolean | |||
type: object | |||
md.LaunchBindAlipayAccountReq: | |||
properties: | |||
redirect_uri: | |||
description: 回调页面,是经过转义的 URL 链接(url 必须以 HTTP 或者 HTTPS 开头) | |||
type: string | |||
type: object | |||
md.LoginReq: | |||
properties: | |||
code: | |||
@@ -3340,6 +3337,37 @@ paths: | |||
summary: 蛋蛋星球-钱包-提现余额(获取) | |||
tags: | |||
- 钱包 | |||
/api/v1/wallet/withdraw/launchBindAlipay: | |||
post: | |||
consumes: | |||
- application/json | |||
description: 发起绑定支付宝获得URL | |||
parameters: | |||
- description: 验证参数Bearer和token空格拼接 | |||
in: header | |||
name: Authorization | |||
required: true | |||
type: string | |||
- description: 具体参数 | |||
in: body | |||
name: req | |||
required: true | |||
schema: | |||
$ref: '#/definitions/md.LaunchBindAlipayAccountReq' | |||
produces: | |||
- application/json | |||
responses: | |||
"200": | |||
description: Url | |||
schema: | |||
type: string | |||
"400": | |||
description: 具体错误 | |||
schema: | |||
$ref: '#/definitions/md.Response' | |||
summary: 蛋蛋星球-钱包-发起绑定支付宝获得URL | |||
tags: | |||
- 钱包 | |||
/api/v1/wechatLogin: | |||
post: | |||
consumes: | |||