38 lines
		
	
	
		
			837 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			837 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package pay
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"net/http"
 | |
| 
 | |
| 	"tyc-server/app/main/api/internal/svc"
 | |
| 
 | |
| 	"github.com/zeromicro/go-zero/core/logx"
 | |
| )
 | |
| 
 | |
| type WechatPayCallbackLogic struct {
 | |
| 	logx.Logger
 | |
| 	ctx    context.Context
 | |
| 	svcCtx *svc.ServiceContext
 | |
| }
 | |
| 
 | |
| func NewWechatPayCallbackLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WechatPayCallbackLogic {
 | |
| 	return &WechatPayCallbackLogic{
 | |
| 		Logger: logx.WithContext(ctx),
 | |
| 		ctx:    ctx,
 | |
| 		svcCtx: svcCtx,
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func (l *WechatPayCallbackLogic) WechatPayCallback(w http.ResponseWriter, r *http.Request) error {
 | |
| 	err := l.svcCtx.PayService.HandlePaymentCallback(l.ctx, "wechat", r)
 | |
| 	if err != nil {
 | |
| 		logx.Errorf("微信支付回调,%+v", err)
 | |
| 		return nil
 | |
| 	}
 | |
| 
 | |
| 	// 响应微信回调成功
 | |
| 	w.WriteHeader(http.StatusOK)
 | |
| 	_, _ = w.Write([]byte("success")) // 确保只写入一次响应
 | |
| 	return nil
 | |
| }
 |