添加文件: xy_sh/internal/biz/biz.go
This commit is contained in:
parent
917dbeba52
commit
53868e0eeb
|
|
@ -0,0 +1,67 @@
|
||||||
|
package biz
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"xy_sh/internal/config"
|
||||||
|
"xy_sh/internal/entities"
|
||||||
|
"xy_sh/pkg/crypto"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Biz 业务逻辑层
|
||||||
|
type Biz struct {
|
||||||
|
cfg *config.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewBiz 创建业务逻辑实例
|
||||||
|
func NewBiz(cfg *config.Config) *Biz {
|
||||||
|
return &Biz{cfg: cfg}
|
||||||
|
}
|
||||||
|
|
||||||
|
// EncryptResponse 加密响应数据
|
||||||
|
func (b *Biz) EncryptResponse(data interface{}) (string, error) {
|
||||||
|
jsonBytes, err := json.Marshal(data)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return crypto.SM4ECBEncrypt(jsonBytes, b.cfg.SM4Key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecryptRequest 解密请求数据
|
||||||
|
func (b *Biz) DecryptRequest(encryptedData string) ([]byte, error) {
|
||||||
|
return crypto.SM4ECBDecrypt(encryptedData, b.cfg.SM4Key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProcessOrder 处理下单请求
|
||||||
|
func (b *Biz) ProcessOrder(req *entities.OrderRequest) (*entities.OrderResponse, error) {
|
||||||
|
return &entities.OrderResponse{
|
||||||
|
OrderNo: "HM" + generateOrderNo(),
|
||||||
|
Status: 0,
|
||||||
|
ExpireTime: "2025-12-31 23:59:59",
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProcessQuery 处理订单查询请求
|
||||||
|
func (b *Biz) ProcessQuery(req *entities.QueryRequest) (*entities.QueryResponse, error) {
|
||||||
|
return &entities.QueryResponse{
|
||||||
|
OrderNo: req.OrderNo,
|
||||||
|
Status: 0,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProcessWechatRecharge 处理微信立减金充值请求
|
||||||
|
func (b *Biz) ProcessWechatRecharge(req *entities.WechatRechargeRequest) (*entities.WechatRechargeResponse, error) {
|
||||||
|
return &entities.WechatRechargeResponse{
|
||||||
|
OrderNo: req.OrderNo,
|
||||||
|
Status: 0,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProcessCallback 处理回调通知
|
||||||
|
func (b *Biz) ProcessCallback(req *entities.CallbackRequest) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// generateOrderNo 生成订单号(示例)
|
||||||
|
func generateOrderNo() string {
|
||||||
|
return "0000000000000000"
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue