42 lines
1019 B
Go
42 lines
1019 B
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/go-kratos/kratos/v2/log"
|
|
"github.com/go-kratos/kratos/v2/transport/http"
|
|
"io"
|
|
"voucher/internal/biz"
|
|
"voucher/internal/biz/bo"
|
|
"voucher/internal/pkg/helper"
|
|
)
|
|
|
|
type TripartiteService struct {
|
|
multiBiz *biz.MultiBiz
|
|
}
|
|
|
|
func NewTripartiteService(multiBiz *biz.MultiBiz) *TripartiteService {
|
|
return &TripartiteService{multiBiz: multiBiz}
|
|
}
|
|
|
|
func (srv *TripartiteService) QiXingNotify(ctx http.Context) error {
|
|
|
|
ip := helper.GetClientIP(ctx)
|
|
if ip == "" {
|
|
return fmt.Errorf("获取请求 IP 失败")
|
|
}
|
|
|
|
bodyBytes, err := io.ReadAll(ctx.Request().Body)
|
|
if err != nil {
|
|
return fmt.Errorf("read body error: %v", err)
|
|
}
|
|
|
|
var req *bo.WechatVoucherNotifyBo
|
|
if err = json.Unmarshal(bodyBytes, &req); err != nil {
|
|
log.Errorf("qixing notify ip:%s,error:%v,body:%s", ip, err, string(bodyBytes))
|
|
return fmt.Errorf("json unmarshal bodyBytes error: %v", err)
|
|
}
|
|
|
|
return srv.multiBiz.Notify(ctx, ip, "qixing_"+req.PlainText.StockCreatorMchid, req)
|
|
}
|