65 lines
2.3 KiB
Go
65 lines
2.3 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"linkpay/internal/service"
|
|
|
|
"git.linkiio.cn/linkpay/protobuf"
|
|
"github.com/gogf/gf/v2/encoding/gbase64"
|
|
"github.com/gogf/gf/v2/encoding/gjson"
|
|
"github.com/gogf/gf/v2/errors/gcode"
|
|
"github.com/gogf/gf/v2/errors/gerror"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"google.golang.org/grpc/metadata"
|
|
)
|
|
|
|
func Config(ctx context.Context) *gjson.Json {
|
|
md, ok := metadata.FromIncomingContext(ctx)
|
|
|
|
if !ok {
|
|
return &gjson.Json{}
|
|
}
|
|
|
|
c := md.Get("x-cfg-api")
|
|
b, _ := gbase64.DecodeString(c[0])
|
|
return gjson.New(b)
|
|
|
|
}
|
|
|
|
/**
|
|
* 回调事件实现
|
|
* @author dc.To
|
|
* @version 20250418
|
|
*/
|
|
func EventTestCase(ctx context.Context, req *protobuf.EventReq) (res *protobuf.EventRes, err error) {
|
|
|
|
if req.Kid != Config(ctx).Get("appId").Uint64() || req.Kid != g.Cfg("api").MustGet(ctx, "appId").Uint64() {
|
|
g.Log().Errorf(ctx, "req-Kid: %d == grpc-Kid: %d == cfg-Kid: %d", req.Kid, Config(ctx).Get("appId").Uint64(), g.Cfg("api").MustGet(ctx, "appId").Uint64())
|
|
return nil, gerror.NewCodef(gcode.CodeInternalError, "req-Kid [%d] not match Grpc Kid [%d] or cfg-Kid [%d]", req.Kid, Config(ctx).Get("appId").Uint64(), g.Cfg("api").MustGet(ctx, "appId").Uint64())
|
|
} else {
|
|
g.Log().Infof(ctx, "req-Kid: %d == grpc-Kid: %d == cfg-Kid: %d", req.Kid, Config(ctx).Get("appId").Uint64(), g.Cfg("api").MustGet(ctx, "appId").Uint64())
|
|
}
|
|
|
|
return &protobuf.EventRes{
|
|
Body: Config(ctx).Get("appId").String(),
|
|
}, nil
|
|
|
|
res = &protobuf.EventRes{
|
|
Type: "order",
|
|
Data: &protobuf.EventRes_Order{
|
|
Order: &protobuf.Orders{
|
|
Kid: req.Kid, //商户ID
|
|
Uid: req.Uid, //用户ID
|
|
Org: req.Org, //商户名称
|
|
Via: req.Via, //支付渠道
|
|
OrgNo: "12345", //渠道订单号
|
|
OrderNo: "67890", //商户订单号
|
|
Response: string(req.GetBody()), //解签后的Body数据
|
|
State: int32(service.GetState("error")), //订单状态 (参考 protobuf.State 枚举 @see https://git.linkiio.cn/linkpay/protobuf/src/commit/982698cc1cf9d050d21f904563b5403d1f11d987/org.pb.go#L26)
|
|
StateText: "支付失败", //渠道方状态原因,状态说明
|
|
},
|
|
},
|
|
}
|
|
return
|
|
}
|