diff --git a/CHANGELOG.md b/CHANGELOG.md index 3663bd3d1bed9798c8587f763f1d2879459dee4b..b14038fc75543491b07fbabe9f65e395963a8f7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - 修改播控 - 增加一个http的入口 - 增加国学 +- 增加删除SessionId ## [0.0.1-beta.2] - 2025.5.29 ### Changed diff --git a/c2c.http b/c2c.http index cc92425895130d36a213f8258b43dc76e4dbf9ef..f9f80982fdbef09404ee639700924a9c2be8d307 100644 --- a/c2c.http +++ b/c2c.http @@ -5,7 +5,7 @@ Content-Type: application/json "ip": "14.215.222.17", "mac": "ece154a865eb", "mid": "11011", - "query":"播放弟子规", + "query":"哈哈", "requestId": "123456111" } @@ -17,7 +17,7 @@ Content-Type: application/json "ip": "14.215.222.17", "mac": "ece154a865eb", "mid": "11011", - "query":"播放弟子规", + "query":"天使的翅膀", "requestId": "123456111" } @@ -38,7 +38,7 @@ Content-Type: application/json "trafficParameter": "mode=childxxx;macWifi=28b77c218ed1;mid=10f05;vender=7e000025;macVoice=testyuntiancloud;ver=3.0;scenario=smarthome;filterName=nlu;req_nlu_length=1;returnType=json;fullDuplex=true;appendLength=1;additionalService=geli_nlu2;version=0.5;filterUrl=https://testnlu.gree.com:443/semantic/unisoundc2c/querys;" }, "nluRet": { - "text": "播放海来阿木的专辑" + "text": "天使的翅膀" }, "postProc": {} } @@ -57,7 +57,7 @@ Content-Type: application/json }, "nluRet": { "asr_recongize": "", - "text": "珠海在哪里" + "text": "播放歌曲大菠萝" } }, "version": "v0" @@ -79,7 +79,7 @@ Content-Type: application/json "trafficParameter": "mode=childxx;macWifi=ece154a73d38;mid=11011;macVoice=testyuntiancloud;ver=3.0;scenario=smarthome;filterName=nlu;req_nlu_length=1;returnType=json;fullDuplex=true;appendLength=1;additionalService=geli_nlu2;version=0.5;filterUrl=https://testnlu.gree.com:443/semantic/unisoundc2c/querys;" }, "nluRet": { - "text": "播放国学故事" + "text": "休息吧" }, "postProc": {} } diff --git a/pkg/database/redis.go b/pkg/database/redis.go index 6c7e0c361784f15fabea95c440ae6558b9db3f04..039a87f1a2ea6e6c6dbb3ac0b55498d3a2331809 100644 --- a/pkg/database/redis.go +++ b/pkg/database/redis.go @@ -66,6 +66,21 @@ func GetSession(mac string) (string, error) { return sessionId, nil } +// 删除 Session记录 +func DeleteSession(mac string) error { + ctx := context.Background() + key := getSessionKey(mac) + + // 删除Redis中的key + _, err := redisClient.Del(ctx, key).Result() + if err != nil { + global.Logger.Errorf("删除会话失败 (MAC: %s): %v", mac, err) + return fmt.Errorf("failed to delete session: %w", err) + } + + return nil +} + // 获取会话并自动续期 func GetAndRefreshSession(mac string, expiration time.Duration) (string, bool) { ctx := context.Background() diff --git a/service/speechNlu/domain.go b/service/speechNlu/domain.go index 3b34bb90e5777935a72ba9b3fb32367f906e98dc..9c816b027b1c16a3703144a5274c181494aad2f1 100644 --- a/service/speechNlu/domain.go +++ b/service/speechNlu/domain.go @@ -56,6 +56,8 @@ func baseParse(params *model.SpeechDomainParams) (*model.ResponseBody, error) { if !params.SpeechWsResp.Dm.ShouldEndSession { fmt.Println("保存:", params.SpeechWsResp.SessionId) database.UpdateSession(params.Mac, params.SpeechWsResp.SessionId) + } else { + database.DeleteSession(params.Mac) } //UpdateSession(params.Mac, params.SpeechWsResp.SessionId) @@ -479,6 +481,8 @@ func alarmDomain(params *model.SpeechDomainParams) []byte { //UpdateSession(params.Mac, params.SpeechWsResp.SessionId) database.UpdateSession(params.Mac, params.SpeechWsResp.SessionId) return Marshal(params, &result) + } else { + database.DeleteSession(params.Mac) } if !params.CheckDm() || !params.CheckCommandParam() { @@ -796,6 +800,8 @@ func musicDomain(params *model.SpeechDomainParams) []byte { if !params.SpeechWsResp.Dm.ShouldEndSession { fmt.Println("保存:", params.SpeechWsResp.SessionId) database.UpdateSession(params.Mac, params.SpeechWsResp.SessionId) + } else { + database.DeleteSession(params.Mac) } list, err := connect.MusicGrpc(params) @@ -899,6 +905,8 @@ func financeDomain(params *model.SpeechDomainParams) []byte { if !params.SpeechWsResp.Dm.ShouldEndSession { fmt.Println("保存:", params.SpeechWsResp.SessionId) database.UpdateSession(params.Mac, params.SpeechWsResp.SessionId) + } else { + database.DeleteSession(params.Mac) } var result model.ResponseBody @@ -922,6 +930,8 @@ func convertDomain(params *model.SpeechDomainParams) []byte { if !params.SpeechWsResp.Dm.ShouldEndSession { fmt.Println("保存:", params.SpeechWsResp.SessionId) database.UpdateSession(params.Mac, params.SpeechWsResp.SessionId) + } else { + database.DeleteSession(params.Mac) } var result model.ResponseBody @@ -945,6 +955,8 @@ func holidayDomain(params *model.SpeechDomainParams) []byte { if !params.SpeechWsResp.Dm.ShouldEndSession { fmt.Println("保存:", params.SpeechWsResp.SessionId) database.UpdateSession(params.Mac, params.SpeechWsResp.SessionId) + } else { + database.DeleteSession(params.Mac) } var result model.ResponseBody @@ -968,6 +980,8 @@ func speechOtherDomain(params *model.SpeechDomainParams) []byte { if !params.SpeechWsResp.Dm.ShouldEndSession { fmt.Println("保存:", params.SpeechWsResp.SessionId) database.UpdateSession(params.Mac, params.SpeechWsResp.SessionId) + } else { + database.DeleteSession(params.Mac) } var result model.ResponseBody