使用BTCPay Server Greenfield PHP API认证失败及数组转字符串问题求助
BTCPayServer Greenfield PHP 创建发票认证失败及数组转字符串警告问题
环境版本
"btcpayserver/btcpayserver-greenfield-php": "^2.8"
错误信息
向https://mainnet.demo.btcpayserver.org/api/v1/stores/__STORE_ID/invoices发起POST请求时出错。收到响应(401):{"code":"unauthenticated","message":"Authentication is required for accessing this endpoint"}
Warning: Array to string conversion in D:\xampp\htdocs\my_app\path to file.php on line 79
Array
代码实现
类代码片段
use BTCPayServer\Client\Invoice; use BTCPayServer\Client\InvoiceCheckoutOptions; use BTCPayServer\Util\PreciseNumber;
public function createInvoice($amount, $orderId, $buyerEmail) { // 创建基础发票 try { $client = new Invoice($this->host, $this->apiKey); $result = $client->createInvoice( $this->storeId, $this->currency, PreciseNumber::parseString($amount), $orderId, $buyerEmail ); return $result; } catch (\Exception $e) { echo "Error: " . $e->getMessage(); echo $e->getTrace(); } }
调用代码
require_once "vendor/autoload.php"; use Dotenv\Dotenv; $dotenv = Dotenv::createImmutable(__DIR__); $dotenv->load(); $ObjBtcServer = new \MyApp\CryptoDepositClasses\BTCPayServerClass(); print_r($ObjBtcServer->createInvoice(amount: '600', orderId: "#303", buyerEmail: 'email@gmail.com'));
问题说明
已从BTCPayServer仪表盘获取Store ID和API Key,但调用创建发票接口时持续返回401未认证错误,同时无法定位代码中"Array to string conversion"警告的来源,求解决办法。
内容的提问来源于stack exchange,提问作者Meshach
相关产品推荐
相关产品推荐

