Browse Source

audio file encrypt , CPA update

dujunchen 2 weeks ago
parent
commit
55227dc75d
3 changed files with 14 additions and 7 deletions
  1. 1 3
      cmd/main.go
  2. 5 1
      internal/app/ami/action/index.go
  3. 8 3
      pkg/utils/file.go

+ 1 - 3
cmd/main.go

@@ -6,7 +6,6 @@ import (
 	"pbx-api-gin/pkg/lfshook"
 	"pbx-api-gin/pkg/utils"
 
-	"github.com/gin-gonic/gin"
 	"github.com/sirupsen/logrus"
 	"gopkg.in/natefinch/lumberjack.v2"
 )
@@ -26,8 +25,7 @@ func main() {
 
 	configs.ConfigGlobal.LogLevel = logrus.InfoLevel
 
-	gin.SetMode(gin.ReleaseMode)
-
+	//gin.SetMode(gin.ReleaseMode)
 	//gin.SetMode(gin.DebugMode)
 
 	lfshook.NewLogger().Logger.SetReportCaller(true)

+ 5 - 1
internal/app/ami/action/index.go

@@ -110,7 +110,7 @@ func HandleAMI(event map[string]string) {
 			DstFile := ""
 			if len(FileNames) > 0 { // 文件切割之后进入循环处理
 				for _, file := range FileNames {
-					DstFile = fmt.Sprintf("%s.bin", file)
+					DstFile = fmt.Sprintf("encrypted-%s", file)
 
 					lfshook.NewLogger().Infof("===========Bin file====%s", DstFile)
 					err = utils.AudioFileEncode(DstFile, file)
@@ -173,6 +173,10 @@ func HandleAMI(event map[string]string) {
 				if priority.CheckPriority("CPA") {
 					if active.ActivedCab == "" { //No active Signal on both side,Hangup caller
 						Hangup(event["CallerIDNum"])
+					} else if active.ActivedCab == "1" && event["CallerIDNum"] == "1411" {
+						Hangup(event["CallerIDNum"])
+					} else if active.ActivedCab == "8" && event["CallerIDNum"] == "1481" {
+						Hangup(event["CallerIDNum"])
 					}
 
 					//hangup others if priority is higher

+ 8 - 3
pkg/utils/file.go

@@ -48,6 +48,7 @@ func GetDuration(filePath string) (int, error) {
 }
 
 func AudioFileEncode(dstFile, srcFile string) error {
+	// Step 1:获取 Base64 编码结果
 	data := "sripis123"
 	encoded := base64.StdEncoding.EncodeToString([]byte(data))
 
@@ -70,13 +71,17 @@ func AudioFileEncode(dstFile, srcFile string) error {
 	}
 	defer audioFile.Close()
 
-	// Step 4: 将 audio.wav 的内容追加到 output.bin 文件末尾
-	_, err = audioFile.Seek(0, io.SeekStart) // 确保从文件开头读取
+	// Step 4: 读取源文件的全部内容
+	data1, err := io.ReadAll(audioFile)
 	if err != nil {
 		return err
 	}
 
-	_, err = io.Copy(outputFile, audioFile)
+	// Step 5: 对读取的内容进行 Base64 编码
+	encoded1 := base64.StdEncoding.EncodeToString(data1)
+
+	// Step 6: 写入 Base64 编码后的内容
+	_, err = outputFile.WriteString(encoded1)
 	if err != nil {
 		return err
 	}