Skip to content

Commit f55d6f9

Browse files
committed
bugfix for overtrue#6
1 parent 78206df commit f55d6f9

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

README.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
微信 SDK for Laravel 5, 基于 [overtrue/wechat](https://github.com/overtrue/wechat)
44

5+
本项目只适用于,只有一个固定的账号,如果是开发微信公众号管理系统就不要使用了,直接用 [overtrue/wechat](https://github.com/overtrue/wechat) 更方便些。
6+
57
## 安装
68

79
1. 安装包文件
@@ -23,21 +25,30 @@
2325

2426
然后请修改 `config/wechat.php` 中对应的项即可。
2527

26-
4. 添加下面行到 `config/app.php``aliases` 部分:
27-
28-
```php
29-
'Wechat' => 'Overtrue\LaravelWechat\Facade',
30-
```
3128

3229
## 使用
3330

3431
> 注意:
3532
3633
> 1. Laravel 5 默认启用了 CRSF 中间件,因为微信的消息是 POST 过来,所以会触发 CRSF 检查导致无法正确响应消息,所以请去除默认的 CRSF 中间件,改成路由中间件。[默认启用的代码位置](https://github.com/laravel/laravel/blob/master/app/Http/Kernel.php#L18)
3734
38-
> 2. 你不需要在 `Wechat::make($config)` 了,我已经在拓展包里完成了这个动作,只要你在 `config/wechat.php` 里填写好配置就好了。
35+
所有的Wechat对象都已经放到了容器中,直接从容器中取就好。
36+
37+
别名对应关系如下:
3938

40-
由于我们已经添加了外观 `Wechat`,那么我们可以在控制器或者其它任何地方使用 `Wechat::方法名` 方式调用 SDK。
39+
'wechat.user' => 'Overtrue\\Wechat\\User',
40+
'wechat.group' => 'Overtrue\\Wechat\\Group',
41+
'wechat.auth' => 'Overtrue\\Wechat\\Auth',
42+
'wechat.menu' => 'Overtrue\\Wechat\\Menu',
43+
'wechat.menu.item' => 'Overtrue\\Wechat\\MenuItem',
44+
'wechat.js' => 'Overtrue\\Wechat\\Js',
45+
'wechat.staff' => 'Overtrue\\Wechat\\Staff',
46+
'wechat.store' => 'Overtrue\\Wechat\\Store',
47+
'wechat.card' => 'Overtrue\\Wechat\\Card',
48+
'wechat.qrcode' => 'Overtrue\\Wechat\\QRCode',
49+
'wechat.url' => 'Overtrue\\Wechat\\Url',
50+
'wechat.media' => 'Overtrue\\Wechat\\Media',
51+
'wechat.image' => 'Overtrue\\Wechat\\Image',
4152

4253
下面以接收普通消息为例写一个例子:
4354

@@ -49,22 +60,13 @@ Route::any('/wechat', 'WechatController@serve');
4960

5061
> 注意:一定是 `Route::any`, 因为微信服务端认证的时候是 `GET`, 接收用户消息时是 `POST`
5162
52-
你有两种方式获取 `Wechat` 实例:
53-
54-
### 一、 使用外观(Facade)
55-
56-
由于我们已经添加了外观 `Wechat`,那么我们可以在控制器或者其它任何地方使用 `Wechat::方法名` 方式调用 SDK。
57-
58-
下面以接收普通消息为例写一个例子:
59-
6063
这里假设您的域名为 `overtrue.me` 那么请登录微信公众平台 “开发者中心” 修改 “URL(服务器配置)” 为: `http://overtrue.me/wechat`
6164

6265
然后创建控制器 `WechatController`
6366

6467
```php
6568
<?php namespace App\Http\Controllers;
6669

67-
use Wechat;
6870
use Log;
6971

7072
class WechatController extends Controller {
@@ -76,7 +78,7 @@ class WechatController extends Controller {
7678
*/
7779
public function serve()
7880
{
79-
Wechat::on('message', function($message){
81+
App::on('message', function($message){
8082
Log::info("收到来自'{$message['FromUserName']}'的消息:{$message['Content']}");
8183
});
8284

src/ServiceProvider.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,18 @@ public function register()
5959

6060
foreach ($this->services as $alias => $service) {
6161
$this->app->singleton($service, function($app){
62-
return new {$service}(config('wechat.appId'), config('wechat.secret'));
62+
return new $service(config('wechat.appId'), config('wechat.secret'));
6363
});
6464

6565
$this->app->alias($service, $alias);
6666
}
6767
}
6868

69+
/**
70+
* 提供的服务名称列表
71+
*
72+
* @return array
73+
*/
6974
public function provides()
7075
{
7176
return array_keys($this->services) + array_values($this->services);

0 commit comments

Comments
 (0)