PHP code example of limingxinleo / swoft-easywechat
1. Go to this page and download the library: Download limingxinleo/swoft-easywechat 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/ */
limingxinleo / swoft-easywechat example snippets
namespace App\Core\Wechat;
use App\Core\Wechat\Config\OfficialAccountConfig;
use Swoftx\EasyWeChat\Factory;
use Xin\Swoft\Traits\InstanceTrait;
/**
* Class OfficialAccount
* @package App\Core\Wechat
*/
class OfficialAccount
{
use InstanceTrait;
/**
* @var OfficialAccountConfig
*/
public $config;
public $app;
public function __construct()
{
$this->config = bean(OfficialAccountConfig::class);
$dir = alias('@runtime/logs');
$config = [
'app_id' => $this->config->getAppId(),
'secret' => $this->config->getSecret(),
'token' => $this->config->getToken(),
'aes_key' => $this->config->getAesKey(),
// 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
'response_type' => 'array',
'log' => [
'level' => 'debug',
'file' => $dir . '/wechat.log',
],
];
$this->app = Factory::officialAccount($config);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.