-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
205 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Oops, something went wrong.