PHP code example of 943626451 / easywechat-for-hyperf

1. Go to this page and download the library: Download 943626451/easywechat-for-hyperf library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

943626451 / easywechat-for-hyperf example snippets


namespace App\Listener\PayListener;


use EasyWeChat\Factory;
use Hyperf\HttpServer\Contract\RequestInterface;

class WechatPayBase
{

    public function initPay()
    {
        $payConfig = [
            'app_id' => env('MINI_APPID'),
            'mch_id' => env('MINI_MCHID'),
            'key' => env('MINI_PAYKEY'),
            // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径
//            'cert_path' => 'path/to/your/cert.pem', // 绝对路径
//            'key_path' => 'path/to/your/key',      // 绝对路径,
            'notify_url' => env('MINI_NOTIFYURL')
        ];
        $app = Factory::payment($payConfig);
        $request = di(RequestInterface::class);//重点
        $app->rebind('request',$request);//重点
        return $app;
    }