feat: 开启otel

This commit is contained in:
danial
2025-02-24 21:37:26 +08:00
parent 70de293138
commit b2583cead4
16 changed files with 172 additions and 115 deletions

View File

@@ -1,7 +1,6 @@
package gateway
import (
"context"
"fmt"
"gateway/internal/config"
"gateway/internal/models/merchant"
@@ -25,7 +24,8 @@ type OrderController struct {
}
func (c *OrderController) OrderQuery() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "ShopHttp")
defer cancel()
bankOrderId := c.GetString("bankOrderId")
otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("获取订单信息:%s", bankOrderId), zap.String("bankOrderId", bankOrderId))
qy := query.SupplierOrderQueryResult(ctx, bankOrderId)
@@ -34,7 +34,8 @@ func (c *OrderController) OrderQuery() {
}
func (c *OrderController) OrderUpdate() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "OrderUpdate")
defer cancel()
bankOrderId := c.GetString("bankOrderId")
solveType := c.GetString("solveType")
orderInfo := order.GetOrderByBankOrderId(ctx, bankOrderId)
@@ -77,7 +78,8 @@ func (c *OrderController) OrderUpdate() {
}
func (c *OrderController) MerchantQuery() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "MerchantQuery")
defer cancel()
appKey := strings.TrimSpace(c.GetString("appKey"))
orderNo := strings.TrimSpace(c.GetString("orderNo"))
timestamp := strings.TrimSpace(c.GetString("timestamp"))

View File

