#!/bin/bash # get_feishu_token.sh - 获取飞书 tenant_access_token set -e APP_ID="${FEISHU_APP_ID:-cli_a91b01debab81cd1}" APP_SECRET="${FEISHU_APP_SECRET:-}" if [ -z "$APP_SECRET" ]; then # 尝试从 .env 文件读取 if [ -f "$HOME/.hermes/.env" ]; then APP_SECRET=$(grep "FEISHU_APP_SECRET" "$HOME/.hermes/.env" | cut -d'=' -f2) fi fi if [ -z "$APP_SECRET" ]; then echo "Error: FEISHU_APP_SECRET not set" echo "Please set it in ~/.hermes/.env or environment variable" exit 1 fi RESPONSE=$(curl -s -X POST \ https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal \ -H "Content-Type: application/json" \ -d "{\"app_id\":\"$APP_ID\",\"app_secret\":\"$APP_SECRET\"}") CODE=$(echo "$RESPONSE" | grep -o '"code":[0-9]*' | cut -d':' -f2) if [ "$CODE" != "0" ]; then echo "Error: Failed to get token" echo "$RESPONSE" exit 1 fi TOKEN=$(echo "$RESPONSE" | grep -o '"tenant_access_token":"[^"]*"' | cut -d'"' -f4) EXPIRE=$(echo "$RESPONSE" | grep -o '"expire":[0-9]*' | cut -d':' -f2) echo "Token: $TOKEN" echo "Expire: $EXPIRE seconds ($(($EXPIRE / 60)) minutes)" # 保存 token 到临时文件 mkdir -p /sdcard/feishu echo "$TOKEN" > /sdcard/feishu/token echo "Token saved to /sdcard/feishu/token"