add 查询回调地址接口

This commit is contained in:
李子铭 2025-03-13 15:20:00 +08:00
parent 514e7bb724
commit 8d294ef297
6 changed files with 77 additions and 7 deletions

View File

@ -155,3 +155,11 @@ message EncryptBody {
message DecryptBody {
string decryptBody = 1 [json_name = "decryptBody"];
}
message QueryWechatVoucherNotifyUrlRequest {
string mch_id = 1 [json_name = "mch_id"];
}
message QueryWechatVoucherNotifyUrlReply {
string url = 1 [json_name = "url"];
}

View File

@ -11,5 +11,6 @@ type WechatCpnRepo interface {
Order(ctx context.Context, order *bo.OrderBo) (couponId string, err error)
Query(ctx context.Context, order *bo.OrderBo) (vo.OrderStatus, error)
QueryProduct(ctx context.Context, stockCreatorMchId, stockId string) (*cashcoupons.Stock, error)
QueryCallback(ctx context.Context, mchId string) (*cashcoupons.Callback, error)
RegisterNotifyTag(ctx context.Context, stockID string) error
}

View File

@ -147,13 +147,47 @@ func (c *CpnRepoImpl) QueryProduct(ctx context.Context, stockCreatorMchId, stock
}
if result.Response.StatusCode != CodeSuccess {
err = fmt.Errorf("查询活动微信返回错误StatusCode[%d]Status[%s]", result.Response.StatusCode, result.Response.Status)
err = fmt.Errorf("查询活动微信返回错误tatus[%s]", result.Response.Status)
return nil, err
}
return response, nil
}
func (c *CpnRepoImpl) QueryCallback(ctx context.Context, mchId string) (*cashcoupons.Callback, error) {
client, err := data.GetClient(ctx, c.Server)
if err != nil {
return nil, err
}
svc := cashcoupons.CallBackUrlApiService{Client: client}
response, result, err := svc.QueryCallback(ctx, cashcoupons.QueryCallbackRequest{
Mchid: core.String(mchId),
})
if err != nil {
bodyBytes, err := io.ReadAll(result.Response.Body)
if err != nil {
return nil, err
}
if err = json.Unmarshal(bodyBytes, &ErrBody); err != nil {
return nil, err
}
return nil, fmt.Errorf("微信返回错误:%s", ErrBody.Message)
}
if result.Response.StatusCode != CodeSuccess {
return nil, fmt.Errorf("微信返回错误tatus[%s]", result.Response.Status)
}
return response, nil
}
func (c *CpnRepoImpl) Notify(ctx context.Context) error {
return nil
}

View File

@ -48,6 +48,7 @@ func NewHTTPServer(
v1.POST("/product/query", voucherService.CmbProductQuery)
v1.POST("/decryptBody", voucherService.DecryptBody)
v1.POST("/queryWechatVoucherNotifyUrl", voucherService.QueryWechatVoucherNotifyUrl)
return srv
}

View File

@ -104,3 +104,25 @@ func (s *VoucherService) DecryptBody(ctx http.Context) error {
DecryptBody: decryptBody,
})
}
func (s *VoucherService) QueryWechatVoucherNotifyUrl(ctx http.Context) error {
bodyBytes, err := io.ReadAll(ctx.Request().Body)
if err != nil {
return err
}
var req *v1.QueryWechatVoucherNotifyUrlRequest
if err = json.Unmarshal(bodyBytes, &req); err != nil {
return err
}
rep, err := s.VoucherBiz.WechatCpnRepo.QueryCallback(ctx, req.MchId)
if err != nil {
return err
}
return ctx.JSON(200, &v1.QueryWechatVoucherNotifyUrlReply{
Url: *rep.NotifyUrl,
})
}

View File

@ -3,23 +3,27 @@ package service
import (
"voucher/internal/biz"
"voucher/internal/biz/mixrepos"
"voucher/internal/biz/wechatrepo"
"voucher/internal/conf"
)
type VoucherService struct {
bc *conf.Bootstrap
VoucherBiz *biz.VoucherBiz
CmbMixRepo mixrepos.CmbMixRepo
bc *conf.Bootstrap
VoucherBiz *biz.VoucherBiz
CmbMixRepo mixrepos.CmbMixRepo
WechatCpnRepo wechatrepo.WechatCpnRepo
}
func NewVoucherService(
bc *conf.Bootstrap,
VoucherBiz *biz.VoucherBiz,
CmbMixRepo mixrepos.CmbMixRepo,
WechatCpnRepo wechatrepo.WechatCpnRepo,
) *VoucherService {
return &VoucherService{
bc: bc,
VoucherBiz: VoucherBiz,
CmbMixRepo: CmbMixRepo,
bc: bc,
VoucherBiz: VoucherBiz,
CmbMixRepo: CmbMixRepo,
WechatCpnRepo: WechatCpnRepo,
}
}