@@ -1,12 +1,12 @@
package gateway
import (
"context"
"fmt"
"gateway/internal/config"
"gateway/internal/models/order"
"gateway/internal/models/payfor"
"gateway/internal/models/road"
"gateway/internal/otelTrace"
"gateway/internal/schema/response"
"gateway/internal/service/pay_for"
"gateway/internal/service/supplier/third_party"
@@ -24,7 +24,8 @@ type PayForGateway struct {
// PayFor 接受下游商户的代付请求
func (c *PayForGateway) PayFor() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayFor")
defer cancel()
params := map[string]any{
"merchantKey": strings.TrimSpace(c.GetString("merchantKey")),
"realname": strings.TrimSpace(c.GetString("realname")),
@@ -48,7 +49,8 @@ func (c *PayForGateway) PayFor() {
// PayForQuery 代付结果查询,
func (c *PayForGateway) PayForQuery() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayForQuery")
defer cancel()
params := map[string]any{
"merchantKey": strings.TrimSpace(c.GetString("merchantKey")),
"timestamp": strings.TrimSpace(c.GetString("timestamp")),
@@ -61,7 +63,8 @@ func (c *PayForGateway) PayForQuery() {
// QuerySupplierPayForResult 查询上游的代付结果
func (c *PayForGateway) QuerySupplierPayForResult() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "QuerySupplierPayForResult")
defer cancel()
bankOrderId := strings.TrimSpace(c.GetString("bankOrderId"))
p := payfor.GetPayForByBankOrderId(ctx, bankOrderId)
if p.RoadUid == "" {
@@ -87,7 +90,8 @@ func (c *PayForGateway) QuerySupplierPayForResult() {
// SolvePayForResult 接收boss发送过来的代付手动处理结果
func (c *PayForGateway) SolvePayForResult() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "SolvePayForResult")
defer cancel()
resultType := strings.TrimSpace(c.GetString("resultType"))
bankOrderId := strings.TrimSpace(c.GetString("bankOrderId"))
@@ -107,7 +111,8 @@ func (c *PayForGateway) SolvePayForResult() {
// Balance 商户查找余额
func (c *PayForGateway) Balance() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "Balance")
defer cancel()
params := map[string]any{
"merchantKey": strings.TrimSpace(c.GetString("merchantKey")),
"timestamp": strings.TrimSpace(c.GetString("timestamp")),

View File

@@ -50,7 +50,8 @@ type ScanController struct {
// Scan 处理扫码的请求
func (c *ScanController) Scan() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "ScanController")
defer cancel()
// 获取所有请求参数
// 获取客户端的ip
p := service.GetMerchantInfo(ctx, map[string]any{
@@ -66,7 +67,7 @@ func (c *ScanController) Scan() {
"ip": strings.TrimSpace(c.GetString("ip")),
"deviceId": strings.TrimSpace(c.GetString("deviceId")),
})
ctx, cancel := otelTrace.Span(ctx, "页面订单", "ScanController", trace.WithAttributes(
ctx, cancel = otelTrace.Span(ctx, "页面订单", "ScanController", trace.WithAttributes(
attribute.String("exValue", p.Params["exValue"].(string)),
attribute.String("orderNo", p.Params["orderNo"].(string)),
attribute.String("productCode", p.Params["productCode"].(string)),
@@ -291,7 +292,8 @@ func (c *ScanController) SolveFailJSON(p *response.PayBaseResp) {
}
func (c *ScanController) GetAllowedMM() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "GetAllowedMM")
defer cancel()
payKey := strings.TrimSpace(c.GetString("payKey"))
showMMValue, err := c.GetFloat("showMMValue")
productCode := strings.TrimSpace(c.GetString("productCode"))
@@ -358,7 +360,8 @@ func (c *ScanController) GetAllowedMM() {
// CreateOrder 创建订单
func (c *ScanController) CreateOrder() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "CreateOrder")
defer cancel()
createdOrder := request.CreatedOrder{}
_ = c.Bind(&createdOrder)
otelTrace.Logger.WithContext(ctx).Info("创建订单:", zap.Any("createdOrder", createdOrder))
@@ -371,7 +374,7 @@ func (c *ScanController) CreateOrder() {
_ = c.ServeJSON()
return
}
ctx, cancel := otelTrace.Span(ctx, "API订单", "ScanController", trace.WithAttributes(
ctx, cancel = otelTrace.Span(ctx, "API订单", "ScanController", trace.WithAttributes(
attribute.String("PayKey", createdOrder.PayKey),
attribute.String("ProductCode", createdOrder.ProductCode),
attribute.String("productCode", createdOrder.Sign),

View File

@@ -257,41 +257,41 @@ func NewSchedulerTrace(opts ...trace.TracerOption) trace.Tracer {
return otel.Tracer("scheduler", opts...)
}
func init() {
// 初始化日志
// 自定义日志格式配置
encoderConfig := zapcore.EncoderConfig{
TimeKey: "time",
LevelKey: "level",
NameKey: "logger",
CallerKey: "caller",
FunctionKey: zapcore.OmitKey,
MessageKey: "msg",
StacktraceKey: "stacktrace",
LineEnding: zapcore.DefaultLineEnding,
EncodeLevel: zapcore.CapitalLevelEncoder, // 使用大写字母记录日志级别
EncodeTime: zapcore.TimeEncoderOfLayout(time.DateTime), // ISO8601 时间格式
EncodeDuration: zapcore.SecondsDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder, // 短路径编码器
}
// 创建核心
core := zapcore.NewTee(
zapcore.NewCore(
zapcore.NewConsoleEncoder(encoderConfig),
zapcore.NewMultiWriteSyncer(
zapcore.AddSync(os.Stdout),
),
zap.InfoLevel,
),
)
logger := zap.New(core,
zap.AddCaller(),
// zap.AddCallerSkip(1),
zap.AddStacktrace(zap.ErrorLevel),
)
// zap设置标准输出流
// 设置全局 logger
Logger = &LoggerStruct{
logger: logger,
}
}
// func init() {
// // 初始化日志
// // 自定义日志格式配置
// encoderConfig := zapcore.EncoderConfig{
// TimeKey: "time",
// LevelKey: "level",
// NameKey: "logger",
// CallerKey: "caller",
// FunctionKey: zapcore.OmitKey,
// MessageKey: "msg",
// StacktraceKey: "stacktrace",
// LineEnding: zapcore.DefaultLineEnding,
// EncodeLevel: zapcore.CapitalLevelEncoder, // 使用大写字母记录日志级别
// EncodeTime: zapcore.TimeEncoderOfLayout(time.DateTime), // ISO8601 时间格式
// EncodeDuration: zapcore.SecondsDurationEncoder,
// EncodeCaller: zapcore.ShortCallerEncoder, // 短路径编码器
// }
// // 创建核心
// core := zapcore.NewTee(
// zapcore.NewCore(
// zapcore.NewConsoleEncoder(encoderConfig),
// zapcore.NewMultiWriteSyncer(
// zapcore.AddSync(os.Stdout),
// ),
// zap.InfoLevel,
// ),
// )
// logger := zap.New(core,
// zap.AddCaller(),
// // zap.AddCallerSkip(1),
// zap.AddStacktrace(zap.ErrorLevel),
// )
// // zap设置标准输出流
// // 设置全局 logger
// Logger = &LoggerStruct{
// logger: logger,
// }
// }

View File

@@ -185,7 +185,8 @@ func (c *AppleCardImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roa
// KMEncrypt 加密卡密
func (c *AppleCardImpl) kMEncrypt(kf, appSecret string) (string, error) {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "kMEncrypt")
defer cancel()
secret := utils.GetMD5LOWER(appSecret)[:16] // 加密秘钥
block, err := aes.NewCipher([]byte(secret))
if err != nil {
@@ -201,7 +202,8 @@ func (c *AppleCardImpl) kMEncrypt(kf, appSecret string) (string, error) {
}
func (c *AppleCardImpl) PayNotify() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayNotify")
defer cancel()
attach := strings.TrimSpace(c.GetString("attach"))
orderInfo := order.GetOrderByBankOrderId(ctx, attach) // OrderId
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
@@ -237,7 +239,8 @@ func (c *AppleCardImpl) PayNotify() {
}
func (c *AppleCardImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayQuery")
defer cancel()
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
if err != nil {
@@ -302,7 +305,8 @@ func (c *AppleCardImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadIn
}
func (c *AppleCardImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supply_model.MsgModel {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayQueryV2")
defer cancel()
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
if err != nil {
@@ -384,7 +388,8 @@ func (c *AppleCardImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
if err != nil {
return config.PAYFOR_FAIL, ""
}
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayForQuery")
defer cancel()
params := map[string]string{}
params["order_id"] = payFor.BankOrderId

View File

@@ -166,7 +166,8 @@ func (c *AppleCardSharkImpl) kMEncrypt(ctx context.Context, kf, appSecret string
}
func (c *AppleCardSharkImpl) PayNotify() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayNotify")
defer cancel()
attach := strings.TrimSpace(c.GetString("attach"))
orderInfo := order.GetOrderByBankOrderId(ctx, attach) // OrderId
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
@@ -217,7 +218,8 @@ func (c *AppleCardSharkImpl) PayNotify() {
func (c *AppleCardSharkImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
params := map[string]any{}
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayQuery")
defer cancel()
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
if err != nil {
@@ -281,7 +283,8 @@ func (c *AppleCardSharkImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.R
func (c *AppleCardSharkImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supply_model.MsgModel {
params := map[string]any{}
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "AppleCardSharkImpl")
defer cancel()
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
if err != nil {
@@ -357,7 +360,8 @@ func (c *AppleCardSharkImpl) PayFor(info payfor.PayforInfo) string {
func (c *AppleCardSharkImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
cfg := config.Config{}
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayForQuery")
defer cancel()
url, err := cfg.GetMFCardQueryUrl()
if err != nil {

View File

@@ -102,7 +102,8 @@ func (c *DaiLiImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInf
}
func (c *DaiLiImpl) PayNotify() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayNotify")
defer cancel()
orderNo := strings.TrimSpace(c.GetString("orderNo"))
orderInfo := order.GetOrderByBankOrderId(ctx, orderNo)
@@ -168,7 +169,8 @@ func (c *DaiLiImpl) PayNotify() {
}
func (c *DaiLiImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayQuery")
defer cancel()
tradeStatus := "SUCCESS"
trxNo := orderInfo.BankOrderId

View File

@@ -147,7 +147,8 @@ func (c *JDCardImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadIn
// KMEncrypt 加密卡密
func (c *JDCardImpl) kMEncrypt(kf, appSecret string) (string, error) {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "kMEncrypt")
defer cancel()
secret := utils.GetMD5LOWER(appSecret)[:16] // 加密秘钥
block, err := aes.NewCipher([]byte(secret))
@@ -164,7 +165,8 @@ func (c *JDCardImpl) kMEncrypt(kf, appSecret string) (string, error) {
}
func (c *JDCardImpl) PayNotify() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayNotify")
defer cancel()
attach := strings.TrimSpace(c.GetString("merchantId"))
orderInfo := order.GetOrderByBankOrderId(ctx, attach) // OrderId
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
@@ -214,7 +216,8 @@ func (c *JDCardImpl) PayNotify() {
func (c *JDCardImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
params := map[string]any{}
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayQuery")
defer cancel()
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
if err != nil {
return false
@@ -277,7 +280,8 @@ func (c *JDCardImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo)
func (c *JDCardImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supply_model.MsgModel {
params := map[string]any{}
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayQueryV2")
defer cancel()
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
if err != nil {
return supply_model.CardMsgErr
@@ -351,9 +355,10 @@ func (c *JDCardImpl) PayFor(info payfor.PayforInfo) string {
}
func (c *JDCardImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayForQuery")
defer cancel()
cfg := config.Config{}
url, err := cfg.GetMFCardQueryUrl()
ctx := context.Background()
if err != nil {
return config.PAYFOR_FAIL, ""
}

View File

@@ -122,7 +122,8 @@ func (c *KuaiFuImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadIn
// PayNotify 支付回调
func (c *KuaiFuImpl) PayNotify() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayNotify")
defer cancel()
orderNo := strings.TrimSpace(c.GetString("orderNo"))
orderInfo := order.GetOrderByBankOrderId(ctx, orderNo)
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
@@ -185,7 +186,8 @@ func (c *KuaiFuImpl) PayNotify() {
}
func (c *KuaiFuImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayQuery")
defer cancel()
if orderInfo.Status != "wait" && orderInfo.Status != "" {
otelTrace.Logger.WithContext(ctx).Error("订单已经被处理不需要查询bankOrderId", zap.String("BankOrderId", orderInfo.BankOrderId))
return false
@@ -241,7 +243,8 @@ func (c *KuaiFuImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInf
}
func (c *KuaiFuImpl) PayFor(payFor payfor.PayforInfo) string {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayFor")
defer cancel()
params := make(map[string]any)
params["merchantKey"] = KF_PAY_KEY
params["realname"] = payFor.BankAccountName
@@ -292,7 +295,8 @@ func (c *KuaiFuImpl) PayForNotify() string {
}
func (c *KuaiFuImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayForQuery")
defer cancel()
params := make(map[string]any)
params["merchantKey"] = KF_PAY_KEY
params["timestamp"] = utils.GetNowTimesTamp()
@@ -346,12 +350,13 @@ func (c *KuaiFuImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
}
func (c *KuaiFuImpl) BalanceQuery(roadInfo road.RoadInfo) float64 {
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "BalanceQuery")
defer cancel()
params := map[string]any{
"merchantKey": KF_PAY_KEY,
"timestamp": utils.GetNowTimesTamp(),
"merchantOrderId": xid.New().String(),
}
ctx := context.Background()
keys := utils.SortMap(params)
sign := utils.GetMD5Sign(params, keys, KF_PAY_SECRET)
params["sign"] = sign

View File

@@ -171,7 +171,8 @@ func (c *MFCardV2Impl) Scan(ctx context.Context, orderInfo order.OrderInfo, road
// KMEncrypt 加密卡密
func (c *MFCardV2Impl) kMEncrypt(kf, appSecret string) (string, error) {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "kMEncrypt")
defer cancel()
secret := utils.GetMD5LOWER(appSecret)[:16] // 加密秘钥
block, err := aes.NewCipher([]byte(secret))
if err != nil {
@@ -187,7 +188,8 @@ func (c *MFCardV2Impl) kMEncrypt(kf, appSecret string) (string, error) {
}
func (c *MFCardV2Impl) PayNotify() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayNotify")
defer cancel()
otelTrace.Logger.WithContext(ctx).Info("消息回调成功!!!")
params := make(map[string]any)
attach := strings.TrimSpace(c.GetString("attach"))
@@ -255,7 +257,8 @@ func (c *MFCardV2Impl) PayNotify() {
}
func (c *MFCardV2Impl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayQuery")
defer cancel()
params := map[string]any{}
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
@@ -319,8 +322,9 @@ func (c *MFCardV2Impl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInf
}
func (c *MFCardV2Impl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supply_model.MsgModel {
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayQueryV2")
defer cancel()
params := map[string]any{}
ctx := context.Background()
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
if err != nil {
return supply_model.CardMsgErr
@@ -395,8 +399,9 @@ func (c *MFCardV2Impl) PayFor(info payfor.PayforInfo) string {
}
func (c *MFCardV2Impl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayForQuery")
defer cancel()
cfg := config.Config{}
ctx := context.Background()
url, err := cfg.GetMFCardQueryUrl()
if err != nil {
return config.PAYFOR_FAIL, ""

View File

@@ -128,7 +128,8 @@ func (c *SelfThirdImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roa
// KMEncrypt 加密卡密
func (c *SelfThirdImpl) kMEncrypt(kf, appSecret string) (string, error) {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "kMEncrypt")
defer cancel()
secret := utils.GetMD5LOWER(appSecret)[:16] // 加密秘钥
block, err := aes.NewCipher([]byte(secret))
@@ -145,7 +146,8 @@ func (c *SelfThirdImpl) kMEncrypt(kf, appSecret string) (string, error) {
}
func (c *SelfThirdImpl) PayNotify() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayNotify")
defer cancel()
params := map[string]any{
"orderNo": c.GetString("orderNo"),
@@ -198,7 +200,8 @@ func (c *SelfThirdImpl) PayNotify() {
}
func (c *SelfThirdImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayQuery")
defer cancel()
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
if err != nil {
@@ -263,7 +266,8 @@ func (c *SelfThirdImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadIn
}
func (c *SelfThirdImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supply_model.MsgModel {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayQueryV2")
defer cancel()
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
if err != nil {
@@ -345,7 +349,8 @@ func (c *SelfThirdImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
if err != nil {
return config.PAYFOR_FAIL, ""
}
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayForQuery")
defer cancel()
params := map[string]string{}
params["order_id"] = payFor.BankOrderId

View File

@@ -109,7 +109,9 @@ func (c *StarSilenceImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, r
}
func (c *StarSilenceImpl) PayNotify() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayNotify")
defer cancel()
otelTrace.Logger.WithContext(ctx).Info("消息回调成功!!!")
params := map[string]string{
"supplierOrderId": strings.TrimSpace(c.GetString("supplierOrderId")),
@@ -175,7 +177,8 @@ func (c *StarSilenceImpl) PayNotify() {
func (c *StarSilenceImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
params := map[string]any{}
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayQuery")
defer cancel()
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
if err != nil {
return false
@@ -238,7 +241,8 @@ func (c *StarSilenceImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.Road
func (c *StarSilenceImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supply_model.MsgModel {
params := map[string]any{}
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayQueryV2")
defer cancel()
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
if err != nil {
return supply_model.CardMsgErr
@@ -314,7 +318,8 @@ func (c *StarSilenceImpl) PayFor(info payfor.PayforInfo) string {
func (c *StarSilenceImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
cfg := config.Config{}
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayForQuery")
defer cancel()
url, err := cfg.GetMFCardQueryUrl()
if err != nil {
return config.PAYFOR_FAIL, ""

View File

@@ -166,8 +166,8 @@ func (c *TMAllGameImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roa
}
func (c *TMAllGameImpl) PayNotify() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayNotify")
defer cancel()
orderInfo := order.GetOrderByBankOrderId(ctx, strings.TrimSpace(c.GetString("merchantOrder"))) // OrderId
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
otelTrace.Logger.WithContext(ctx).Error("【TMALLGAME】回调的订单号不存在订单号=", zap.String("merchantOrder", strings.TrimSpace(c.GetString("merchantOrder"))))
@@ -225,7 +225,8 @@ func (c *TMAllGameImpl) PayNotify() {
func (c *TMAllGameImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
params := map[string]any{}
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayQuery")
defer cancel()
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
if err != nil {
@@ -289,7 +290,8 @@ func (c *TMAllGameImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadIn
func (c *TMAllGameImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supply_model.MsgModel {
params := map[string]any{}
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayQueryV2")
defer cancel()
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
if err != nil {
@@ -370,8 +372,8 @@ func (c *TMAllGameImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
if err != nil {
return config.PAYFOR_FAIL, ""
}
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayForQuery")
defer cancel()
params := map[string]string{}
params["order_id"] = payFor.BankOrderId
params["app_key"] = gojson.Json("").Get("appKey").Tostring()

View File

@@ -232,7 +232,8 @@ type ResponseStruct struct {
}
func (c *WalMartImpl) PayNotify() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayNotify")
defer cancel()
otelTrace.Logger.WithContext(ctx).Info("【沃尔玛】快付回调开始")
response := ResponseStruct{}
err := json.Unmarshal(c.Ctx.Input.RequestBody, &response)
@@ -270,7 +271,8 @@ func (c *WalMartImpl) PayNotify() {
func (c *WalMartImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
params := map[string]any{}
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayQuery")
defer cancel()
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
if err != nil {
return false
@@ -333,7 +335,8 @@ func (c *WalMartImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo
func (c *WalMartImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supply_model.MsgModel {
params := map[string]any{}
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayQueryV2")
defer cancel()
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
if err != nil {
return supply_model.CardMsgErr
@@ -412,7 +415,8 @@ func (c *WalMartImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
if err != nil {
return config.PAYFOR_FAIL, ""
}
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayForQuery")
defer cancel()
params := map[string]string{}
params["order_id"] = payFor.BankOrderId
params["app_key"] = gojson.Json("").Get("appKey").Tostring()

View File

@@ -148,7 +148,8 @@ func (c *WalmartSelfImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, r
// KMEncrypt 加密卡密
func (c *WalmartSelfImpl) kMEncrypt(kf, appSecret string) (string, error) {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "kMEncrypt")
defer cancel()
secret := utils.GetMD5LOWER(appSecret)[:16] // 加密秘钥
block, err := aes.NewCipher([]byte(secret))
@@ -165,7 +166,8 @@ func (c *WalmartSelfImpl) kMEncrypt(kf, appSecret string) (string, error) {
}
func (c *WalmartSelfImpl) PayNotify() {
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayNotify")
defer cancel()
otelTrace.Logger.WithContext(ctx).Info("【沃尔玛】回调开始")
attach := strings.TrimSpace(c.GetString("merchantId"))
orderInfo := order.GetOrderByBankOrderId(ctx, attach) // OrderId
@@ -218,7 +220,8 @@ func (c *WalmartSelfImpl) PayNotify() {
func (c *WalmartSelfImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
params := map[string]any{}
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayQuery")
defer cancel()
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
if err != nil {
return false
@@ -276,7 +279,8 @@ func (c *WalmartSelfImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.Road
func (c *WalmartSelfImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supply_model.MsgModel {
params := map[string]any{}
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayQueryV2")
defer cancel()
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
if err != nil {
return supply_model.CardMsgErr
@@ -351,7 +355,8 @@ func (c *WalmartSelfImpl) PayFor(info payfor.PayforInfo) string {
func (c *WalmartSelfImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
cfg := config.Config{}
ctx := context.Background()
ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "", "PayForQuery")
defer cancel()
url, err := cfg.GetMFCardQueryUrl()
if err != nil {
return config.PAYFOR_FAIL, ""

24
main.go
View File

@@ -16,18 +16,18 @@ import (
)
func main() {
// cleanup1, cleanup2, cleanup3 := otelTrace.InitTracer()
// defer func() {
// if cleanup1 != nil {
// _ = cleanup1(otelTrace.InitCtx)
// }
// if cleanup2 != nil {
// _ = cleanup2(otelTrace.InitCtx)
// }
// if cleanup3 != nil {
// _ = cleanup3(otelTrace.InitCtx)
// }
// }()
cleanup1, cleanup2, cleanup3 := otelTrace.InitTracer()
defer func() {
if cleanup1 != nil {
_ = cleanup1(otelTrace.InitCtx)
}
if cleanup2 != nil {
_ = cleanup2(otelTrace.InitCtx)
}
if cleanup3 != nil {
_ = cleanup3(otelTrace.InitCtx)
}
}()
go notify.CreateOrderNotifyConsumer(otelTrace.InitCtx)
go query.CreatePayForQueryConsumer(otelTrace.InitCtx)
go service.OrderSettleInit(otelTrace.InitCtx)