PHP code example of lujihong / easywechat6
1. Go to this page and download the library: Download lujihong/easywechat6 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/ */
lujihong / easywechat6 example snippets
Router::addRoute(['GET', 'POST', 'HEAD'], '/wechat', 'App\Controller\WeChatController@serve');
declare(strict_types=1);
namespace App\Controller;
use EasyWeChat\Kernel\Exceptions\BadRequestException;
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
use Hyperf\EasyWechat\EasyWechat;
use function response;
use ReflectionException;
class WeChatController
{
/**
* 处理微信的请求消息
*
* @return string
* @throws BadRequestException
* @throws InvalidArgumentException
* @throws InvalidConfigException
* @throws ReflectionException
*/
public function serve()
{
$app = EasyWechat::officialAccount();
$server = $app->getServer();
$server->with(function ($message, \Closure $next) {
return '谢谢关注!';
// 自定义逻辑
// return $next($message);
});
// response转换
return response($server->serve());
}
}
use Hyperf\EasyWechat\EasyWechat;
$officialAccount = EasyWechat::officialAccount(); //公众号
$pay = EasyWechat::pay(); //微信支付
$miniApp = EasyWechat::miniApp(); //小程序
$openPlatform = EasyWechat::openPlatform(); //开放平台
$work = EasyWechat::work(); //企业微信
$openWork = EasyWechat::openWork(); //企业微信开放平台
// `foo` 为配置文件中的名称,默认为 `default`。`[]` 可覆盖账号配置
EasyWeChat::officialAccount('foo', []);
shell script
php ./bin/hyperf.php vendor:publish lujihong/easywechat6