Skip to content
This repository has been archived by the owner on Sep 25, 2021. It is now read-only.

Commit

Permalink
添加自定义缓存 demo & 同步模板消息文档
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Aug 23, 2016
1 parent e17e000 commit 723ec03
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
66 changes: 66 additions & 0 deletions cache.md
Expand Up @@ -50,3 +50,69 @@ $app->cache = $cacheDriver;

> 上面提到的 `app('redis')->connection($name)`, 这里的 `$name` 是 laravel 项目中配置文件 `database.php``redis` 配置名 `default`https://github.com/laravel/laravel/blob/master/config/database.php#L118
> 如果你使用的其它连接,对应传名称就好了。

## 使用自定义的缓存方式

如果你发现 doctrine 提供的几十种缓存方式都满足不了你的需求的话,那么你可以自己建立一个类来完成缓存操作,前提这个类得实现接口:[Doctrine\Common\Cache\Cache](https://github.com/doctrine/cache/blob/master/lib/Doctrine/Common/Cache/Cache.php)

该接口有以下方法需要实现:

```php
public function fetch($id); // 读取缓存
public function contains($id); // 检查是否存在缓存
public function save($id, $data, $lifeTime = 0); // 设置缓存
public function delete($id); // 删除缓存
public function getStats(); // 获取状态
```

下面为一个示例:

```php
<?php

use Doctrine\Common\Cache\Cache as CacheInterface;

class MyCacheDriver implements CacheInterface
{
public function fetch($id)
{
// 你自己从你想实现的存储方式读取并返回
}

public function contains($id)
{
// 同理 返回存在与否 bool 值
}

public function save($id, $data, $lifeTime = 0)
{
// 用你的方式存储该缓存内容即可
}

public function delete($id)
{
// 删除并返回 bool 值
}

public function getStats()
{
// 这个你可以不用实现,返回 null 即可
}
}
```

然后实例化你的缓存类并在 EasyWeChat 里使用它:

```php
$myCacheDriver = new MyCacheDriver();

$config = [
//...
'cache' => $myCacheDriver,
];

$wechatApp = new Application($options);
```

OK,这样就完成了自定义缓存的操作。
11 changes: 9 additions & 2 deletions notice.md
Expand Up @@ -8,7 +8,7 @@ title: 模板消息
1. 所有服务号都可以在功能->添加功能插件处看到申请模板消息功能的入口,但只有认证后的服务号才可以申请模板消息的使用权限并获得该权限;
2. 需要选择公众账号服务所处的2个行业,每月可更改1次所选行业;
3. 在所选择行业的模板库中选用已有的模板进行调用;
4. 每个账号可以同时使用15个模板
4. 每个账号可以同时使用多个模板
5. 当前每个模板的日调用上限为 10 万次【2014年11月18日将接口调用频率从默认的日1万次提升为日10万次,可在MP登录后的开发者中心查看】。

关于接口文档,请注意:
Expand Down Expand Up @@ -101,7 +101,14 @@ $data = array(
"remark" => "欢迎再次购买!",
);

$messageId = $notice->uses($templateId)->withUrl($url)->andData($data)->andReceiver($userId)->send();
$result = $notice->uses($templateId)->withUrl($url)->andData($data)->andReceiver($userId)->send();
var_dump($result);

// {
// "errcode":0,
// "errmsg":"ok",
// "msgid":200228332
// }
```

结果:
Expand Down

0 comments on commit 723ec03

Please sign in to comment.