收藏
回答

wechatpay-guzzle-middleware 报错提示 class找不到

<?php
declare (strict_types = 1);

namespace app\wechat\extend;


use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use WechatPay\GuzzleMiddleware\Util\PemUtil;
use WechatPay\GuzzleMiddleware\WechatPayMiddleware;
class WechatPay
{
    public function place($data)
    {
        $merchantKey=PemUtil::loadPrivateKey(app()->getRootPath().$this->merchantPrivateKey);
        $merchantCert=PemUtil::loadCertificate(app()->getRootPath().$this->wechatpayCertificate);
        $wechatpayMiddleware=WechatPayMiddleware::builder()
            ->withMerchant($this->merchantId,$this->merchantSerialNumber,$merchantKey)
            ->withWechatPay([$merchantCert])
            ->build();
        $stack=HandlerStack::create();
        $stack->push($wechatpayMiddleware);
        $client=new Client(['handler'=>$stack]);
        try {
//            $resp = $client->request('GET', 'https://api.mch.weixin.qq.com/v3/...', [ // 注意替换为实际URL
//                'headers' => [ 'Accept' => 'application/json' ]
//            ]);
//
//            echo $resp->getStatusCode().' '.$resp->getReasonPhrase()."\n";
//            echo $resp->getBody()."\n";
            $data['appid']=$this->APPID;
            $data['mchid']=$this->merchantId;
            $data=json_encode($data);
            $resp = $client->request('POST', $this->place_url, [
                'json' => $data,
                'headers' => [ 'Accept' => 'application/json' ]
            ]);

            $res['statusCode']=$resp->getStatusCode();
            $res['reasonPhrase']=$resp->getReasonPhrase();
            $res['body']=$resp->getBody();
            return  $res;
        } catch (\RangeException $e) {
            // 进行错误处理
            echo $e->getMessage()."\n";
            if ($e->hasResponse()) {
                echo $e->getResponse()->getStatusCode().' '.$e->getResponse()->getReasonPhrase()."\n";
                echo $e->getResponse()->getBody();
            }
            return;
        }
    }
}

#0 [0]Error in WechatPay.php line 26

Class 'WechatPay\GuzzleMiddleware\Util\PemUtil' not found

报错class找不到,这个问题怎么解决,使用的是thinkphp6

回答关注问题邀请回答
收藏

2 个回答

  • 细🐟
    细🐟
    2021-09-17
    require_once 'vendor/autoload.php';//必定是未引入这个
    
    2021-09-17
    有用
    回复
  • 北望沣渭
    北望沣渭
    2021-04-23

    先从PHP软件包管理工具`composer`开始,工程化软件开发。 -> https://getcomposer.org

    2021-04-23
    有用
    回复
登录 后发表内容