<?php
class WeixinAction extends CommonAction{
public function index(){
/* 加载微信SDK */
import('ORG.Util.ThinkWechat');
$weixin = new ThinkWechat(I('callback_token')); //这里的TOKEN是在公众平台开发者模式中配置的TOKEN
/* 获取请求信息 */
$data = $weixin->request();
/* 获取回复信息 */
// 这里的回复信息是通过判断请求内容自行定制的, 不在SDK范围内,请自行完成
list($content, $type) = $this->reply($data);
/* 响应当前请求 */
$weixin->response($content, $type);
}
private function reply($data){
if('event' == $data['MsgType'] && 'subscribe' == $data['Event']){
$reply = array('欢迎您关注麦当苗儿公众助手!', 'text');
return $reply;
}
//回复文本消息
//$reply = array($data['Content'], 'text');
//
//回复图文消息
$data = array(
array('ThinkPHP七周年', '1', 'http://www.thinkphp.cn/Uploads/ad/2013-05-09/518b19ed4bd74.jpg', 'http://www.thinkphp.cn/7year.html'),
array('ThinkPHP发布3.1.3版本', '2', 'http://www.thinkphp.cn__NEW__/img/header_logo.png', 'http://www.thinkphp.cn'),
);
$reply = array($data, 'news');
return $reply;
}
}
最佳答案