错误信息乱码处理
This commit is contained in:
parent
de76bd806d
commit
8eb97590d5
|
@ -2,12 +2,15 @@ module plugins/alipay_cpn
|
|||
|
||||
go 1.22.2
|
||||
|
||||
replace plugins/utils => ../../utils
|
||||
|
||||
require (
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240911021858-7f3ba37bbbca
|
||||
github.com/carlmjohnson/requests v0.24.2
|
||||
github.com/go-playground/validator/v10 v10.22.0
|
||||
github.com/hashicorp/go-plugin v1.6.1
|
||||
github.com/stretchr/testify v1.9.0
|
||||
plugins/utils v0.0.0-00010101000000-000000000000
|
||||
)
|
||||
|
||||
require (
|
||||
|
|
|
@ -2,10 +2,12 @@ package internal
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||
"github.com/carlmjohnson/requests"
|
||||
"plugins/alipay_cpn/internal/po"
|
||||
"plugins/utils"
|
||||
)
|
||||
|
||||
// 插件通信信息,若不对应则会报错panic
|
||||
|
@ -42,9 +44,13 @@ func (s *AlipayCpnService) Order(ctx context.Context, request *proto.OrderReques
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response po.OrderResp
|
||||
err = requests.URL(c.BaseUri).BodyForm(uv).ToJSON(&response).Fetch(ctx)
|
||||
if err != nil {
|
||||
|
||||
var sp string
|
||||
err = requests.URL(c.BaseUri).Post().BodyForm(uv).ToString(&sp).Fetch(ctx)
|
||||
|
||||
var response *po.OrderResp
|
||||
sp = utils.ToChinese(sp)
|
||||
if err = json.Unmarshal([]byte(sp), &response); err != nil {
|
||||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||
}
|
||||
|
||||
|
@ -68,11 +74,19 @@ func (s *AlipayCpnService) Query(ctx context.Context, request *proto.QueryReques
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response po.QueryResp
|
||||
err = requests.URL(c.BaseUri).BodyForm(uv).ToJSON(&response).Fetch(ctx)
|
||||
|
||||
var sp string
|
||||
err = requests.URL(c.BaseUri).Post().BodyForm(uv).ToString(&sp).Fetch(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||
}
|
||||
|
||||
var response po.QueryResp
|
||||
sp = utils.ToChinese(sp)
|
||||
if err = json.Unmarshal([]byte(sp), &response); err != nil {
|
||||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||
}
|
||||
|
||||
return queryResp(request, response), nil
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ func orderReq(order *proto.OrderRequest_Order, product *proto.OrderRequest_Produ
|
|||
return o, nil
|
||||
}
|
||||
|
||||
func orderResp(request *proto.OrderRequest, resp po.OrderResp) *proto.OrderResponse {
|
||||
func orderResp(request *proto.OrderRequest, resp *po.OrderResp) *proto.OrderResponse {
|
||||
data, _ := json.Marshal(resp)
|
||||
return &proto.OrderResponse{
|
||||
Result: &proto.Result{
|
||||
|
|
|
@ -2,10 +2,12 @@ package internal
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gitea.cdlsxd.cn/sdk/plugin/proto"
|
||||
"github.com/carlmjohnson/requests"
|
||||
"plugins/alipay_redpack/internal/po"
|
||||
"plugins/utils"
|
||||
"plugins/utils/alipay"
|
||||
)
|
||||
|
||||
|
@ -44,9 +46,13 @@ func (s *AlipayRedPackService) Order(ctx context.Context, request *proto.OrderRe
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response po.OrderResp
|
||||
err = requests.URL(baseUri).Post().Params(uv).ToJSON(&response).Fetch(ctx)
|
||||
if err != nil {
|
||||
|
||||
var sp string
|
||||
err = requests.URL(baseUri).Post().BodyForm(uv).ToString(&sp).Fetch(ctx)
|
||||
|
||||
var response *po.OrderResp
|
||||
sp = utils.ToChinese(sp)
|
||||
if err = json.Unmarshal([]byte(sp), &response); err != nil {
|
||||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||
}
|
||||
|
||||
|
@ -70,11 +76,19 @@ func (s *AlipayRedPackService) Query(ctx context.Context, request *proto.QueryRe
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response po.QueryResp
|
||||
err = requests.URL(baseUri).BodyForm(uv).ToJSON(&response).Fetch(ctx)
|
||||
|
||||
var sp string
|
||||
err = requests.URL(baseUri).Post().BodyForm(uv).ToString(&sp).Fetch(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||
}
|
||||
|
||||
var response po.QueryResp
|
||||
sp = utils.ToChinese(sp)
|
||||
if err = json.Unmarshal([]byte(sp), &response); err != nil {
|
||||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||
}
|
||||
|
||||
return queryResp(request, response), nil
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ func orderReq(order *proto.OrderRequest_Order, product *proto.OrderRequest_Produ
|
|||
return o, nil
|
||||
}
|
||||
|
||||
func orderResp(request *proto.OrderRequest, resp po.OrderResp) *proto.OrderResponse {
|
||||
func orderResp(request *proto.OrderRequest, resp *po.OrderResp) *proto.OrderResponse {
|
||||
data, _ := json.Marshal(resp)
|
||||
return &proto.OrderResponse{
|
||||
Result: &proto.Result{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"golang.org/x/text/encoding/simplifiedchinese"
|
||||
"golang.org/x/text/transform"
|
||||
"os"
|
||||
)
|
||||
|
||||
|
@ -8,3 +10,10 @@ func FileExists(filePath string) bool {
|
|||
_, err := os.Stat(filePath)
|
||||
return err == nil || os.IsExist(err)
|
||||
}
|
||||
|
||||
// ToChinese 处理文件名编码为简体中文
|
||||
func ToChinese(s string) string {
|
||||
encoder := simplifiedchinese.GBK.NewDecoder()
|
||||
encodedName, _, _ := transform.String(encoder, s)
|
||||
return encodedName
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package utils
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestToChinese(t *testing.T) {
|
||||
arg := "sub_msg"
|
||||
got := ToChinese(arg)
|
||||
t.Log(got)
|
||||
}
|
|
@ -3,11 +3,10 @@ module plugins/utils
|
|||
go 1.22.2
|
||||
|
||||
require (
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b
|
||||
github.com/tjfoc/gmsm v1.4.1
|
||||
github.com/wechatpay-apiv3/wechatpay-go v0.2.18
|
||||
golang.org/x/text v0.16.0
|
||||
)
|
||||
|
||||
require (
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b // indirect
|
||||
github.com/stretchr/testify v1.8.4 // indirect
|
||||
)
|
||||
require github.com/stretchr/testify v1.8.4 // indirect
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240821033242-d9c3e7ad88f6 h1:L+z3IjcLEbj9UJAQCZv1YA1HqIrZZxBlZ9I4tQF6dXY=
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240821033242-d9c3e7ad88f6/go.mod h1:59zYRFcPur2HizJEIfttVOMY0AscollDYKX0yvPJS7k=
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b h1:x8Gf1EJ6oLHEIgK/SilgMZ5EDgcEknef9zhGrFvXXMg=
|
||||
gitea.cdlsxd.cn/sdk/plugin v0.0.0-20240830100334-2e99a5df732b/go.mod h1:cd+ZFTmd/ZxrrVc1OZCkrh2wAMPDaAa8ce13FAAkBg0=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
|
@ -68,6 +66,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
|
|
Loading…
Reference in New Issue