错误信息乱码处理
This commit is contained in:
parent
8eb97590d5
commit
4bd9c4185b
|
@ -63,10 +63,10 @@ func wechatRedPackQuery() {
|
|||
queryRequest := &proto.QueryRequest{
|
||||
Config: getWechatRedPackConf(),
|
||||
Order: &proto.QueryRequest_Order{
|
||||
OrderNo: "240403164049635931",
|
||||
OrderNo: "202409141056275034200011",
|
||||
TradeNo: "",
|
||||
Account: "",
|
||||
Extra: []byte(`{"out_detail_no":"123456789"}`),
|
||||
Extra: []byte(`{"out_detail_no":"0a2511525cc94a27bac18328771dc53e"}`),
|
||||
},
|
||||
}
|
||||
resQuery, err := instance.Query(context.Background(), wechatRedPackConf.Tag, queryRequest)
|
||||
|
|
|
@ -46,7 +46,7 @@ func (s *AlipayCpnService) Order(ctx context.Context, request *proto.OrderReques
|
|||
}
|
||||
|
||||
var sp string
|
||||
err = requests.URL(c.BaseUri).Post().BodyForm(uv).ToString(&sp).Fetch(ctx)
|
||||
err = requests.URL(baseUri).Post().BodyForm(uv).ToString(&sp).Fetch(ctx)
|
||||
|
||||
var response *po.OrderResp
|
||||
sp = utils.ToChinese(sp)
|
||||
|
@ -76,7 +76,7 @@ func (s *AlipayCpnService) Query(ctx context.Context, request *proto.QueryReques
|
|||
}
|
||||
|
||||
var sp string
|
||||
err = requests.URL(c.BaseUri).Post().BodyForm(uv).ToString(&sp).Fetch(ctx)
|
||||
err = requests.URL(baseUri).Post().BodyForm(uv).ToString(&sp).Fetch(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||
}
|
||||
|
|
|
@ -69,7 +69,8 @@ func TestQuery(t *testing.T) {
|
|||
t.Errorf("Query() error = %v", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("%+v \n", got)
|
||||
fmt.Printf("request:%s \n", request.String())
|
||||
fmt.Printf("response:%s \n", got.String())
|
||||
assert.Equal(t, int(proto.Status_SUCCESS), int(got.Result.Status))
|
||||
})
|
||||
}
|
||||
|
|
|
@ -11,10 +11,9 @@ import (
|
|||
)
|
||||
|
||||
type Config struct {
|
||||
AppId string `json:"app_id"`
|
||||
BaseUri string `json:"base_uri"`
|
||||
Prk string `json:"prk"` // 私钥
|
||||
Npk string `json:"npk"` // 回调公钥
|
||||
AppId string `json:"app_id"`
|
||||
Prk string `json:"prk"` // 私钥
|
||||
Npk string `json:"npk"` // 回调公钥
|
||||
}
|
||||
|
||||
func transConfig(config []byte) (*Config, error) {
|
||||
|
@ -23,9 +22,6 @@ func transConfig(config []byte) (*Config, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if c.BaseUri == "" {
|
||||
c.BaseUri = baseUri
|
||||
}
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
|
@ -55,7 +51,7 @@ func orderReq(order *proto.OrderRequest_Order, product *proto.OrderRequest_Produ
|
|||
if order.Extra != nil {
|
||||
err := json.Unmarshal(order.Extra, &extra)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("order extra json unmarshal error: %v", err)
|
||||
return nil, fmt.Errorf("order拓展参数 json unmarshal error: %v", err)
|
||||
}
|
||||
}
|
||||
o := &po.OrderReq{
|
||||
|
@ -91,7 +87,7 @@ func queryReq(in *proto.QueryRequest_Order) (*po.QueryReq, error) {
|
|||
if in.Extra != nil {
|
||||
err := json.Unmarshal(in.Extra, &extra)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("order extra json unmarshal error: %v", err)
|
||||
return nil, fmt.Errorf("order拓展参数 json unmarshal error: %v", err)
|
||||
}
|
||||
}
|
||||
return &po.QueryReq{
|
||||
|
|
|
@ -54,11 +54,11 @@ func orderReq(order *proto.OrderRequest_Order, product *proto.OrderRequest_Produ
|
|||
}
|
||||
var productExtra ProductExtra
|
||||
if product.Extra == nil {
|
||||
return nil, fmt.Errorf("product extra is nil")
|
||||
return nil, fmt.Errorf("商品拓展参数不能为空")
|
||||
}
|
||||
err := json.Unmarshal(product.Extra, &productExtra)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("product extra json unmarshal error: %v", err)
|
||||
return nil, fmt.Errorf("商品拓展参数 json unmarshal error: %v", err)
|
||||
}
|
||||
payeeInfo := po.PayeeInfo{
|
||||
Identity: order.Account,
|
||||
|
@ -74,7 +74,7 @@ func orderReq(order *proto.OrderRequest_Order, product *proto.OrderRequest_Produ
|
|||
var orderExtra OrderExtra
|
||||
err = json.Unmarshal(order.Extra, &orderExtra)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("order extra json unmarshal error: %v", err)
|
||||
return nil, fmt.Errorf("订单拓展参数 json unmarshal error: %v", err)
|
||||
}
|
||||
if orderExtra.Name == "" {
|
||||
return nil, fmt.Errorf("姓名,当identity_type=ALIPAY_LOGON_ID时,本字段必填")
|
||||
|
|
|
@ -2,6 +2,7 @@ package internal
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||
"plugins/union_pay_cpn/internal/po"
|
||||
"plugins/union_pay_cpn/internal/vo"
|
||||
|
@ -32,7 +33,10 @@ func (c *Config) orderReq(in *proto.OrderRequest) (*po.OrderReq, error) {
|
|||
OrderDt string `json:"orderDt"`
|
||||
}
|
||||
var e OrderExtra
|
||||
_ = json.Unmarshal(in.Order.Extra, &e)
|
||||
err := json.Unmarshal(in.Order.Extra, &e)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("订单拓展参数 json unmarshal error: %v", err)
|
||||
}
|
||||
|
||||
mobile, err := union_pay.Encrypt([]byte(in.Order.Account), []byte(c.KEY), []byte(c.IV))
|
||||
if err != nil {
|
||||
|
|
|
@ -29,7 +29,7 @@ func orderReq(order *proto.OrderRequest_Order, product *proto.OrderRequest_Produ
|
|||
if order.Extra != nil {
|
||||
err := json.Unmarshal(order.Extra, &extra)
|
||||
if err != nil {
|
||||
return cashcoupons.SendCouponRequest{}, fmt.Errorf("order extra json unmarshal error: %v", err)
|
||||
return cashcoupons.SendCouponRequest{}, fmt.Errorf("order拓展参数 json unmarshal error: %v", err)
|
||||
}
|
||||
}
|
||||
return cashcoupons.SendCouponRequest{
|
||||
|
@ -62,7 +62,7 @@ func queryReq(order *proto.QueryRequest_Order) (*cashcoupons.QueryCouponRequest,
|
|||
if order.Extra != nil {
|
||||
err := json.Unmarshal(order.Extra, &extra)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("order extra json unmarshal error: %v", err)
|
||||
return nil, fmt.Errorf("order拓展参数 json unmarshal error: %v", err)
|
||||
}
|
||||
}
|
||||
return &cashcoupons.QueryCouponRequest{
|
||||
|
|
|
@ -33,12 +33,12 @@ func orderReq(order *proto.OrderRequest_Order, product *proto.OrderRequest_Produ
|
|||
var orderExtra OrderExtra
|
||||
err := json.Unmarshal(order.Extra, &orderExtra)
|
||||
if err != nil {
|
||||
return transferbatch.InitiateBatchTransferRequest{}, fmt.Errorf("order extra json unmarshal error: %v", err)
|
||||
return transferbatch.InitiateBatchTransferRequest{}, fmt.Errorf("order拓展参数 json unmarshal error[%+v]", err)
|
||||
}
|
||||
var productExtra ProductExtra
|
||||
err = json.Unmarshal(product.Extra, &productExtra)
|
||||
if err != nil {
|
||||
return transferbatch.InitiateBatchTransferRequest{}, fmt.Errorf("order extra json unmarshal error: %v", err)
|
||||
return transferbatch.InitiateBatchTransferRequest{}, fmt.Errorf("product拓展参数json unmarshal error:[%+v], extra[%s]", err, string(product.Extra))
|
||||
}
|
||||
return transferbatch.InitiateBatchTransferRequest{
|
||||
Appid: core.String(orderExtra.Appid),
|
||||
|
@ -78,7 +78,7 @@ func queryReq(order *proto.QueryRequest_Order) (*transferbatch.GetTransferDetail
|
|||
if order.Extra != nil {
|
||||
err := json.Unmarshal(order.Extra, &orderExtra)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("order extra json unmarshal error: %v", err)
|
||||
return nil, fmt.Errorf("order拓展参数 json unmarshal error: %v", err)
|
||||
}
|
||||
}
|
||||
return &transferbatch.GetTransferDetailByOutNoRequest{
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||
"plugins/wechat_redpack/internal/vo"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 插件通信信息,若不对应则会报错panic
|
||||
|
@ -17,6 +18,7 @@ const (
|
|||
type WeChatRedPackService struct{}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -40,6 +42,7 @@ func (p *WeChatRedPackService) Order(ctx context.Context, request *proto.OrderRe
|
|||
}
|
||||
|
||||
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())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -59,10 +59,10 @@ func TestQuery(t *testing.T) {
|
|||
request := &proto.QueryRequest{
|
||||
Config: config(),
|
||||
Order: &proto.QueryRequest_Order{
|
||||
OrderNo: "240403164049635931",
|
||||
OrderNo: "202409141056275034200012",
|
||||
TradeNo: "",
|
||||
Account: "",
|
||||
Extra: []byte(`{"out_detail_no":"123456789"}`),
|
||||
Extra: []byte(`{"out_detail_no":"0a2511525cc94a27bac18328771dc53e"}`),
|
||||
},
|
||||
}
|
||||
t.Run("TestQuery", func(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue