Jelajahi Sumber

提交测试代码修改

DESKTOP-HN5QP3V\Administrator 3 hari lalu
induk
melakukan
85df664724

+ 3 - 2
app/service/subscribe.go

@@ -157,13 +157,14 @@ func (this *SubscribeTaskService) Task() error {
 
 	switch this.Module {
 	case "hangup":
-		key = fmt.Sprintf("$s_hangup", this.DeviceId)
+		key = fmt.Sprintf("%s_hangup", this.DeviceId)
 	case "autofight":
-		key = fmt.Sprintf("$s_autofight", this.DeviceId)
+		key = fmt.Sprintf("%s_autofight", this.DeviceId)
 	default:
 		return errors.New("unknown module")
 	}
 
+	this.Timestamp = util.GetNowSecond() + 5*1000
 	task.SubscribeTask.Append(key, this.DeviceId, this.Timestamp, this.Module)
 
 	return nil

+ 5 - 6
app/task/subscribe.go

@@ -34,23 +34,22 @@ func SubscribeInit() *Subscribe {
 func (this *Subscribe) Exec() {
 	now := util.GetNowSecond()
 
-	var needPush []string
+	var needPush []*PushItem
 
 	this.Lock()
 	for key, item := range this.waiting {
 		if item.Timestamp <= now {
-			needPush = append(needPush, key)
-			delete(this.waiting, key) // 触发后移除,防止重复
+			needPush = append(needPush, item)
+			delete(this.waiting, key)
 		}
 	}
 	this.Unlock()
 
-	for _, key := range needPush {
-		item := this.waiting[key]
+	for _, item := range needPush {
 		this.sender.Send(&sender.SubscribeSend{
 			DeviceId: item.DeviceId,
 			Module:   item.Module,
-		})
+		}) // 触发后移除,防止重复
 	}
 }
 

+ 3 - 0
config/.env.local

@@ -11,3 +11,6 @@ LISTEN_PORT=8765
 REDIS_DB=0
 REDIS_ADDR="127.0.0.1:6379"
 REDIS_PW=""
+WECHAT_APPID="wx4e85c6fbd4e0b279"
+WECHAT_SECRET="6df059f9ff00a3bce5b03b8eaf00d453"
+

+ 3 - 2
pkg/helper/wechat/wechatHelper.go

@@ -33,7 +33,7 @@ const (
 
 func NewWechatHelper() *WechatHelper {
 	appID := os.Getenv("WECHAT_APPID")
-	appSecret := os.Getenv("WECHAT_SECERT")
+	appSecret := os.Getenv("WECHAT_SECRET")
 	wx := wechat.NewWechat(&wechat.Config{
 		AppID:     appID,
 		AppSecret: appSecret,
@@ -85,9 +85,10 @@ func (this *WechatHelper) SendWechatSubscribe(openid string, template string, ms
 	}
 	if re.Errcode != 0 {
 		if re.Errcode == 40003 || re.Errcode == 43101 { //openid无效,appid与openid不匹配, 用户未订阅消息(用户未在近两小时访问小程序)
+			logger.Info("CheckWechatMsg msg: %s ret: %d errmsg: %s", msg, re.Errcode, re.Errmsg)
 			return 0
 		}
-		logger.Info("CheckWechatMsg msg:", msg, " ret:", re.Errcode, " errmsg:", re.Errmsg)
+
 	} else {
 		if re.Result.Label != 100 && re.Result.Label != 0 {
 			logger.Info("[ERROR]CheckWechatMsg msg:", msg, " ret:", re.Result.Label, " ,suggest:", re.Result.Suggest)

+ 9 - 0
pkg/util/common.go

@@ -20,6 +20,15 @@ var (
 	milliSec int64 = getMilliSec() //毫秒数
 )
 
+func init() {
+	go func() {
+		for {
+			time.Sleep(time.Millisecond)
+			atomic.StoreInt64(&milliSec, getMilliSec())
+		}
+	}()
+}
+
 // RandStringRunes 返回随机字符串
 func RandStringRunes(n int) string {
 	var letterRunes = []rune("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")