插件通信

This commit is contained in:
李子铭 2024-07-01 17:17:26 +08:00
parent feae7d4bd8
commit 1b2e54302c
7 changed files with 35 additions and 16 deletions

View File

@ -7,24 +7,33 @@ import (
"log"
)
var appKey = "8db16e8cc8363ed4eb4c14f9520bcc32"
var appId = "23329"
var appKey = "8db16e8cc8363ed4eb4c14f9520bcc32"
var baseUri = "http://test.openapi.1688sup.cn"
var notifyUrl = "http://test.openapi.1688sup.cn"
// main 这只是一个演示
func main() {
load := []*instance.PkgConf{
{
conf := &instance.PkgConf{
Cmd: "pkg/zltx",
Tag: "zltx",
},
Version: 1,
CookieKey: "zltx",
CookieValue: "zltx",
}
err := instance.Load(load)
err := instance.Load([]*instance.PkgConf{conf})
if err != nil {
panic(err)
}
request := &proto.OrderRequest{
res, err := instance.Get("zltx").Order(context.Background(), getRequest())
if err != nil {
log.Fatalln(err)
}
log.Printf("Order res:%+v", res)
}
func getRequest() *proto.OrderRequest {
return &proto.OrderRequest{
Config: &proto.Config{
AppId: appId,
AppKey: appKey,
@ -41,9 +50,4 @@ func main() {
Extra: []byte(`{}`),
},
}
res, err := instance.Get("zltx").Order(context.Background(), request)
if err != nil {
log.Fatalln(err)
}
log.Printf("Order res:%+v", res)
}

2
go.mod
View File

@ -2,7 +2,7 @@ module plugins
go 1.21
require codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701062026-8d942924410e
require codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701085519-f6acae1d59f9
require (
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect

2
go.sum
View File

@ -1,5 +1,7 @@
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701062026-8d942924410e h1:1X0dk1OR8Zhf9gjZHRKpY7d/iYqX7UqMPqy8q+GxmXM=
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701062026-8d942924410e/go.mod h1:QdW8HjHYQN8LCkFAB9e4oh7HziePCYnDXnUaKtmb8iQ=
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701085519-f6acae1d59f9 h1:U0ZsVK8mZBDxL3Nm6Btf3tEYZqC434qgubaZwnSL/7g=
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701085519-f6acae1d59f9/go.mod h1:QdW8HjHYQN8LCkFAB9e4oh7HziePCYnDXnUaKtmb8iQ=
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=

View File

@ -3,7 +3,7 @@ module plugins/zltx
go 1.21
require (
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701070232-7c96c21e16ac
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701085519-f6acae1d59f9
github.com/carlmjohnson/requests v0.23.5
github.com/go-playground/validator/v10 v10.22.0
github.com/hashicorp/go-plugin v1.6.1

View File

@ -4,6 +4,10 @@ codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701065841-5ae68878
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701065841-5ae68878836f/go.mod h1:QdW8HjHYQN8LCkFAB9e4oh7HziePCYnDXnUaKtmb8iQ=
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701070232-7c96c21e16ac h1:SY71ZgI7jKQyREHxfe9F0FvH3E4AICh0MLrFao6oCFk=
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701070232-7c96c21e16ac/go.mod h1:QdW8HjHYQN8LCkFAB9e4oh7HziePCYnDXnUaKtmb8iQ=
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701084422-a0dcbe4339b0 h1:qX4F5QwDka918bxtq9D1MvEYkybXhiGvBdrVoCFjh9M=
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701084422-a0dcbe4339b0/go.mod h1:QdW8HjHYQN8LCkFAB9e4oh7HziePCYnDXnUaKtmb8iQ=
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701085519-f6acae1d59f9 h1:U0ZsVK8mZBDxL3Nm6Btf3tEYZqC434qgubaZwnSL/7g=
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701085519-f6acae1d59f9/go.mod h1:QdW8HjHYQN8LCkFAB9e4oh7HziePCYnDXnUaKtmb8iQ=
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
github.com/carlmjohnson/requests v0.23.5 h1:NPANcAofwwSuC6SIMwlgmHry2V3pLrSqRiSBKYbNHHA=

View File

@ -10,8 +10,15 @@ import (
"plugins/zltx/internal/po"
)
// 插件通信信息,若不对应则会报错panic
const (
Tag = "zltx"
Version = 1
CookieKey = "zltx"
CookieValue = "zltx"
)
const (
orderMethod = "/recharge/order"
queryMethod = "/recharge/query"
)
@ -64,6 +71,7 @@ func (p *ZltxService) Notify(_ context.Context, request *proto.NotifyRequest) (*
if err != nil {
return nil, fmt.Errorf("解析异常msg:" + err.Error())
}
err = poReq.Validate()
if err != nil {
return nil, err
@ -71,5 +79,6 @@ func (p *ZltxService) Notify(_ context.Context, request *proto.NotifyRequest) (*
if !verify(poReq, request.Config.AppKey) {
return nil, errors.New("验签不通过")
}
return notifyResp(poReq), nil
}

View File

@ -8,7 +8,7 @@ import (
func main() {
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: shared.Handshake,
HandshakeConfig: shared.HandshakeConfig(internal.Version, internal.CookieKey, internal.CookieValue),
Plugins: shared.PluginSet(shared.NewPlugin(&internal.ZltxService{}, internal.Tag)),
GRPCServer: plugin.DefaultGRPCServer,
})