# 安装 Stripe CLI 在 macOS、Windows 或 Linux 上安装 Stripe CLI。 通过 Stripe CLI,您可以从命令行构建、测试和管理您的集成。您可以使用 Stripe CLI 执行以下操作: - 在沙盒中创建、检索、更新或删除任何 Stripe 资源。 - 推送实时 API 请求和您的账户中发生的事件。 - 触发事件以测试 Webhook 集成。 更多详情请参阅 [Stripe CLI 参考](https://docs.stripe.com/cli.md)。 [Watch on YouTube](https://www.youtube.com/watch?v=iFwBGI-kqeE) ## 安装 Stripe CLI 在命令行中,使用一个安装脚本或为您的操作系统下载并提取一个有版本号的归档文件,完成 CLI 的安装。 #### homebrew 要用 [homebrew](https://brew.sh/) 安装 Stripe CLI,请运行: ```bash brew install stripe/stripe-cli/stripe ``` #### apt CLI 的 Debian 版本可在 [JFrog](https://packages.stripe.dev) 上获取,该域名不归 Stripe 所有。当您访问此 URL 时,它会将您重定向到 Jfrog artifactory 列表。 要在基于 Debian 和 Ubuntu 的发行版本上安装 Stripe CLI: 1. 将 Stripe CLI 的 GPG 密钥添加到 apt 源密钥环中: ```bash curl -s https://packages.stripe.dev/api/security/keypair/stripe-cli-gpg/public | gpg --dearmor | sudo tee /usr/share/keyrings/stripe.gpg > /dev/null ``` 1. 将 CLI 的 apt 存储库添加到 apt 源列表: ```bash echo "deb [signed-by=/usr/share/keyrings/stripe.gpg] https://packages.stripe.dev/stripe-cli-debian-local stable main" | sudo tee -a /etc/apt/sources.list.d/stripe.list ``` 1. 更新软件包列表: ```bash sudo apt update ``` 1. 安装 CLI: ```bash sudo apt install stripe ``` #### yum CLI 的 RPM 版本可在 [JFrog](https://packages.stripe.dev) 上获取,该域名不归 Stripe 所有。当您访问此 URL 时,它会将您重定向到 Jfrog artifactory 列表。 要在基于 RPM 的发行版本上安装 Stripe CLI: 1. 将 CLI 的 yum repository 添加到 yum 源列表: ```bash echo -e "[Stripe]\nname=stripe\nbaseurl=https://packages.stripe.dev/stripe-cli-rpm-local/\nenabled=1\ngpgcheck=0" >> /etc/yum.repos.d/stripe.repo ``` 1. 安装 CLI: ```bash sudo yum install stripe ``` #### Scoop 要用 [Scoop](https://scoop.sh/) 安装 Stripe CLI,请运行: ```bash scoop bucket add stripe https://github.com/stripe/scoop-stripe-cli.git ``` ```bash scoop install stripe ``` #### macOS 要在没有 homebrew 的 macOS 上安装 Stripe CLI: 1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载您的 CPU 结构类型的最新的 `mac-os` tar.gz 文件。 1. 解压文件:`tar -xvf stripe_[X.X.X]_mac-os_[ARCH_TYPE].tar.gz`。 也可以将二进制文件安装在可以全局执行的位置(例如,`/usr/local/bin`)。 #### Linux 要在没有软件包管理器的 Linux 上安装 Stripe CLI: 1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载最新的 `linux` tar.gz 文件。 1. 解压文件: `tar -xvf stripe_X.X.X_linux_x86_64.tar.gz`. 1. 将 `./stripe` 移到您的执行路径。 #### Windows 要在没有 Scoop 的 Windows 上安装 Stripe CLI: 1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载最新的 `windows` zip 文件 1. 解压 `stripe_X.X.X_windows_x86_64.zip` 文件。 1. 将解压缩后的 `stripe.exe` 文件的路径添加到 `Path` 环境变量中。要了解如何更新环境变量,请参见 [Microsoft PowerShell 文档](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.3#saving-changes-to-environment-variables)。 Windows 防病毒扫描程序有时会将 Stripe CLI 标记为不安全。这很可能是误报。有关更多信息,请参阅 GitHub 存储库中的 [Issue #692](https://github.com/stripe/stripe-cli/issues/692)。 #### Docker Stripe CLI 也可以作为 [Docker 镜像](https://hub.docker.com/r/stripe/stripe-cli)提供。要安装最新版本,请运行: ```bash docker run --rm -it stripe/stripe-cli:latest ``` ## 登入 CLI 1. 登录您的 Stripe 用户[账户](https://docs.stripe.com/get-started/account/set-up.md)并进行身份验证,以生成一组受限密钥。如需了解更多信息,请参阅 [Stripe CLI 密钥和权限](https://docs.stripe.com/stripe-cli/keys.md)。 ```bash stripe login ``` 1. 在浏览器中按键盘上的**回车键**以完成认证流程。 ```bash Your pairing code is: enjoy-enough-outwit-win This pairing code verifies your authentication with Stripe. Press Enter to open the browser or visit https://dashboard.stripe.com/stripecli/confirm_auth?t=THQdJfL3x12udFkNorJL8OF1iFlN8Az1 (^C to quit) ``` 如果您不想使用浏览器,可以选择通过现有的 API 密钥或受限的密钥用 `--interactive` 标志进行身份验证。这在没有浏览器的情况下对 CLI 进行身份验证时很有帮助,例如在 CI/CD 管道中。 ```bash stripe login --interactive ``` 您还可以使用 `--api-key` 标志,以便在每次发送请求时内联指定您的 API 密钥。 ```bash stripe login --api-key <> ```