1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- # 读取配置文件
- $scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
- $envPath = Join-Path $scriptPath "../../.env"
- # 从.env文件读取配置
- $envContent = Get-Content $envPath -Raw
- if ($envContent -match 'WECHAT_PAY_KEY=(.+)') {
- $apiV3key = $matches[1].Trim()
- } else {
- $apiV3key = Read-Host "未找到 API V3 密钥,请手动输入"
- }
- if ($envContent -match 'WECHAT_PAY_MCH_ID=(.+)') {
- $mchId = $matches[1].Trim()
- } else {
- $mchId = Read-Host "未找到商户号,请手动输入"
- }
- # 从wechat.php配置文件读取证书序列号
- $configContent = Get-Content $envPath -Raw
- if ($configContent -match 'WECHAT_PAY_SERIAL_NO=(.+)') {
- $mchSerialNo = $matches[1].Trim()
- } else {
- $mchSerialNo = Read-Host "未找到商户证书序列号,请手动输入"
- }
- # 设置证书相关路径
- $certPath = Join-Path $scriptPath "../../storage/app/certs/wechat"
- $mchPrivateKeyFilePath = Join-Path $certPath "apiclient_key.pem"
- $outputFilePath = Join-Path $certPath "wechatpay_cert.pem"
- # 确保证书目录存在
- if (-not (Test-Path $certPath)) {
- New-Item -ItemType Directory -Path $certPath -Force
- }
- Write-Host "`n证书将下载到: $outputFilePath"
- Write-Host "使用的商户私钥文件路径: $mchPrivateKeyFilePath`n"
- # 执行证书下载
- try {
- java -jar ./script/bin/CertificateDownloader-1.2.0-jar-with-dependencies.jar `
- -k $apiV3key `
- -m $mchId `
- -f $mchPrivateKeyFilePath `
- -s $mchSerialNo `
- -o $outputFilePath
- if ($LASTEXITCODE -eq 0) {
- Write-Host "`n证书下载成功!" -ForegroundColor Green
- } else {
- Write-Host "`n证书下载失败!" -ForegroundColor Red
- }
- } catch {
- Write-Host "`n发生错误: $_" -ForegroundColor Red
- }
|