feat: wecom message init
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"base-service/app/dao"
|
||||
"base-service/pkg/wecom/message"
|
||||
"base-service/utils"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func GetMapString(data map[string]interface{}, key string) string {
|
||||
|
||||
val, ok := data[key]
|
||||
|
||||
if !ok || val == nil {
|
||||
return dao.StringEmpty
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%v", val)
|
||||
}
|
||||
|
||||
func GetExtString(ext map[string]any, key string) string {
|
||||
|
||||
v, ok := ext[key].(string)
|
||||
if !ok || v == "" {
|
||||
return "无"
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func BuildContent(kvPairs ...struct{ Key, Value string }) []message.HorizontalContent {
|
||||
const maxTotal = 6
|
||||
const fixedItems = 1
|
||||
maxInput := maxTotal - fixedItems
|
||||
|
||||
inputCount := len(kvPairs)
|
||||
if inputCount > maxInput {
|
||||
inputCount = maxInput
|
||||
}
|
||||
|
||||
content := make([]message.HorizontalContent, 0, inputCount+fixedItems)
|
||||
|
||||
for i := 0; i < inputCount; i++ {
|
||||
content = append(content, message.HorizontalContent{
|
||||
KeyName: kvPairs[i].Key,
|
||||
Value: kvPairs[i].Value,
|
||||
})
|
||||
}
|
||||
|
||||
content = append(content, message.HorizontalContent{
|
||||
KeyName: "审核时间",
|
||||
Value: utils.Now().Format(),
|
||||
})
|
||||
|
||||
return content
|
||||
}
|
||||
Reference in New Issue
Block a user