合并代码
This commit is contained in:
		
							parent
							
								
									b781a61f21
								
							
						
					
					
						commit
						aa1481b923
					
				|  | @ -3,7 +3,7 @@ package common | ||||||
| const ( | const ( | ||||||
| 	TOKEN_PRE   = "player_token_" | 	TOKEN_PRE   = "player_token_" | ||||||
| 	TOKEN_Admin = "Admin_token_" | 	TOKEN_Admin = "Admin_token_" | ||||||
| 	ADMIN_V1     = "/pay/admin/api/v1 | 	ADMIN_V1    = "/pay/admin/api/v1" | ||||||
| 	FRONT_V1    = "/api/v1" | 	FRONT_V1    = "/api/v1" | ||||||
| 
 | 
 | ||||||
| 	// 支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
 | 	// 支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
 | ||||||
|  |  | ||||||
|  | @ -16,8 +16,8 @@ type AppResponse struct { | ||||||
| 	MerchantId        int64  `json:"merchant_id"` | 	MerchantId        int64  `json:"merchant_id"` | ||||||
| 	AppName           string `json:"app_name"` | 	AppName           string `json:"app_name"` | ||||||
| 	AppRemark         string `json:"app_remark"` | 	AppRemark         string `json:"app_remark"` | ||||||
| 	Status            int    `json:"status"` | 	Status            int32  `json:"status"` | ||||||
| 	KeyType           int    `json:"key_type"` | 	KeyType           int32  `json:"key_type"` | ||||||
| 	PublicKey         string `json:"public_key"` | 	PublicKey         string `json:"public_key"` | ||||||
| 	PrivateKey        string `json:"private_key"` | 	PrivateKey        string `json:"private_key"` | ||||||
| 	MerchantPublicKey string `json:"merchant_public_key"` | 	MerchantPublicKey string `json:"merchant_public_key"` | ||||||
|  | @ -45,8 +45,8 @@ type AppCreateRequest struct { | ||||||
| 	MerchantId        int64  `json:"merchant_id" validate:"required" label:"商户ID"` | 	MerchantId        int64  `json:"merchant_id" validate:"required" label:"商户ID"` | ||||||
| 	AppName           string `json:"app_name" validate:"required" label:"应用名称"` | 	AppName           string `json:"app_name" validate:"required" label:"应用名称"` | ||||||
| 	AppRemark         string `json:"app_remark" label:"应用备注"` | 	AppRemark         string `json:"app_remark" label:"应用备注"` | ||||||
| 	Status            int    `json:"status" validate:"oneof=0 1 2" label:"应用状态"` | 	Status            int32  `json:"status" validate:"oneof=0 1 2" label:"应用状态"` | ||||||
| 	KeyType           int    `json:"key_type" validate:"required" label:"应用密钥类型"` | 	KeyType           int32  `json:"key_type" validate:"required" label:"应用密钥类型"` | ||||||
| 	PublicKey         string `json:"public_key" validate:"required" label:"应用公钥"` | 	PublicKey         string `json:"public_key" validate:"required" label:"应用公钥"` | ||||||
| 	PrivateKey        string `json:"private_key" validate:"required" label:"应用私钥"` | 	PrivateKey        string `json:"private_key" validate:"required" label:"应用私钥"` | ||||||
| 	MerchantPublicKey string `json:"merchant_public_key"  label:"商户公钥"` | 	MerchantPublicKey string `json:"merchant_public_key"  label:"商户公钥"` | ||||||
|  | @ -72,8 +72,8 @@ type AppUpdateRequest struct { | ||||||
| 	Id                int64  `json:"id" validate:"required" label:"应用ID"` | 	Id                int64  `json:"id" validate:"required" label:"应用ID"` | ||||||
| 	AppName           string `json:"app_name" label:"应用名称"` | 	AppName           string `json:"app_name" label:"应用名称"` | ||||||
| 	AppRemark         string `json:"app_remark" label:"应用备注"` | 	AppRemark         string `json:"app_remark" label:"应用备注"` | ||||||
| 	Status            int    `json:"status"  label:"应用状态"` | 	Status            int32  `json:"status"  label:"应用状态"` | ||||||
| 	KeyType           int    `json:"key_type" label:"应用密钥类型"` | 	KeyType           int32  `json:"key_type" label:"应用密钥类型"` | ||||||
| 	PublicKey         string `json:"public_key"  label:"应用公钥"` | 	PublicKey         string `json:"public_key"  label:"应用公钥"` | ||||||
| 	PrivateKey        string `json:"private_key"  label:"应用私钥"` | 	PrivateKey        string `json:"private_key"  label:"应用私钥"` | ||||||
| 	MerchantPublicKey string `json:"merchant_public_key" label:"商户公钥"` | 	MerchantPublicKey string `json:"merchant_public_key" label:"商户公钥"` | ||||||
|  |  | ||||||
|  | @ -4,14 +4,15 @@ package routes | ||||||
|  * 配置路由 |  * 配置路由 | ||||||
|  */ |  */ | ||||||
| import ( | import ( | ||||||
| 	"PaymentCenter/app/constants/common" |  | ||||||
| 	"PaymentCenter/app/http/controllers" | 	"PaymentCenter/app/http/controllers" | ||||||
| 	"PaymentCenter/app/http/controllers/front" |  | ||||||
| 	"PaymentCenter/app/http/controllers/backend" | 	"PaymentCenter/app/http/controllers/backend" | ||||||
|  | 	"PaymentCenter/app/http/controllers/front" | ||||||
| 	"PaymentCenter/app/http/middlewares" | 	"PaymentCenter/app/http/middlewares" | ||||||
| 	"PaymentCenter/app/http/trace" | 	"PaymentCenter/app/http/trace" | ||||||
| 	"PaymentCenter/app/utils/metric" | 	"PaymentCenter/app/utils/metric" | ||||||
| 	"PaymentCenter/config" | 	"PaymentCenter/config" | ||||||
|  | 	ginSwagger "github.com/swaggo/gin-swagger" | ||||||
|  | 	"github.com/swaggo/gin-swagger/swaggerFiles" | ||||||
| 
 | 
 | ||||||
| 	"github.com/gin-gonic/gin" | 	"github.com/gin-gonic/gin" | ||||||
| 	"github.com/qit-team/snow-core/http/middleware" | 	"github.com/qit-team/snow-core/http/middleware" | ||||||
|  | @ -45,8 +46,6 @@ func RegisterRoute(router *gin.Engine) { | ||||||
| 	router.NoRoute(controllers.Error404) | 	router.NoRoute(controllers.Error404) | ||||||
| 
 | 
 | ||||||
| 	//router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
 | 	//router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
 | ||||||
| 	v1 := router.Group(common.FRONT_V1, middlewares.ValidateRequest()) |  | ||||||
| 	{ |  | ||||||
| 
 | 
 | ||||||
| 	v1 := router.Group("/v1") | 	v1 := router.Group("/v1") | ||||||
| 	{ | 	{ | ||||||
|  | @ -59,8 +58,6 @@ func RegisterRoute(router *gin.Engine) { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) | 	router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) | ||||||
| 		pay := v1.Group("pay", middlewares.ValidatePayRequest()) | 	pay := v1.Group("pay", middlewares.ValidatePayRequest()) | ||||||
| 		pay.POST("web", backend.MerchantList) // 商户列表
 | 	pay.POST("web", backend.MerchantList) // 商户列表
 | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -65,15 +65,7 @@ func AppUpdate(app *appmodel.App) (code int) { | ||||||
| 	} else { | 	} else { | ||||||
| 		_, err = repo.AppUpdate(app, conn) | 		_, err = repo.AppUpdate(app, conn) | ||||||
| 	} | 	} | ||||||
| 	if !has { | 	 | ||||||
| 		return errorcode.MerchantNotFound |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	// 拼接查询条件
 |  | ||||||
| 	uconn := builder.NewCond() |  | ||||||
| 	uconn = uconn.And(builder.Eq{"Id": App.Id}) |  | ||||||
| 	_, err = repo.AppUpdate(App, uconn, "app_remark") |  | ||||||
| 
 |  | ||||||
| 	code = handErr(err) | 	code = handErr(err) | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,89 +1,89 @@ | ||||||
| package mq | package mq | ||||||
| 
 | 
 | ||||||
| import ( | //
 | ||||||
| 	"PaymentCenter/app/utils" | //import (
 | ||||||
| 	"PaymentCenter/config" | //	"PaymentCenter/app/utils"
 | ||||||
| 	"context" | //	"PaymentCenter/config"
 | ||||||
| 	"encoding/json" | //	"context"
 | ||||||
| 	"fmt" | //	"fmt"
 | ||||||
| 	"github.com/Shopify/sarama" | //	"github.com/Shopify/sarama"
 | ||||||
| 	"github.com/qit-team/snow-core/redis" | //	"github.com/qit-team/snow-core/redis"
 | ||||||
| 
 | //
 | ||||||
| 	"strconv" | //	"strconv"
 | ||||||
| 	"sync" | //	"sync"
 | ||||||
| ) | //)
 | ||||||
| 
 | //
 | ||||||
| type KafkaMq struct { | //type KafkaMq struct {
 | ||||||
| } | //}
 | ||||||
| 
 | //
 | ||||||
| // 同步
 | //// 同步
 | ||||||
| func (n KafkaMq) Produce(name string, log interface{}, delayTime int, args ...interface{}) error { | //func (n KafkaMq) Produce(name string, log interface{}, delayTime int, args ...interface{}) error {
 | ||||||
| 	kafConfig := sarama.NewConfig() | //	//kafConfig := sarama.NewConfig()
 | ||||||
| 	kafConfig.Producer.RequiredAcks = sarama.WaitForAll          // 发送完数据需要leader和follow都确认
 | //	//kafConfig.Producer.RequiredAcks = sarama.WaitForAll          // 发送完数据需要leader和follow都确认
 | ||||||
| 	kafConfig.Producer.Partitioner = sarama.NewRandomPartitioner // 新选出一个partition
 | //	//kafConfig.Producer.Partitioner = sarama.NewRandomPartitioner // 新选出一个partition
 | ||||||
| 	kafConfig.Producer.Return.Successes = true                   // 成功交付的消息将在success channel返回
 | //	//kafConfig.Producer.Return.Successes = true                   // 成功交付的消息将在success channel返回
 | ||||||
| 
 | //	//
 | ||||||
| 	// 构造一个消息
 | //	//// 构造一个消息
 | ||||||
| 	msg := &sarama.ProducerMessage{} | //	//msg := &sarama.ProducerMessage{}
 | ||||||
| 	msg.Topic = name | //	//msg.Topic = name
 | ||||||
| 	var data, _ = json.Marshal(log) | //	//var data, _ = json.Marshal(log)
 | ||||||
| 	msg.Value = sarama.StringEncoder(string(data)) | //	//msg.Value = sarama.StringEncoder(string(data))
 | ||||||
| 	// 连接kafka
 | //	//// 连接kafka
 | ||||||
| 	client, err := sarama.NewSyncProducer(config.GetConf().KafkaUrl, kafConfig) | //	//client, err := sarama.NewSyncProducer(config.GetConf().KafkaUrl, kafConfig)
 | ||||||
| 	if err != nil { | //	//if err != nil {
 | ||||||
| 		fmt.Println("producer closed, err:", err) | //	//	fmt.Println("producer closed, err:", err)
 | ||||||
| 		return nil | //	//	return nil
 | ||||||
| 	} | //	//}
 | ||||||
| 	defer client.Close() | //	//defer client.Close()
 | ||||||
| 	// 发送消息
 | //	//// 发送消息
 | ||||||
| 	pid, offset, err := client.SendMessage(msg) | //	//pid, offset, err := client.SendMessage(msg)
 | ||||||
| 	if err != nil { | //	//if err != nil {
 | ||||||
| 		utils.Log(nil, "send msg failed, err:", err, pid, offset) | //	//	utils.Log(nil, "send msg failed, err:", err, pid, offset)
 | ||||||
| 		return nil | //	//	return nil
 | ||||||
| 	} | //	//}
 | ||||||
| 	return nil | //	return nil
 | ||||||
| } | //}
 | ||||||
| 
 | //
 | ||||||
| func (n KafkaMq) Consume(name string, hand interface{}) { | //func (n KafkaMq) Consume(name string, hand interface{}) {
 | ||||||
| 	consumer, err := sarama.NewConsumer(config.GetConf().KafkaUrl, nil) | //	consumer, err := sarama.NewConsumer(config.GetConf().KafkaUrl, nil)
 | ||||||
| 	if err != nil { | //	if err != nil {
 | ||||||
| 		utils.Log(nil, "kafka comsume", err.Error()) | //		utils.Log(nil, "kafka comsume", err.Error())
 | ||||||
| 		return | //		return
 | ||||||
| 	} | //	}
 | ||||||
| 	partitionList, err := consumer.Partitions(name) // 根据topic取到所有的分区
 | //	partitionList, err := consumer.Partitions(name) // 根据topic取到所有的分区
 | ||||||
| 	if err != nil { | //	if err != nil {
 | ||||||
| 		utils.Log(nil, "kafka comsume", err.Error()) | //		utils.Log(nil, "kafka comsume", err.Error())
 | ||||||
| 		return | //		return
 | ||||||
| 	} | //	}
 | ||||||
| 	//utils.Log(nil,"kafka comsume",name,partitionList)
 | //	//utils.Log(nil,"kafka comsume",name,partitionList)
 | ||||||
| 	for partition := range partitionList { // 遍历所有的分区
 | //	for partition := range partitionList { // 遍历所有的分区
 | ||||||
| 		// 针对每个分区创建一个对应的分区消费者
 | //		// 针对每个分区创建一个对应的分区消费者
 | ||||||
| 		var offsetReDis, _ = redis.GetRedis().Incr(context.Background(), "kafka_consume:"+strconv.Itoa(int(partition))).Result() //保证多消费者不重复消费
 | //		var offsetReDis, _ = redis.GetRedis().Incr(context.Background(), "kafka_consume:"+strconv.Itoa(int(partition))).Result() //保证多消费者不重复消费
 | ||||||
| 		var offset int64 = sarama.OffsetNewest | //		var offset int64 = sarama.OffsetNewest
 | ||||||
| 		if offsetReDis > 0 { | //		if offsetReDis > 0 {
 | ||||||
| 			//offset = int64(offsetReDis)
 | //			//offset = int64(offsetReDis)
 | ||||||
| 		} | //		}
 | ||||||
| 		pc, err := consumer.ConsumePartition(name, int32(partition), offset) | //		pc, err := consumer.ConsumePartition(name, int32(partition), offset)
 | ||||||
| 		//utils.Log(nil,"partion",int32(partition))
 | //		//utils.Log(nil,"partion",int32(partition))
 | ||||||
| 		if err != nil { | //		if err != nil {
 | ||||||
| 			fmt.Printf("failed to start consumer for partition %d,err:%v\n", partition, err) | //			fmt.Printf("failed to start consumer for partition %d,err:%v\n", partition, err)
 | ||||||
| 			return | //			return
 | ||||||
| 		} | //		}
 | ||||||
| 		defer pc.AsyncClose() | //		defer pc.AsyncClose()
 | ||||||
| 		var wg sync.WaitGroup | //		var wg sync.WaitGroup
 | ||||||
| 		wg.Add(1) | //		wg.Add(1)
 | ||||||
| 		// 异步从每个分区消费信息
 | //		// 异步从每个分区消费信息
 | ||||||
| 		go func(sarama.PartitionConsumer) { | //		go func(sarama.PartitionConsumer) {
 | ||||||
| 			for msg := range pc.Messages() { | //			for msg := range pc.Messages() {
 | ||||||
| 				defer wg.Done() | //				defer wg.Done()
 | ||||||
| 				var handler = hand.(func(tag uint64, ch interface{}, msg []byte)) | //				var handler = hand.(func(tag uint64, ch interface{}, msg []byte))
 | ||||||
| 				handler(0, nil, msg.Value) | //				handler(0, nil, msg.Value)
 | ||||||
| 				//utils.Log(nil,"hand msg",string(msg.Value),msg.Offset)
 | //				//utils.Log(nil,"hand msg",string(msg.Value),msg.Offset)
 | ||||||
| 			} | //			}
 | ||||||
| 		}(pc) | //		}(pc)
 | ||||||
| 		wg.Wait() | //		wg.Wait()
 | ||||||
| 	} | //	}
 | ||||||
| } | //}
 | ||||||
| func (n KafkaMq) DelyConsume(name string, hand interface{}) { | //func (n KafkaMq) DelyConsume(name string, hand interface{}) {
 | ||||||
| 
 | //
 | ||||||
| } | //}
 | ||||||
|  |  | ||||||
							
								
								
									
										7
									
								
								go.mod
								
								
								
								
							
							
						
						
									
										7
									
								
								go.mod
								
								
								
								
							|  | @ -117,17 +117,12 @@ require ( | ||||||
| 	go.uber.org/atomic v1.9.0 // indirect | 	go.uber.org/atomic v1.9.0 // indirect | ||||||
| 	go.uber.org/multierr v1.6.0 // indirect | 	go.uber.org/multierr v1.6.0 // indirect | ||||||
| 	go.uber.org/zap v1.21.0 // indirect | 	go.uber.org/zap v1.21.0 // indirect | ||||||
|  | 	golang.org/x/arch v0.6.0 // indirect | ||||||
| 	golang.org/x/crypto v0.25.0 // indirect | 	golang.org/x/crypto v0.25.0 // indirect | ||||||
| 	golang.org/x/net v0.25.0 // indirect | 	golang.org/x/net v0.25.0 // indirect | ||||||
| 	golang.org/x/sync v0.7.0 // indirect | 	golang.org/x/sync v0.7.0 // indirect | ||||||
| 	golang.org/x/sys v0.22.0 // indirect | 	golang.org/x/sys v0.22.0 // indirect | ||||||
| 	golang.org/x/text v0.16.0 // indirect | 	golang.org/x/text v0.16.0 // indirect | ||||||
| 	golang.org/x/arch v0.6.0 // indirect |  | ||||||
| 	golang.org/x/crypto v0.17.0 // indirect |  | ||||||
| 	golang.org/x/net v0.17.0 // indirect |  | ||||||
| 	golang.org/x/sync v0.1.0 // indirect |  | ||||||
| 	golang.org/x/sys v0.15.0 // indirect |  | ||||||
| 	golang.org/x/text v0.14.0 // indirect |  | ||||||
| 	golang.org/x/time v0.1.0 // indirect | 	golang.org/x/time v0.1.0 // indirect | ||||||
| 	golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect | 	golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect | ||||||
| 	google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect | 	google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue