namespace app\index\controller;
require_once(root_path() . 'vendor/autoload.php');
use app\BaseController;
use WeChatPay\Builder;
use WeChatPay\Crypto\Rsa;
use WeChatPay\Formatter;
public function index(){
$timestamp = Formatter::timestamp(); // 生成时间戳 $timestamp,$nonce,
//$nonce = Formatter::nonce(); // 生成随机串
dump($timestamp);return;
}
使用的是thinkphp8,已把wechatpay放在了vendor文件夹中, 调试 index 方法出现这个问题,请问是什么原因?
Class "WeChatPay\Formatter
" not found,
求指教
谢谢你的指点。 vendor与app同级, require_once __DIR__ . '/vendor/autoload.php';加载不了文件;出现如下错误: require_once(/www/wwwroot/www.域名.top/app/index/controller/vendor/autoload.php): Failed to open stream: No such file or directory 用 require_once(root_path() . 'vendor/autoload.php');错误:Formatter 类未找到! 异常信息:Class "WeChatPay\Formatter" not found
<?php require_once __DIR__ . '/vendor/autoload.php'; // 确保正确加载 Composer use WeChatPay\Formatter; try { // 尝试调用 Formatter 类的方法 $timestamp = Formatter::timestamp(); echo "Formatter 类加载成功,生成的时间戳:$timestamp"; } catch (\Throwable $e) { echo "错误:Formatter 类未找到!" . PHP_EOL; echo "异常信息:" . $e->getMessage(); }
试试上面代码,看看能不能正常加载