add 查询回调地址接口
This commit is contained in:
parent
514e7bb724
commit
8d294ef297
|
|
@ -154,4 +154,12 @@ message EncryptBody {
|
||||||
}
|
}
|
||||||
message DecryptBody {
|
message DecryptBody {
|
||||||
string decryptBody = 1 [json_name = "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"];
|
||||||
}
|
}
|
||||||
|
|
@ -11,5 +11,6 @@ type WechatCpnRepo interface {
|
||||||
Order(ctx context.Context, order *bo.OrderBo) (couponId string, err error)
|
Order(ctx context.Context, order *bo.OrderBo) (couponId string, err error)
|
||||||
Query(ctx context.Context, order *bo.OrderBo) (vo.OrderStatus, error)
|
Query(ctx context.Context, order *bo.OrderBo) (vo.OrderStatus, error)
|
||||||
QueryProduct(ctx context.Context, stockCreatorMchId, stockId string) (*cashcoupons.Stock, 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
|
RegisterNotifyTag(ctx context.Context, stockID string) error
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -147,13 +147,47 @@ func (c *CpnRepoImpl) QueryProduct(ctx context.Context, stockCreatorMchId, stock
|
||||||
}
|
}
|
||||||
|
|
||||||
if result.Response.StatusCode != CodeSuccess {
|
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 nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
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 {
|
func (c *CpnRepoImpl) Notify(ctx context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ func NewHTTPServer(
|
||||||
v1.POST("/product/query", voucherService.CmbProductQuery)
|
v1.POST("/product/query", voucherService.CmbProductQuery)
|
||||||
|
|
||||||
v1.POST("/decryptBody", voucherService.DecryptBody)
|
v1.POST("/decryptBody", voucherService.DecryptBody)
|
||||||
|
v1.POST("/queryWechatVoucherNotifyUrl", voucherService.QueryWechatVoucherNotifyUrl)
|
||||||
|
|
||||||
return srv
|
return srv
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,3 +104,25 @@ func (s *VoucherService) DecryptBody(ctx http.Context) error {
|
||||||
DecryptBody: decryptBody,
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,23 +3,27 @@ package service
|
||||||
import (
|
import (
|
||||||
"voucher/internal/biz"
|
"voucher/internal/biz"
|
||||||
"voucher/internal/biz/mixrepos"
|
"voucher/internal/biz/mixrepos"
|
||||||
|
"voucher/internal/biz/wechatrepo"
|
||||||
"voucher/internal/conf"
|
"voucher/internal/conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VoucherService struct {
|
type VoucherService struct {
|
||||||
bc *conf.Bootstrap
|
bc *conf.Bootstrap
|
||||||
VoucherBiz *biz.VoucherBiz
|
VoucherBiz *biz.VoucherBiz
|
||||||
CmbMixRepo mixrepos.CmbMixRepo
|
CmbMixRepo mixrepos.CmbMixRepo
|
||||||
|
WechatCpnRepo wechatrepo.WechatCpnRepo
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVoucherService(
|
func NewVoucherService(
|
||||||
bc *conf.Bootstrap,
|
bc *conf.Bootstrap,
|
||||||
VoucherBiz *biz.VoucherBiz,
|
VoucherBiz *biz.VoucherBiz,
|
||||||
CmbMixRepo mixrepos.CmbMixRepo,
|
CmbMixRepo mixrepos.CmbMixRepo,
|
||||||
|
WechatCpnRepo wechatrepo.WechatCpnRepo,
|
||||||
) *VoucherService {
|
) *VoucherService {
|
||||||
return &VoucherService{
|
return &VoucherService{
|
||||||
bc: bc,
|
bc: bc,
|
||||||
VoucherBiz: VoucherBiz,
|
VoucherBiz: VoucherBiz,
|
||||||
CmbMixRepo: CmbMixRepo,
|
CmbMixRepo: CmbMixRepo,
|
||||||
|
WechatCpnRepo: WechatCpnRepo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue