api pay
This commit is contained in:
parent
8cf426abc3
commit
4eac72e0a5
|
@ -2,9 +2,18 @@ package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"enterprise/common/config"
|
"enterprise/common/config"
|
||||||
|
"enterprise/common/global"
|
||||||
"enterprise/server/service"
|
"enterprise/server/service"
|
||||||
|
"enterprise/server/session"
|
||||||
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/smbrave/goutil"
|
||||||
|
"github.com/spf13/cast"
|
||||||
"gitlab.batiao8.com/open/gosdk/qyweixin"
|
"gitlab.batiao8.com/open/gosdk/qyweixin"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type QyWeixin struct {
|
type QyWeixin struct {
|
||||||
|
@ -25,3 +34,46 @@ func (q *QyWeixin) Approve(ctx *gin.Context) {
|
||||||
|
|
||||||
qyApp.Callback(ctx)
|
qyApp.Callback(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (q *QyWeixin) Pay(ctx *gin.Context) {
|
||||||
|
userid := ctx.Query("userid")
|
||||||
|
amount := cast.ToInt64(ctx.Query("amount"))
|
||||||
|
title := ctx.Query("title")
|
||||||
|
pass := ctx.Query("pass")
|
||||||
|
if pass != "1c9dea1fb85cf06ab0b4d946d49aa92f" {
|
||||||
|
panic("password error")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 支付费用
|
||||||
|
var req qyweixin.PayReq
|
||||||
|
req.BillNo = fmt.Sprintf("API%s_%s", time.Now().Format("20060102150405"), userid)
|
||||||
|
req.Title = title
|
||||||
|
req.Userid = userid
|
||||||
|
req.TotalAmount = amount
|
||||||
|
qyPay := qyweixin.NewAppPay(&qyweixin.PayConfig{
|
||||||
|
Corpid: config.GetConfig().QyWeixin.Corpid,
|
||||||
|
Secret: config.GetConfig().QyWeixin.PaySecret,
|
||||||
|
Agent: config.GetConfig().QyWeixin.PayAgent,
|
||||||
|
SerialNumber: config.GetConfig().WxPay.PaySerialNumber,
|
||||||
|
ApiKey: config.GetConfig().WxPay.PayApiKeyV2,
|
||||||
|
MchId: config.GetConfig().WxPay.PayMchId,
|
||||||
|
CertPem: config.GetConfig().WxPay.PayCertPem,
|
||||||
|
KeyPem: config.GetConfig().WxPay.PayKeyPem,
|
||||||
|
})
|
||||||
|
if err := qyPay.PayMoney(&req); err != nil {
|
||||||
|
log.Errorf("pay error :%s", err.Error())
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
message := make([]string, 0)
|
||||||
|
|
||||||
|
message = append(message, fmt.Sprintf("【红包发放】[%s]", userid))
|
||||||
|
message = append(message, fmt.Sprintf("发放金额:%s", goutil.FormatMoney(amount))))
|
||||||
|
message = append(message, fmt.Sprintf("员工名称:%s", userid))
|
||||||
|
message = append(message, fmt.Sprintf("费用说明:%s", title))
|
||||||
|
|
||||||
|
if err := global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
|
||||||
|
log.Errorf("send message error :%s", err.Error())
|
||||||
|
}
|
||||||
|
ctx.JSON(http.StatusOK, session.NewRspOk())
|
||||||
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ func initRoutge(engine *gin.Engine) {
|
||||||
apiGroup.Use(base.Recovery)
|
apiGroup.Use(base.Recovery)
|
||||||
group.Use(base.Recovery)
|
group.Use(base.Recovery)
|
||||||
apiGroup.Any("/qyweixin/approve", qyweixin.Approve)
|
apiGroup.Any("/qyweixin/approve", qyweixin.Approve)
|
||||||
|
apiGroup.Any("/qyweixin/pay", qyweixin.Pay)
|
||||||
|
|
||||||
group.GET("/staff/salary", staff.Salary)
|
group.GET("/staff/salary", staff.Salary)
|
||||||
group.GET("/staff/sync/salary", staff.SyncStaffSalary)
|
group.GET("/staff/sync/salary", staff.SyncStaffSalary)
|
||||||
|
|
|
@ -163,7 +163,7 @@ func (a *Approve) handleRefund(detail *qyweixin.ApproveDetail) {
|
||||||
CertPem: config.GetConfig().WxPay.PayCertPem,
|
CertPem: config.GetConfig().WxPay.PayCertPem,
|
||||||
KeyPem: config.GetConfig().WxPay.PayKeyPem,
|
KeyPem: config.GetConfig().WxPay.PayKeyPem,
|
||||||
})
|
})
|
||||||
if qyPay.PayMoney(&req); err != nil {
|
if err = qyPay.PayMoney(&req); err != nil {
|
||||||
log.Errorf("pay error :%s", err.Error())
|
log.Errorf("pay error :%s", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue