meteorlxy / laravel-wechat
This package is abandoned and no longer maintained.
No replacement package was suggested.
Wechat package for Laravel
0.1.4
2017-09-26 14:05 UTC
Requires
- php: >=5.5.0
- guzzlehttp/guzzle: ^6.3
- illuminate/cache: 5.*
- illuminate/http: 5.*
- illuminate/support: 5.*
- nesbot/carbon: ^1.22
README
个人边学习边开发的Wechat SDK for Laravel
还远远没有完成
部分内容参考自overtrue/wechat 和 overtrue/laravel-wechat
使用说明
- 使用Composer引入
composer require meteorlxy/laravel-wechat
- 注册ServiceProvider
在config/app.php
中加入
'providers' => [ ... Meteorlxy\LaravelWechat\WechatServiceProvider::class, ]
- 配置文件
运行以下命令,将在config/
文件夹下生成wechat.php
文件
php artisan vendor:publish
可以直接修改wechat.php
,也可以在.env
中添加如下变量覆盖默认配置
WECHAT_APPID
WECHAT_APPSECRET
WECHAT_TOKEN
WECHAT_AES_KEY
WECHAT_SERVER
WECHAT_TIMEOUTE
- 使用
<?php namespace App\Http\Controllers\Wechat; use Illuminate\Http\Request; use Meteorlxy\LaravelWechat\Controllers\WechatController as BaseController; class WechatController extends BaseController { public function listen() { $this->wechat->server->setHandler(function($message) { switch($message->MsgType) { case 'event' : $text = '处理文字消息'; break; case 'event' : $text = '处理事件消息'; break; default: $text = '默认处理器'; break; } return [ 'Content' => $text, // 若不设置MsgType,默认回复为Text消息,则必须设置Content 'MsgType' => 'text', // 若不设置FromUserName和ToUserName,默认回复给消息来源用户 'FromUserName' => $message->ToUserName, 'ToUserName' => $message->FromUserName, ]; }); return $this->wechat->server->handle($request); } }