68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package internal
|
|
|
|
import (
|
|
"context"
|
|
"gitea.cdlsxd.cn/BaseSystem/plugin/proto"
|
|
"plugins/weixin_redpack/internal/vo"
|
|
)
|
|
|
|
// 插件通信信息,若不对应则会报错panic
|
|
const (
|
|
Tag = "weixin_redpack"
|
|
Version = 1
|
|
CookieKey = "weixin_redpack"
|
|
CookieValue = "weixin_redpack"
|
|
)
|
|
|
|
type WeiXinRedPackService struct{}
|
|
|
|
func (p *WeiXinRedPackService) Order(ctx context.Context, request *proto.OrderRequest) (*proto.OrderResponse, error) {
|
|
config, err := transConfig(request.Config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
req, err := orderReq(request.GetOrder(), request.GetProduct())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
svc, err := transferBatchApiService(ctx, config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
resp, result, err := svc.InitiateBatchTransfer(ctx, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if result.Response.StatusCode != vo.CodeSuccess.Value() {
|
|
return nil, err
|
|
}
|
|
return orderResp(request.GetOrder(), *resp.BatchId), nil
|
|
}
|
|
|
|
func (p *WeiXinRedPackService) Query(ctx context.Context, request *proto.QueryRequest) (*proto.QueryResponse, error) {
|
|
req, err := queryReq(request.GetOrder())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
config, err := transConfig(request.Config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
svc, err := transferDetailApiService(ctx, config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
resp, result, err := svc.GetTransferDetailByNo(ctx, *req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if result.Response.StatusCode != vo.CodeSuccess.Value() {
|
|
return nil, err
|
|
}
|
|
return queryResp(request, resp), nil
|
|
}
|
|
|
|
func (p *WeiXinRedPackService) Notify(_ context.Context, _ *proto.NotifyRequest) (*proto.NotifyResponse, error) {
|
|
return notifyResp(), nil
|
|
}
|