auth
This commit is contained in:
parent
939120ddb9
commit
fe1766242f
|
@ -16,6 +16,16 @@ type Payment struct {
|
||||||
func NewPayment() *Payment {
|
func NewPayment() *Payment {
|
||||||
return &Payment{}
|
return &Payment{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (q *Payment) AlipayAuth(ctx *gin.Context) {
|
||||||
|
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
|
||||||
|
authCode := ctx.Query("auth_code")
|
||||||
|
state := ctx.Query("state")
|
||||||
|
|
||||||
|
data := service.NewPay().AlipayAuth(sess, authCode, state)
|
||||||
|
ctx.JSON(http.StatusOK, session.NewRsp(data))
|
||||||
|
}
|
||||||
|
|
||||||
func (q *Payment) Pay(ctx *gin.Context) {
|
func (q *Payment) Pay(ctx *gin.Context) {
|
||||||
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
|
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
|
||||||
corp, err := dao.NewCorpDao().GetByHost(sess.GetHeader().Host)
|
corp, err := dao.NewCorpDao().GetByHost(sess.GetHeader().Host)
|
||||||
|
|
|
@ -17,6 +17,7 @@ func initRoutge(engine *gin.Engine) {
|
||||||
noTokenGroup.Use(base.Recovery).Use(base.Before)
|
noTokenGroup.Use(base.Recovery).Use(base.Before)
|
||||||
|
|
||||||
noTokenGroup.POST("/pay", controller.NewPayment().Pay)
|
noTokenGroup.POST("/pay", controller.NewPayment().Pay)
|
||||||
|
noTokenGroup.GET("/payment/auth/alipay", controller.NewPayment().AlipayAuth)
|
||||||
noTokenGroup.POST("/payment", controller.NewPayment().Pay)
|
noTokenGroup.POST("/payment", controller.NewPayment().Pay)
|
||||||
apiGroup.GET("/payment", controller.NewPayment().List)
|
apiGroup.GET("/payment", controller.NewPayment().List)
|
||||||
apiGroup.GET("/payment/suggest", controller.NewPayment().Suggest)
|
apiGroup.GET("/payment/suggest", controller.NewPayment().Suggest)
|
||||||
|
|
|
@ -25,6 +25,33 @@ func NewPay() *Pay {
|
||||||
return &Pay{}
|
return &Pay{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Pay) AlipayAuth(sess *session.AdminSession, authCode, state string) interface{} {
|
||||||
|
|
||||||
|
corp, err := dao.NewCorpDao().GetByHost(sess.GetHeader().Host)
|
||||||
|
session.CheckDBError(err)
|
||||||
|
session.CheckNilError(corp)
|
||||||
|
cli := config.GetAliPayClient(corp.GetConfig().PayChannel)
|
||||||
|
|
||||||
|
var req alipay.SystemOauthToken
|
||||||
|
req.Code = authCode
|
||||||
|
req.GrantType = "authorization_code"
|
||||||
|
res, err := cli.SystemOauthToken(context.Background(), req)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("error :%s", err.Error())
|
||||||
|
panic(config.ErrInternal.New().Append(err))
|
||||||
|
}
|
||||||
|
if !res.IsSuccess() {
|
||||||
|
log.Errorf(goutil.EncodeJSON(res))
|
||||||
|
panic(config.ErrInternal.New().Append(goutil.EncodeJSON(res)))
|
||||||
|
}
|
||||||
|
|
||||||
|
data := make(map[string]interface{})
|
||||||
|
data["state"] = state
|
||||||
|
data["userid"] = res.UserId
|
||||||
|
log.Errorf("state=%s,userid=%s", state, res.UserId)
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Pay) Pay(corp *model.Corp, req *api.PayReq) {
|
func (p *Pay) Pay(corp *model.Corp, req *api.PayReq) {
|
||||||
|
|
||||||
user, err := dao.NewStaffUserDao().GetByUsername(corp.Id, req.Username)
|
user, err := dao.NewStaffUserDao().GetByUsername(corp.Id, req.Username)
|
||||||
|
|
Loading…
Reference in New Issue