启用微信支付逻辑;调整支付金额处理方式以支持调试模式
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
## todo
|
||||
|
||||
- 长效业务接入
|
||||
- 微信支付
|
||||
- 页面 账户总览
|
||||
- 页面 提取记录
|
||||
- 页面 使用记录
|
||||
@@ -9,6 +8,7 @@
|
||||
|
||||
- globals 合并到 services 或者反之
|
||||
- 自定义的服务错误没有必要,可以统一在 handler 层使用包装的 fiber.Error
|
||||
- 公众号的到期提示
|
||||
|
||||
### 下阶段
|
||||
|
||||
|
||||
2
pkg/env/env.go
vendored
2
pkg/env/env.go
vendored
@@ -406,6 +406,6 @@ func Init() {
|
||||
loadDebug()
|
||||
loadRemote()
|
||||
loadAlipay()
|
||||
// loadWechatPay()
|
||||
loadWechatPay()
|
||||
loadAliyun()
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@ type WechatPayClient struct {
|
||||
func InitWechatPay() {
|
||||
|
||||
// 加载 rsa 密钥文件
|
||||
appPrivateKey, err := utils.LoadPrivateKey(env.WechatPayMchPrivateKeyPath)
|
||||
appPrivateKey, err := utils.LoadPrivateKeyWithPath(env.WechatPayMchPrivateKeyPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
wechatPublicKey, err := utils.LoadPublicKey(env.WechatPayPublicKeyPath)
|
||||
wechatPublicKey, err := utils.LoadPublicKeyWithPath(env.WechatPayPublicKeyPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -281,6 +281,7 @@ func RechargeConfirmWechat(c *fiber.Ctx) error {
|
||||
// 验证支付结果
|
||||
result, err := s.Transaction.VerifyTransaction(c.Context(), &s.TransactionVerifyData{
|
||||
TradeNo: req.TradeNo,
|
||||
Method: s.TransactionMethodWeChat,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -49,7 +49,7 @@ type ResourceInfo struct {
|
||||
// region RemoveChannel
|
||||
|
||||
func (s *channelService) RemoveChannels(ctx context.Context, authCtx *auth.Context, id ...int32) error {
|
||||
var step = time.Now()
|
||||
var now = time.Now()
|
||||
var rid = ctx.Value(requestid.ConfigDefault.ContextKey).(string)
|
||||
|
||||
err := q.Q.Transaction(func(tx *q.Query) error {
|
||||
@@ -62,8 +62,6 @@ func (s *channelService) RemoveChannels(ctx context.Context, authCtx *auth.Conte
|
||||
return err
|
||||
}
|
||||
|
||||
slog.Debug("查找通道", "rid", rid, "step", time.Since(step))
|
||||
|
||||
// 检查权限,如果为用户操作的话,则只能删除自己的通道
|
||||
for _, channel := range channels {
|
||||
if authCtx.Payload.Type == auth.PayloadUser && authCtx.Payload.Id != channel.UserID {
|
||||
@@ -72,8 +70,6 @@ func (s *channelService) RemoveChannels(ctx context.Context, authCtx *auth.Conte
|
||||
}
|
||||
|
||||
// 查找代理
|
||||
step = time.Now()
|
||||
|
||||
proxySet := make(map[int32]struct{})
|
||||
proxyIds := make([]int32, 0)
|
||||
for _, channel := range channels {
|
||||
@@ -89,12 +85,10 @@ func (s *channelService) RemoveChannels(ctx context.Context, authCtx *auth.Conte
|
||||
return err
|
||||
}
|
||||
|
||||
slog.Debug("查找代理", "rid", rid, "step", time.Since(step))
|
||||
|
||||
// 删除指定的通道
|
||||
result, err := tx.Channel.
|
||||
result, err := tx.Channel.Debug().
|
||||
Where(q.Channel.ID.In(id...)).
|
||||
Update(q.Channel.DeletedAt, time.Now())
|
||||
Update(q.Channel.DeletedAt, now)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -102,19 +96,15 @@ func (s *channelService) RemoveChannels(ctx context.Context, authCtx *auth.Conte
|
||||
return ChannelServiceErr("删除通道失败")
|
||||
}
|
||||
|
||||
// 删除缓存,异步任务直接在消费端处理删除
|
||||
step = time.Now()
|
||||
|
||||
// 删除缓存
|
||||
err = deleteCache(ctx, channels)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
slog.Debug("删除缓存", "rid", rid, "step", time.Since(step))
|
||||
|
||||
// 禁用代理端口并下线用过的节点
|
||||
if env.DebugExternalChange {
|
||||
step = time.Now()
|
||||
var step = time.Now()
|
||||
|
||||
// 组织数据
|
||||
var configMap = make(map[int32][]g.PortConfigsReq, len(proxies))
|
||||
|
||||
@@ -31,6 +31,14 @@ func (s *transactionService) PrepareTransaction(ctx context.Context, q *q.Query,
|
||||
var tType = data.Type
|
||||
var method = data.Method
|
||||
var amount = data.Amount
|
||||
|
||||
// 实际支付金额,只在创建真实订单时使用
|
||||
var amountReal = data.Amount
|
||||
if env.RunMode == "debug" {
|
||||
amountReal = 0.01
|
||||
}
|
||||
|
||||
// 附加优惠券
|
||||
if data.CouponCode != "" {
|
||||
coupon, err := q.Coupon.WithContext(ctx).
|
||||
Where(
|
||||
@@ -101,7 +109,7 @@ func (s *transactionService) PrepareTransaction(ctx context.Context, q *q.Query,
|
||||
ProductCode: "FAST_INSTANT_TRADE_PAY",
|
||||
OutTradeNo: tradeNo,
|
||||
Subject: subject,
|
||||
TotalAmount: strconv.FormatFloat(amount, 'f', 2, 64),
|
||||
TotalAmount: strconv.FormatFloat(amountReal, 'f', 2, 64),
|
||||
TimeExpire: expire.Format("2006-01-02 15:04:05"),
|
||||
},
|
||||
})
|
||||
@@ -120,7 +128,7 @@ func (s *transactionService) PrepareTransaction(ctx context.Context, q *q.Query,
|
||||
TimeExpire: &expire,
|
||||
NotifyUrl: &env.WechatPayCallbackUrl,
|
||||
Amount: &native.Amount{
|
||||
Total: u.P(int64(amount * 100)),
|
||||
Total: u.P(int64(amountReal * 100)),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -152,7 +160,6 @@ func (s *transactionService) PrepareTransaction(ctx context.Context, q *q.Query,
|
||||
Method: int32(method),
|
||||
Type: int32(tradeType),
|
||||
Amount: amount,
|
||||
Status: 0, // 0-待支付
|
||||
PayURL: payUrl,
|
||||
}
|
||||
err = q.Trade.Create(&trade)
|
||||
|
||||
@@ -47,7 +47,7 @@ func (s *Server) Run() error {
|
||||
// inits
|
||||
g.InitBaiyin()
|
||||
g.InitAlipay()
|
||||
// g.InitWechatPay()
|
||||
g.InitWechatPay()
|
||||
g.InitAliyun()
|
||||
g.InitValidator()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user