public function text($data)
 {
     if ($data['Content'] == '捐赠列表') {
         $url = addons_url('Donations://Donations/donations_list');
         replyText($url);
     }
 }
 function reply($dataArr, $keywordArr = array())
 {
     $config = getAddonConfig('Idioms');
     // 获取后台插件的配置参数
     $api = 'http://i.itpk.cn/api.php?question=@cy';
     // 成语接龙接口地址
     // 当用户触发成语接龙插件时
     if ($dataArr['Content'] == '成语接龙' || $dataArr['Content'] == 'Idioms') {
         $keywordArr['step'] = 'input';
         // 定义消息上下文的判断标识
         beginContext('Idioms', $keywordArr);
         // 设置消息上下文
         replyText('请输入一个成语,比如:一马当先');
         // 进行第一次响应
     }
     // 用户的下一次输入处于消息上下文中
     if ($keywordArr['step'] == 'input') {
         if ($dataArr['Content'] == '退出') {
             // 不设置消息上下文,则用户的下一次输入不再处于消息上下文中
             replyText('你已退出成语接龙模式,再次回复【成语接龙】即可进入~');
             return false;
         }
         // 将用户输入关键词提交到成语接龙接口,获得接口返回内容
         $reply = file_get_contents($api . $dataArr['Content']);
         // 如果用户输入的成语不符合规则
         if ($reply == '别来骗人家,不是随便打4个字就是成语哒!' || $reply == '成语必须为4个汉字') {
             $keywordArr['step'] = 'input';
             // 定义消息上下文的判断标识
             beginContext('Idioms', $keywordArr);
             // 继续设置消息上下文
             replyText($reply . "\n" . '重新输入一个成语开始接龙,输入【退出】退出成语接龙');
         } else {
             // 用户输入的成语是标准成语
             $keywordArr['step'] = 'input';
             // 定义消息上下文的判断标识
             beginContext('Idioms', $keywordArr);
             // 继续设置消息上下文
             replyText($reply);
         }
     }
 }
 private function init_follow($data)
 {
     $info = get_token_appinfo($data['ToUserName']);
     $config = S('PUBLIC_AUTH_' . $info['type']);
     if (!$config) {
         $config = M('public_auth')->getField('name,type_' . $info['type'] . ' as val');
         S('PUBLIC_AUTH_' . $info['type'], $config, 86400);
     }
     C($config);
     // 公众号接口权限
     //用户开启上送地理位置后,打开微信公众号就会自动回复,需要屏蔽掉 location
     if ($data['Event'] == 'LOCATION') {
         exit;
     }
     // 初始化用户信息
     $map['token'] = $data['ToUserName'];
     $map['openid'] = $data['FromUserName'];
     D('Common/Follow')->init_follow($data['FromUserName'], $data['ToUserName']);
     $user = M('public_follow')->where($map)->find();
     // 绑定配置
     $config = getAddonConfig('UserCenter', $map['token']);
     $userNeed = $user['uid'] > 0 && $user['has_subscribe'] < 2 || empty($user);
     if ($config['need_bind'] == 1 && $userNeed && C('USER_OAUTH')) {
         unset($map['uid']);
         $bind_url = addons_url('UserCenter://Wap/userCenter', $map);
         if ($config['bind_start'] != 0 && strtolower($_REQUEST['_addons']) != 'usercenter') {
             replyText('请先<a href="' . $bind_url . '">绑定账号</a>再使用');
             exit;
         }
     }
 }
 function text($data)
 {
     if ($data['Content'] == '功能演示') {
         // replyText("这是文本消息处理钩子里设置的文本回复");
     }
     if ($data['Content'] == '微捐赠') {
         // replyText('weijuanz');
     }
     if ($data['Content'] == 'jssdk' || $data['Content'] == 'demo' || $data['Content'] == '功能演示') {
         $params['token'] = get_token();
         $jump_url = addons_url('Example://Example/demo', $params);
         replyText('<a href="' . $jump_url . '">功能演示</a>');
     }
     if ($data['Content'] == '获取消息数组') {
         $revData = getRevData();
         replyText('消息数组:' . json_encode($revData));
     }
     if ($data['Content'] == '获取用户ID') {
         $revFrom = getRevFrom();
         replyText('用户id是:' . $revFrom);
     }
     if ($data['Content'] == '获取公众号ID') {
         $revTo = getRevTo();
         replyText('公众号id是:' . $revTo);
     }
     if ($data['Content'] == '获取消息类型') {
         $revType = getRevType();
         replyText('你发送的消息类型是:' . $revType);
     }
     if ($data['Content'] == '获取消息ID') {
         $revId = getRevId();
         replyText('你发送的消息ID是:' . $revId);
     }
     if ($data['Content'] == '获取消息发送时间') {
         $revCtime = getRevCtime();
         replyText('你发送的消息发送时间是:' . $revCtime);
     }
     if ($data['Content'] == '获取消息内容') {
         $revContent = getRevContent();
         replyText('你发送的消息内容是:' . $revContent);
     }
     if ($data['Content'] == '回复文本') {
         replyText("这是文本回复");
     }
     if ($data['Content'] == '回复单图文') {
         $articles[0] = array('Title' => '单图文消息标题', 'Description' => '单图文消息描述', 'PicUrl' => 'https://mmbiz.qlogo.cn/mmbiz/bcPR8rBzAQhibbpsMEC1WOYIaD1l85XJRWCoricvUnfricBXO9eIuPEJgB2EsucewMYWjE3dLxohzINoxoaD6R6aA/0?wx_fmt=jpeg', 'Url' => 'http://idouly.com/wenda/');
         replyNews($articles);
     }
     if ($data['Content'] == '回复多图文') {
         $articles[0] = array('Title' => '单图文消息标题1', 'Description' => '单图文消息描述1', 'PicUrl' => 'https://mmbiz.qlogo.cn/mmbiz/bcPR8rBzAQhibbpsMEC1WOYIaD1l85XJRWCoricvUnfricBXO9eIuPEJgB2EsucewMYWjE3dLxohzINoxoaD6R6aA/0?wx_fmt=jpeg', 'Url' => 'http://idouly.com/wenda/');
         $articles[1] = array('Title' => '单图文消息标题2', 'Description' => '单图文消息描述2', 'PicUrl' => 'https://mmbiz.qlogo.cn/mmbiz/bcPR8rBzAQhibbpsMEC1WOYIaD1l85XJRWCoricvUnfricBXO9eIuPEJgB2EsucewMYWjE3dLxohzINoxoaD6R6aA/0?wx_fmt=jpeg', 'Url' => 'http://idouly.com/wenda/');
         $articles[2] = array('Title' => '单图文消息标题3', 'Description' => '单图文消息描述3', 'PicUrl' => 'https://mmbiz.qlogo.cn/mmbiz/bcPR8rBzAQhibbpsMEC1WOYIaD1l85XJRWCoricvUnfricBXO9eIuPEJgB2EsucewMYWjE3dLxohzINoxoaD6R6aA/0?wx_fmt=jpeg', 'Url' => 'http://idouly.com/wenda/');
         $articles[3] = array('Title' => '单图文消息标题4', 'Description' => '单图文消息描述4', 'PicUrl' => 'https://mmbiz.qlogo.cn/mmbiz/bcPR8rBzAQhibbpsMEC1WOYIaD1l85XJRWCoricvUnfricBXO9eIuPEJgB2EsucewMYWjE3dLxohzINoxoaD6R6aA/0?wx_fmt=jpeg', 'Url' => 'http://idouly.com/wenda/');
         replyNews($articles);
     }
     if ($data['Content'] == '回复音乐') {
         replyMusic('我的歌声里', '曲婉婷', 'http://yinyueshiting.baidu.com/data2/music/5a5631832313a6007da895d12994e311/255967781/255704757248400128.mp3?xcode=67dd7bdbf2d520d5bd5cc648288db746');
     }
     if ($data['Content'] == '转接客服') {
         transferCustomerService();
     }
     if ($data['Content'] == '获取菜单') {
         $menu = getMenu();
         replyText(json_encode($menu));
     }
     if ($data['Content'] == '删除菜单') {
         if (deleteMenu()) {
             replyText('删除菜单成功');
         }
     }
     if ($data['Content'] == '创建菜单') {
         $btn1 = array('name' => 'button1', 'type' => 'click', 'key' => 'button1_key');
         $data['button'][0] = $btn1;
         if (createMenu($data)) {
             replyText('创建菜单成功');
         } else {
             replyText('创建菜单失败');
         }
     }
     if ($data['Content'] == '发送模板消息') {
         $temp_data['touser'] = getRevFrom();
         $temp_data['template_id'] = 'A93dk7bWn9W4oSvM7UcXm95X-WehNeLeegRq4RaKF8g';
         $temp_data['url'] = 'http://idouly.com/wenda/';
         $temp_data['topcolor'] = '#44b549';
         $temp_data['data']['first']['value'] = '有新的用户捐赠,请注意查收';
         $temp_data['data']['first']['color'] = '#da4224';
         $temp_data['data']['keyword1']['value'] = '用户捐赠通知';
         $temp_data['data']['keyword1']['color'] = '#0baae4';
         $temp_data['data']['keyword2']['value'] = '2015年1月7日';
         $temp_data['data']['keyword2']['color'] = '#0baae4';
         $temp_data['data']['remark']['value'] = '用户昵称:艾逗笔,捐赠额:66元';
         $temp_data['data']['remark']['color'] = '#333';
         //replyText(json_encode($temp_data));
         sendTemplateMessage($temp_data);
         // replyText(json_encode($temp_data));
         exit;
     }
     if ($data['Content'] == '发送文本客服消息') {
         $kf_data['touser'] = getRevFrom();
         $kf_data['msgtype'] = 'text';
         $kf_data['text']['content'] = '你好啊,亲~';
         //replyText(json_encode($kf_data));
         sendCustomMessage($kf_data);
         exit;
     }
     if ($data['Content'] == '发送图文客服消息') {
         $articles[0] = array('title' => '单图文消息标题1', 'description' => '单图文消息描述1', 'picurl' => 'https://mmbiz.qlogo.cn/mmbiz/bcPR8rBzAQhibbpsMEC1WOYIaD1l85XJRWCoricvUnfricBXO9eIuPEJgB2EsucewMYWjE3dLxohzINoxoaD6R6aA/0?wx_fmt=jpeg', 'url' => 'http://idouly.com/wenda/');
         $articles[1] = array('title' => '单图文消息标题2', 'description' => '单图文消息描述2', 'picurl' => 'https://mmbiz.qlogo.cn/mmbiz/bcPR8rBzAQhibbpsMEC1WOYIaD1l85XJRWCoricvUnfricBXO9eIuPEJgB2EsucewMYWjE3dLxohzINoxoaD6R6aA/0?wx_fmt=jpeg', 'url' => 'http://idouly.com/wenda/');
         $articles[2] = array('title' => '单图文消息标题3', 'description' => '单图文消息描述3', 'picurl' => 'https://mmbiz.qlogo.cn/mmbiz/bcPR8rBzAQhibbpsMEC1WOYIaD1l85XJRWCoricvUnfricBXO9eIuPEJgB2EsucewMYWjE3dLxohzINoxoaD6R6aA/0?wx_fmt=jpeg', 'url' => 'http://idouly.com/wenda/');
         $articles[3] = array('title' => '单图文消息标题4', 'description' => '单图文消息描述4', 'picurl' => 'https://mmbiz.qlogo.cn/mmbiz/bcPR8rBzAQhibbpsMEC1WOYIaD1l85XJRWCoricvUnfricBXO9eIuPEJgB2EsucewMYWjE3dLxohzINoxoaD6R6aA/0?wx_fmt=jpeg', 'url' => 'http://idouly.com/wenda/');
         $kf_data['touser'] = getRevFrom();
         $kf_data['msgtype'] = 'news';
         $kf_data['news']['articles'] = $articles;
         //replyText(json_encode($kf_data));
         sendCustomMessage($kf_data);
         exit;
     }
     if ($data['Content'] == '获取二维码') {
         $qrCode = getQRCode(88, 2);
         replyText(json_encode($qrCode));
     }
 }