Skip to content

Commit 4d43344

Browse files
committed
For lumen. #9
1 parent 1beb55d commit 4d43344

File tree

3 files changed

+44
-13
lines changed

3 files changed

+44
-13
lines changed

README.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,50 @@
1616
```shell
1717
composer require "overtrue/laravel-wechat:2.0.*"
1818
```
19+
## 配置
1920

20-
2. 添加 `ServiceProvider` 到您项目 `config/app.php` 中的 `providers` 部分:
21+
### Laravel 应用
22+
23+
1. 注册 `ServiceProvider`:
2124

2225
```php
23-
'Overtrue\LaravelWechat\ServiceProvider',
26+
Overtrue\LaravelWechat\ServiceProvider::class,
2427
```
2528

26-
3. 创建配置文件:
29+
2. 创建配置文件:
2730

2831
```shell
2932
php artisan vendor:publish
3033
```
31-
4. 请修改应用根目录下的 `config/wechat.php` 中对应的项即可;
34+
3. 请修改应用根目录下的 `config/wechat.php` 中对应的项即可;
3235

33-
5. (可选)添加外观到 `config/app.php` 中的 `aliases` 部分:
36+
4. (可选)添加外观到 `config/app.php` 中的 `aliases` 部分:
3437

3538
```php
3639
'Wechat' => 'Overtrue\LaravelWechat\Facade',
3740
```
41+
### Lumen 应用
42+
43+
1.`bootstrap/app.php` 中 82 行左右:
44+
45+
```php
46+
$app->register(Overtrue\LaravelWechat\ServiceProvider::class);
47+
```
48+
49+
2. 在 ENV 中配置以下选项:
50+
51+
```php
52+
WECHAT_USE_ALIAS=false
53+
WECHAT_APPID=你的微信APPid
54+
WECHAT_SECRET=你的secret
55+
WECHAT_TOKEN=你的token
56+
WECHAT_ENCODING_KEY=AESkey
57+
```
58+
3. 如果你习惯使用 `config/wechat.php` 来配置的话,请记得在 `bootstrap/app.php` 中19行以后添加:
59+
60+
```php
61+
$app->configure('wechat');
62+
```
3863

3964
## 使用
4065

src/ServiceProvider.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ class ServiceProvider extends LaravelServiceProvider
5555
*/
5656
public function boot()
5757
{
58-
$this->publishes([
59-
__DIR__ . '/config.php' => config_path('wechat.php'),
60-
], 'config');
58+
if (function_exists('config_path')) {
59+
$this->publishes([
60+
__DIR__ . '/config.php' => config_path('wechat.php'),
61+
], 'config');
62+
}
6163
}
6264

6365
/**
@@ -67,6 +69,10 @@ public function boot()
6769
*/
6870
public function register()
6971
{
72+
$this->mergeConfigFrom(
73+
__DIR__.'/config.php', 'wechat'
74+
);
75+
7076
if (config('wechat.use_alias')) {
7177
Alias::register();
7278
}

src/config.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22
return [
3-
'use_alias' => false,
4-
'app_id' => 'YourAppId', // 必填
5-
'secret' => 'YourSecret', // 必填
6-
'token' => 'YourToken', // 必填
7-
'encoding_key' => 'YourEncodingAESKey' // 加密模式需要,其它模式不需要
3+
'use_alias' => env('WECHAT_USE_ALIAS', false),
4+
'app_id' => env('WECHAT_APPID', 'YourAppId'), // 必填
5+
'secret' => env('WECHAT_SECRET', 'YourSecret'), // 必填
6+
'token' => env('WECHAT_TOKEN', 'YourToken'), // 必填
7+
'encoding_key' => env('WECHAT_ENCODING_KEY', 'YourEncodingAESKey') // 加密模式需要,其它模式不需要
88
];

0 commit comments

Comments
 (0)