feat: 迁移plant
This commit is contained in:
@@ -5,6 +5,9 @@ package callback
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
@@ -25,8 +28,52 @@ func NewWechatPayCallbackLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *WechatPayCallbackLogic) WechatPayCallback() error {
|
||||
// todo: add your logic here and delete this line
|
||||
// wechatNotify 微信支付回调通知结构
|
||||
type wechatNotify struct {
|
||||
Id string `json:"id"`
|
||||
EventType string `json:"event_type"`
|
||||
Summary string `json:"summary"`
|
||||
ResourceType string `json:"resource_type"`
|
||||
Resource struct {
|
||||
Algorithm string `json:"algorithm"`
|
||||
Ciphertext string `json:"ciphertext"`
|
||||
AssociatedData string `json:"associated_data"`
|
||||
Nonce string `json:"nonce"`
|
||||
} `json:"resource"`
|
||||
}
|
||||
|
||||
// WechatPayCallback 微信支付回调处理
|
||||
// TODO: 接入 wechatpay-go SDK 完成验签 + 解密 + 订单状态更新
|
||||
//
|
||||
// 完整接入步骤:
|
||||
// 1. go get github.com/wechatpay-apiv3/wechatpay-go
|
||||
// 2. 在 config 中添加 WechatPay{ MchId, MchAPIv3Key, PrivateKeyPath, PublicKeyId, PublicKeyPath }
|
||||
// 3. 使用 notify.NewRSANotifyHandler 验签解密
|
||||
// 4. 解析 payments.Transaction 后根据 TradeState == "SUCCESS" 更新 sundynix_exchange_order 状态
|
||||
func (l *WechatPayCallbackLogic) WechatPayCallback(r *http.Request) error {
|
||||
// 1. 读取请求体
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
l.Logger.Errorf("[微信支付回调] 读取请求体失败: %v", err)
|
||||
return err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
|
||||
// 2. 解析通知基本结构(不验签,记录日志)
|
||||
var notify wechatNotify
|
||||
if err = json.Unmarshal(body, ¬ify); err != nil {
|
||||
l.Logger.Errorf("[微信支付回调] 解析通知失败: %v, body: %s", err, string(body))
|
||||
return err
|
||||
}
|
||||
|
||||
l.Logger.Infof("[微信支付回调] 收到通知 id=%s, event=%s, summary=%s",
|
||||
notify.Id, notify.EventType, notify.Summary)
|
||||
|
||||
// TODO: 完成验签 + 解密 + 业务处理
|
||||
// if notify.EventType == "TRANSACTION.SUCCESS" {
|
||||
// transaction := decrypt(notify.Resource, mchAPIv3Key)
|
||||
// updateOrderStatus(transaction.OutTradeNo, "SUCCESS")
|
||||
// }
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user