错误提示调整
This commit is contained in:
parent
a889c05bbd
commit
2ecb127e84
|
@ -3,7 +3,7 @@ package main
|
||||||
// main 这只是一个演示
|
// main 这只是一个演示
|
||||||
func main() {
|
func main() {
|
||||||
//alipayOrderRedPack()
|
//alipayOrderRedPack()
|
||||||
//wechatRedPackOrder()
|
wechatRedPackOrder()
|
||||||
wechatRedPackQuery()
|
//wechatRedPackQuery()
|
||||||
//alipayNotifyRedPack()
|
//alipayNotifyRedPack()
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ func wechatRedPackOrder() {
|
||||||
Account: "oZ5ge5Vb2UvbEcIc8ZTt_yF7fNx8",
|
Account: "oZ5ge5Vb2UvbEcIc8ZTt_yF7fNx8",
|
||||||
Amount: 0.01,
|
Amount: 0.01,
|
||||||
Quantity: 1,
|
Quantity: 1,
|
||||||
Extra: []byte(`{"app_id":"wxbfcf9fd93f390c3a", "out_detail_no":"12345678917"}`),
|
Extra: []byte(`{"app_id":"123456", "out_detail_no":"12345678917"}`),
|
||||||
},
|
},
|
||||||
Product: &proto.OrderRequest_Product{
|
Product: &proto.OrderRequest_Product{
|
||||||
ProductNo: "",
|
ProductNo: "",
|
||||||
|
@ -68,10 +68,10 @@ func wechatRedPackQuery() {
|
||||||
queryRequest := &proto.QueryRequest{
|
queryRequest := &proto.QueryRequest{
|
||||||
Config: getWechatRedPackConf(),
|
Config: getWechatRedPackConf(),
|
||||||
Order: &proto.QueryRequest_Order{
|
Order: &proto.QueryRequest_Order{
|
||||||
OrderNo: "202410181543202661520132",
|
OrderNo: "202410231046525199060462",
|
||||||
TradeNo: "",
|
TradeNo: "",
|
||||||
Account: "",
|
Account: "",
|
||||||
Extra: []byte(`{"out_detail_no":"20241018154320266152013216702243"}`),
|
Extra: []byte(`{"out_detail_no":"20241023104652519906046250731390"}`),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
resQuery, err := instance.Query(context.Background(), wechatRedPackConf.Tag, queryRequest)
|
resQuery, err := instance.Query(context.Background(), wechatRedPackConf.Tag, queryRequest)
|
||||||
|
|
|
@ -2,8 +2,10 @@ package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||||
"plugins/wechat_cpn/internal/vo"
|
"plugins/wechat_cpn/internal/vo"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 插件通信信息,若不对应则会报错panic
|
// 插件通信信息,若不对应则会报错panic
|
||||||
|
@ -31,10 +33,10 @@ func (p *WeChatCpnService) Order(ctx context.Context, request *proto.OrderReques
|
||||||
}
|
}
|
||||||
resp, result, err := svc.SendCoupon(ctx, req)
|
resp, result, err := svc.SendCoupon(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, p.err(ctx, err)
|
||||||
}
|
}
|
||||||
if result.Response.StatusCode != vo.CodeSuccess.Value() {
|
if result.Response.StatusCode != vo.CodeSuccess.Value() {
|
||||||
return nil, err
|
return nil, fmt.Errorf("微信返回错误 Response StatusCode[%d]Status[%s]", result.Response.StatusCode, result.Response.Status)
|
||||||
}
|
}
|
||||||
return orderResp(request.GetOrder(), *resp.CouponId), nil
|
return orderResp(request.GetOrder(), *resp.CouponId), nil
|
||||||
}
|
}
|
||||||
|
@ -51,10 +53,10 @@ func (p *WeChatCpnService) Query(ctx context.Context, request *proto.QueryReques
|
||||||
}
|
}
|
||||||
resp, result, err := svc.QueryCoupon(ctx, *req)
|
resp, result, err := svc.QueryCoupon(ctx, *req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, p.err(ctx, err)
|
||||||
}
|
}
|
||||||
if result.Response.StatusCode != vo.CodeSuccess.Value() {
|
if result.Response.StatusCode != vo.CodeSuccess.Value() {
|
||||||
return nil, err
|
return nil, fmt.Errorf("微信返回错误 Response StatusCode[%d]Status[%s]", result.Response.StatusCode, result.Response.Status)
|
||||||
}
|
}
|
||||||
return queryResp(request, resp), nil
|
return queryResp(request, resp), nil
|
||||||
}
|
}
|
||||||
|
@ -69,3 +71,16 @@ func (p *WeChatCpnService) Notify(ctx context.Context, request *proto.NotifyRequ
|
||||||
}
|
}
|
||||||
return notifyResp(), nil
|
return notifyResp(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *WeChatCpnService) err(_ context.Context, err error) error {
|
||||||
|
errStr := err.Error()
|
||||||
|
startIndex := strings.Index(errStr, "Message: ")
|
||||||
|
if startIndex == -1 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
endIndex := strings.Index(errStr[startIndex:], "\n")
|
||||||
|
if endIndex == -1 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return fmt.Errorf(errStr[startIndex+len("Message: ") : startIndex+endIndex])
|
||||||
|
}
|
||||||
|
|
|
@ -2,9 +2,10 @@ package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||||
"plugins/wechat_redpack/internal/vo"
|
"plugins/wechat_redpack/internal/vo"
|
||||||
"time"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 插件通信信息,若不对应则会报错panic
|
// 插件通信信息,若不对应则会报错panic
|
||||||
|
@ -19,7 +20,6 @@ const (
|
||||||
type WeChatRedPackService struct{}
|
type WeChatRedPackService struct{}
|
||||||
|
|
||||||
func (p *WeChatRedPackService) Order(ctx context.Context, request *proto.OrderRequest) (*proto.OrderResponse, error) {
|
func (p *WeChatRedPackService) Order(ctx context.Context, request *proto.OrderRequest) (*proto.OrderResponse, error) {
|
||||||
ctx, _ = context.WithTimeout(ctx, 30*time.Second)
|
|
||||||
config, err := transConfig(request.Config)
|
config, err := transConfig(request.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -34,16 +34,15 @@ func (p *WeChatRedPackService) Order(ctx context.Context, request *proto.OrderRe
|
||||||
}
|
}
|
||||||
resp, result, err := svc.InitiateBatchTransfer(ctx, req)
|
resp, result, err := svc.InitiateBatchTransfer(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, p.err(ctx, err)
|
||||||
}
|
}
|
||||||
if result.Response.StatusCode != vo.CodeSuccess.Value() {
|
if result.Response.StatusCode != vo.CodeSuccess.Value() {
|
||||||
return nil, err
|
return nil, fmt.Errorf("微信返回错误 Response StatusCode[%d]Status[%s]", result.Response.StatusCode, result.Response.Status)
|
||||||
}
|
}
|
||||||
return orderResp(request.GetOrder(), *resp.BatchId), nil
|
return orderResp(request.GetOrder(), *resp.BatchId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *WeChatRedPackService) Query(ctx context.Context, request *proto.QueryRequest) (*proto.QueryResponse, error) {
|
func (p *WeChatRedPackService) Query(ctx context.Context, request *proto.QueryRequest) (*proto.QueryResponse, error) {
|
||||||
ctx, _ = context.WithTimeout(ctx, 30*time.Second)
|
|
||||||
req, err := queryReq(request.GetOrder())
|
req, err := queryReq(request.GetOrder())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -58,10 +57,10 @@ func (p *WeChatRedPackService) Query(ctx context.Context, request *proto.QueryRe
|
||||||
}
|
}
|
||||||
resp, result, err := svc.GetTransferDetailByOutNo(ctx, *req)
|
resp, result, err := svc.GetTransferDetailByOutNo(ctx, *req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, p.err(ctx, err)
|
||||||
}
|
}
|
||||||
if result.Response.StatusCode != vo.CodeSuccess.Value() {
|
if result.Response.StatusCode != vo.CodeSuccess.Value() {
|
||||||
return nil, err
|
return nil, fmt.Errorf("微信返回错误 Response StatusCode[%d]Status[%s]", result.Response.StatusCode, result.Response.Status)
|
||||||
}
|
}
|
||||||
return queryResp(request, resp), nil
|
return queryResp(request, resp), nil
|
||||||
}
|
}
|
||||||
|
@ -69,3 +68,16 @@ func (p *WeChatRedPackService) Query(ctx context.Context, request *proto.QueryRe
|
||||||
func (p *WeChatRedPackService) Notify(_ context.Context, _ *proto.NotifyRequest) (*proto.NotifyResponse, error) {
|
func (p *WeChatRedPackService) Notify(_ context.Context, _ *proto.NotifyRequest) (*proto.NotifyResponse, error) {
|
||||||
return notifyResp(), nil
|
return notifyResp(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *WeChatRedPackService) err(_ context.Context, err error) error {
|
||||||
|
errStr := err.Error()
|
||||||
|
startIndex := strings.Index(errStr, "Message: ")
|
||||||
|
if startIndex == -1 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
endIndex := strings.Index(errStr[startIndex:], "\n")
|
||||||
|
if endIndex == -1 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return fmt.Errorf(errStr[startIndex+len("Message: ") : startIndex+endIndex])
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue