commit c7f95cb80b1cb696a6a0b359d333af535bb8e7c7 Author: renzhiyuan <465386466@qq.com> Date: Mon Jul 28 17:10:26 2025 +0800 1 diff --git a/README.md b/README.md new file mode 100644 index 0000000..8fd6153 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# Kratos Project Template + +## Install Kratos +``` +go install github.com/go-kratos/kratos/cmd/kratos/v2@latest +``` +## Create a service +``` +# Create a template project +kratos new server + +cd server +# Add a proto template +kratos proto add api/server/server.proto +# Generate the proto code +kratos proto client api/server/server.proto +# Generate the source code of service by proto file +kratos proto server api/server/server.proto -t internal/service + +go generate ./... +go build -o ./bin/ ./... +./bin/server -conf ./configs +``` +## Generate other auxiliary files by Makefile +``` +# Download and update dependencies +make init +# Generate API files (include: pb.go, http, grpc, validate, swagger) by proto file +make api +# Generate all files +make all +``` +## Automated Initialization (wire) +``` +# install wire +go get github.com/google/wire/cmd/wire + +# generate wire +cd cmd/server +wire +``` + +## Docker +```bash +# build +docker build -t . + +# run +docker run --rm -p 8000:8000 -p 9000:9000 -v :/data/conf +``` + diff --git a/constant/param_type.go b/constant/param_type.go new file mode 100644 index 0000000..ff3c047 --- /dev/null +++ b/constant/param_type.go @@ -0,0 +1,3 @@ +package constant + +type () diff --git a/constant/request_code.go b/constant/request_code.go new file mode 100644 index 0000000..b9920a4 --- /dev/null +++ b/constant/request_code.go @@ -0,0 +1,7 @@ +package constant + +type RequestCode string + +const ( + GetAccountBalance RequestCode = "SKBALQRY" +) diff --git a/entity/account_center.go b/entity/account_center.go new file mode 100644 index 0000000..fefce81 --- /dev/null +++ b/entity/account_center.go @@ -0,0 +1,15 @@ +package entity + +type ( + GetAccountBalanceResp []struct { + AccountNo string `json:"accountNo" comment:"账号" xml:"accountNo"` + AccountName string `json:"accountName" comment:"账户名称" xml:"accountName"` + UsableBalance float64 `json:"usableBalance" comment:"可用账户余额" xml:"usableBalance"` //可操作的账户余额 + Balance float64 `json:"Balance" comment:"账号余额" xml:"Balance"` //该账户中全部余额,包含冻结金额、可操作余额等 + FraAmt float64 `json:"fraAmt" comment:"冻结余额" xml:"FraAmt"` + LastUdtTms string `json:"lastUdtTms" comment:"更新时间" xml:"LastUdtTms"` + DataSrc string `json:"dataSrc" comment:"数据来源" xml:"DataSrc"` //直联、非直联-人工等 + CurrencyID string `json:"currencyID" comment:"币种" xml:"CurrencyID"` //CNY:人民币 USD:美元 + Date string `json:"date" comment:"日期" xml:"Date"` + } +) diff --git a/entity/common.go b/entity/common.go new file mode 100644 index 0000000..b959854 --- /dev/null +++ b/entity/common.go @@ -0,0 +1,9 @@ +package entity + +type ( + RespCommon struct { + Status string `json:"status" ` //交易状态 + StatusText string `json:"statusText" ` //交易状态结果描述 + FailReason string `json:"failReason" ` //交易状态 + } +) diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c5fe939 --- /dev/null +++ b/go.mod @@ -0,0 +1,71 @@ +module tysk + +go 1.23.0 + +toolchain go1.23.10 + +require ( + github.com/ZZMarquis/gm v1.3.2 + github.com/bwmarrin/snowflake v0.3.0 + github.com/duke-git/lancet/v2 v2.3.7 + github.com/go-kratos/kratos/contrib/config/nacos/v2 v2.0.0-20250716060240-ac92cbe5701c + github.com/go-kratos/kratos/contrib/registry/nacos/v2 v2.0.0-20250716060240-ac92cbe5701c + github.com/go-kratos/kratos/v2 v2.8.4 + github.com/golang-jwt/jwt/v5 v5.1.0 + github.com/golang/protobuf v1.5.4 + github.com/google/wire v0.6.0 + github.com/mitchellh/mapstructure v1.5.0 + github.com/nacos-group/nacos-sdk-go v1.1.5 + github.com/pkg/errors v0.9.1 + github.com/pupuk/addr v0.0.3 + github.com/shimingyah/pool v1.0.0 + github.com/tjfoc/gmsm v1.4.1 + github.com/xuri/excelize/v2 v2.9.1 + go.opentelemetry.io/otel v1.24.0 + go.opentelemetry.io/otel/exporters/jaeger v1.17.0 + go.opentelemetry.io/otel/sdk v1.24.0 + go.uber.org/automaxprocs v1.5.1 + golang.org/x/crypto v0.38.0 + google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 + google.golang.org/grpc v1.65.0 + google.golang.org/protobuf v1.34.1 + gopkg.in/yaml.v2 v2.4.0 +) + +require ( + dario.cat/mergo v1.0.0 // indirect + github.com/aliyun/alibaba-cloud-sdk-go v1.61.18 // indirect + github.com/buger/jsonparser v1.1.1 // indirect + github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/go-errors/errors v1.0.1 // indirect + github.com/go-kratos/aegis v0.2.0 // indirect + github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-playground/form/v4 v4.2.1 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/gorilla/mux v1.8.1 // indirect + github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect + github.com/json-iterator/go v1.1.6 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect + github.com/richardlehane/mscfb v1.0.4 // indirect + github.com/richardlehane/msoleps v1.0.4 // indirect + github.com/tiendc/go-deepcopy v1.6.0 // indirect + github.com/xuri/efp v0.0.1 // indirect + github.com/xuri/nfp v0.0.1 // indirect + go.opentelemetry.io/otel/metric v1.24.0 // indirect + go.opentelemetry.io/otel/trace v1.24.0 // indirect + go.uber.org/atomic v1.6.0 // indirect + go.uber.org/multierr v1.5.0 // indirect + go.uber.org/zap v1.15.0 // indirect + golang.org/x/exp v0.0.0-20221208152030-732eee02a75a // indirect + golang.org/x/net v0.40.0 // indirect + golang.org/x/sync v0.14.0 // indirect + golang.org/x/sys v0.33.0 // indirect + golang.org/x/text v0.25.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect + gopkg.in/ini.v1 v1.42.0 // indirect + gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/pkg/func.go b/pkg/func.go new file mode 100644 index 0000000..63575b2 --- /dev/null +++ b/pkg/func.go @@ -0,0 +1,50 @@ +package pkg + +import ( + "bytes" + "fmt" +) + +// XmlRequest 定义请求结构 +type XmlRequest struct { + Action string `xml:"action"` + UserName string `xml:"userName"` + ExtraFields map[string]interface{} `xml:"-"` // 忽略此字段,手动处理 +} + +// MarshalToXML 将XmlRequest转换为指定格式的XML字节流 +func (req XmlRequest) MarshalToXML() ([]byte, error) { + var buf bytes.Buffer + + // 写入XML声明 + buf.WriteString(`` + "\n") + buf.WriteString("\n") + + // 写入基本字段 + buf.WriteString(fmt.Sprintf("%s\n", req.Action)) + buf.WriteString(fmt.Sprintf("%s\n", req.UserName)) + + // 处理ExtraFields + for key, value := range req.ExtraFields { + switch v := value.(type) { + case string: + // 空字符串特殊处理(根据示例输出,有些空字段也需要输出) + buf.WriteString(fmt.Sprintf("<%s>%s\n", key, v, key)) + case []map[string]interface{}: + // 处理列表数据 + buf.WriteString(fmt.Sprintf("\n", key)) + for _, row := range v { + buf.WriteString("\n") + for rowKey, rowValue := range row { + buf.WriteString(fmt.Sprintf("<%s>%v\n", rowKey, rowValue, rowKey)) + } + buf.WriteString("\n") + } + buf.WriteString("\n") + // 可以根据需要添加其他类型的处理 + } + } + + buf.WriteString("") + return buf.Bytes(), nil +} diff --git a/pkg/req_test.go b/pkg/req_test.go new file mode 100644 index 0000000..56ebd69 --- /dev/null +++ b/pkg/req_test.go @@ -0,0 +1,29 @@ +package pkg + +import "testing" + +func TestXmL(t *testing.T) { + data := XmlRequest{ + Action: "SKBACQRY", + UserName: "11100199667893870098", + ExtraFields: map[string]interface{}{ + "blngBnkId": "", + "accCgyId": "", + "startRecord": "1", + "pageNumber": "20", + // 列表数据作为 ExtraFields 的一个字段 + "userDataList": []map[string]interface{}{ + {"accountNo": "8110901013900618088", "name": "1", "ss": 222}, + {"accountNo": "8110901013900618088", "name": "2", "ss": 333}, + {"accountNo": "8110901013900618088", "name": "3", "ss": 444}, + }, + "userDataList2": []map[string]interface{}{ + {"accountNo": "8110901013900618088", "name": "4", "ss": 12}, + {"accountNo": "8110901013900618088", "name": "4", "ss": 44324}, + {"accountNo": "8110901013900618088", "name": "4", "ss": 44}, + }, + }, + } + gbkXML, err := data.MarshalToXML() + t.Log(gbkXML, err) +} diff --git a/pkg/request.go b/pkg/request.go new file mode 100644 index 0000000..202b47b --- /dev/null +++ b/pkg/request.go @@ -0,0 +1,6 @@ +package pkg + +func HandleRequest(reqData XmlRequest, result interface{}) { + gbkXML, err := reqData.MarshalToXML() + +} diff --git a/tysk.go b/tysk.go new file mode 100644 index 0000000..1d196a2 --- /dev/null +++ b/tysk.go @@ -0,0 +1,18 @@ +package tysk + +import ( + "tysk/entity" +) + +type Tysk struct { + UserName string +} + +func NewTysk(UserName string) *Tysk { + return &Tysk{UserName: UserName} +} + +func GetAccountBalance(accountList []string) (res entity.GetAccountBalanceResp, err error) { + + return +}