Skip to content

Commit

Permalink
完善注释
Browse files Browse the repository at this point in the history
  • Loading branch information
netputer committed May 17, 2013
1 parent f4b24d1 commit 58fea30
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 40 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@

用法
-----
1. Clone 或下载项目源码。
1. Clone 或下载项目源码,上传至服务器

2. 打开 `/example/server.php` 文件,将实例化 `MyWechat` 时传入的参数改为你的 Token
2. 进入[微信公众平台](https://mp.weixin.qq.com/),高级功能,开启开发模式,并设置接口配置信息。修改 `URL``/example/server.php` 的实际位置,修改 `Token``weixin` (可自行在 `/example/server.php` 中更改)

3. 进入[微信公众平台](https://mp.weixin.qq.com/),高级功能,开启开发模式,并设置接口配置信息。其中 `URL``/example/server.php` 的实际位置, `Token` 为上一步设置的 Token 。

4. 向你的微信公众号发送消息并测试吧!
3. 向你的微信公众号发送消息并测试吧!

TODO
-----
Expand Down
54 changes: 51 additions & 3 deletions example/server.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,86 @@
<?php
/**
* 微信公众平台 PHP SDK 示例文件
*
* @author NetPuter <netputer@gmail.com>
*/

require('../src/Wechat.php');

/**
* 微信公众平台演示类
*/
class MyWechat extends Wechat {

/**
* 用户关注时触发,回复「欢迎关注」
*
* @return void
*/
protected function onSubscribe() {
$this->responseText('欢迎关注');
}

/**
* 用户取消关注时触发
*
* @return void
*/
protected function onUnsubscribe() {
// 悄悄的我走了,正如我悄悄的来;我挥一挥衣袖,不带走一片云彩。
// 悄悄的我走了,正如我悄悄的来;我挥一挥衣袖,不带走一片云彩。
}

/**
* 收到文本消息时触发,回复收到的文本消息内容
*
* @return void
*/
protected function onText() {
$this->responseText('收到了文字消息:' . $this->getRequest('content'));
}

/**
* 收到图片消息时触发,回复由收到的图片组成的图文消息
*
* @return void
*/
protected function onImage() {
$this->responseText('收到了图片消息:' . $this->getRequest('picurl'));
$items = array(
new NewsResponseItem('标题一', '描述一', $this->getRequest('picurl'), $this->getRequest('picurl')),
new NewsResponseItem('标题二', '描述二', $this->getRequest('picurl'), $this->getRequest('picurl')),
);

$this->responseNews($items);
}

/**
* 收到地理位置消息时触发,回复收到的地理位置
*
* @return void
*/
protected function onLocation() {
$this->responseText('收到了位置消息:' . $this->getRequest('location_x') . ',' . $this->getRequest('location_y'));
}

/**
* 收到链接消息时触发,回复收到的链接地址
*
* @return void
*/
protected function onLink() {
$this->responseText('收到了链接:' . $this->getRequest('url'));
}

/**
* 收到未知类型消息时触发,回复收到的消息类型
*
* @return void
*/
protected function onUnknown() {
$this->responseText('收到了未知类型消息:' . $this->getRequest('msgtype'));
}

}

$wechat = new MyWechat('Your Token');
$wechat = new MyWechat('weixin');
$wechat->run();
Loading

0 comments on commit 58fea30

Please sign in to comment.