54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
package rechargectrl
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
"strconv"
|
|
"time"
|
|
|
|
"91porn-server/common/log"
|
|
"91porn-server/common/rchgutil"
|
|
"91porn-server/web/service/rechargeser"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// DXZhiFuCallBack 金鱼结构回调函数
|
|
func DXZhiFuCallBack(ctx *gin.Context) {
|
|
if err := func() error {
|
|
rchg := rchgutil.DXZhiFuRes{}
|
|
err := ctx.ShouldBind(&rchg)
|
|
if err != nil {
|
|
log.Error(fmt.Sprintf("DXZhiFu callback parameter bind fail error:%+v:", err))
|
|
return err
|
|
}
|
|
log.Info(fmt.Sprintf("DXZhiFu callback parameter data:%+v:", rchg))
|
|
if rchg.Sign != rchg.ToSign() {
|
|
log.Error(fmt.Sprintf("DXZhiFu callback sign verify fail error:%+v:", err))
|
|
return errors.New("check sign fail")
|
|
}
|
|
payMoneyf, err := strconv.ParseFloat(rchg.PayMoney, 64)
|
|
if err != nil {
|
|
log.Error(fmt.Sprintf("DXZhiFu callback ParseFloat fail error:%+v:", err))
|
|
return fmt.Errorf("invalid payMoney %s", rchg.PayMoney)
|
|
}
|
|
payMoneyf = payMoneyf * 100
|
|
payMoney := int64(payMoneyf)
|
|
var status int = 200
|
|
if rchg.Code != "00" {
|
|
return nil
|
|
}
|
|
loc, _ := time.LoadLocation("Local")
|
|
paymentAt, _ := time.ParseInLocation("20060102150405", rchg.DateTime, loc)
|
|
if err = rechargeser.RechargeCallBack(ctx, rchg.OID, payMoney, rchg.TradeNo, status, paymentAt); err != nil {
|
|
log.Error(fmt.Sprintf("DXZhiFu RechargeCallBack fail error:%+v:", err))
|
|
}
|
|
return err
|
|
}(); err != nil {
|
|
ctx.String(http.StatusBadRequest, "fail")
|
|
return
|
|
}
|
|
ctx.String(http.StatusOK, "OK")
|
|
}
|