public function index() { import('Vendor.Wechat.Wechat'); $option = array('token' => 'weixin', 'appid' => 'wx444c22311a33b40d', 'secret' => 'f39ae15e9d86c293edbff26a9c47af6e'); $wechatObj = new \Wechat($option); $wechatObj->valid(); //解析来向XML $msg = $wechatObj->getRev(); $message['fromUsername'] = $msg->getRevFrom(); $message['toUsername'] = $msg->getRevTo(); $message['type'] = $msg->getRevType(); $message['createtime'] = $msg->getRevCtime(); $message['keyword'] = $msg->getRevContent(); $message['event'] = $msg->getRevEvent(); //保存新用户相关信息 $status = D('Member'); $status->InsertNewer($message['fromUsername']); //主要部分,暂时仅使用TEXT,EVENT两种 switch ($message['type']) { case $wechatObj::MSGTYPE_TEXT: $text = A('Text'); $ret = $text->textSkip($message); if ('text' == $ret['type']) { $wechatObj->text($ret['content'])->reply(); } else { if ('news' == $ret['type']) { $wechatObj->news($ret['content'])->reply(); } } break; case $wechatObj::MSGTYPE_EVENT: $event = A('Event'); $ret = $event->eventSkip($message); if ('text' == $ret['type']) { $wechatObj->text($ret['content'])->reply(); } else { if ('news' == $ret['type']) { $wechatObj->news($ret['content'])->reply(); } } break; default: $wechatObj->text('更多功能正在研发中,敬请期待')->reply(); } //获取菜单 $menu = $wechatObj->getMenu(); //创建菜单 $newmenu = array('小瓜神力' => array(array('type' => 'click', 'name' => '新生专题', 'key' => 'V1001_01_01'), array('type' => 'click', 'name' => '校车时刻', 'key' => 'V1001_01_02'), array('type' => 'click', 'name' => '交通导航', 'key' => 'V1001_01_03'), array('type' => 'click', 'name' => '考试成绩', 'key' => 'V1001_01_04'), array('type' => 'click', 'name' => '图书信息', 'key' => 'V1001_01_05')), '军训专题' => array(array('type' => 'click', 'name' => '通知公告', 'key' => 'V1001_02_01'), array('type' => 'click', 'name' => '军训快报', 'key' => 'V1001_02_02'), array('type' => 'click', 'name' => '军营风采', 'key' => 'V1001_02_03'), array('type' => 'view', 'name' => '军歌嘹亮', 'url' => 'http://mp.weixin.qq.com/s?__biz=MjM5OTIxMTM2Mg==&mid=209183345&idx=1&sn=96c4cf9ad618e5e051167456210d9fe8&scene=5&srcid=OJ8qMfaW9nS5T0jFFjQj#rd'), array('type' => 'click', 'name' => '微军训', 'key' => 'V1001_02_05')), '小瓜威武' => array(array('type' => 'click', 'name' => '小瓜在线', 'key' => 'V1001_03_01'), array('type' => 'click', 'name' => '跑操查询', 'key' => 'V1001_03_02'), array('type' => 'view', 'name' => '瓜棚论坛', 'url' => 'http://npuxiaogua.mgschool.cn/wx/apps/liuyan/'), array('type' => 'view', 'name' => '失物招领', 'url' => 'http://npuxiaogua.mgschool.cn/wx/npuxg_blog/wxq/index.php'), array('type' => 'click', 'name' => '表白墙', 'key' => 'V1001_03_05'))); $result = $wechatObj->createMenu($newmenu); }
$result = $weObj->createMenu($newmenu); $type = $weObj->getRev()->getRevType(); $revfrom = $weObj->getRev()->getRevFrom(); $getrevto = $weObj->getRev()->getRevTo(); switch ($type) { case Wechat::MSGTYPE_TEXT: $msg = $weObj->getRev()->getRevContent(); switch ($msg) { case 'openid': //get openid $openid = $weObj->getRev()->getRevFrom(); $weObj->text('openid:' . $openid)->reply(); break; case '预约查询': $newsData = array($item = array('Title' => '预约查询', 'Description' => '点击查看', 'Url' => 'www.blkqyy.com/admin.php/message/add_yuyue.html?weixin_id=' . $topmsg['fakeid'])); $weObj->news($newsData)->reply(); break; default: $weObj->text("您的消息我们已经收到,感谢您的支持!")->reply(); break; } exit; break; // 接收语音消息 // 接收语音消息 case Wechat::MSGTYPE_VOICE: $voice = $weObj->getRevVoice(); $weObj->voice($voice['mediaid'])->reply(); exit; break; case Wechat::MSGTYPE_EVENT:
openlog("wechat", LOG_PID | LOG_PERROR, LOG_LOCAL0); syslog(LOG_DEBUG, $text); closelog(); //} } $options = array('token' => 'N6cq3R', 'encodingaeskey' => 'nil3OzTxXoPHx4mvx0GLbyECkPYrfyiB9ca4Iz61ny3', 'appid' => 'wx926454a4965d2b7c', 'appsecret' => 'PkG1V74sWm6V2mNN3F2NOHKQT696g1wrmJZhB7WT-8xcLmt-3rez3FfuH3SzCf', 'agentid' => '3', 'debug' => true, 'logcallback' => '_log'); $weObj = new Wechat($options); _log("GET参数为:\n" . var_export($_GET, true)); $valid = $weObj->valid(); if (!$valid) { _log("验证失败"); exit($valid); } $recv = $weObj->getRev(); $type = $recv->getRevType(); switch ($type) { case Wechat::MSGTYPE_TEXT: $weObj->text("I got your message, here is <a href=\"http://www.gds-services.com\">gds</a>")->reply(); exit; break; case Wechat::MSGTYPE_IMAGE: $weObj->text("I got your image")->reply(); break; case Wechat::MSGTYPE_EVENT: $event = $recv->getRevEvent(); $message = array("0" => array("Title" => "GDS携云灾备方案参加第十届灾备论坛 助力大数据价值挖掘", "Description" => "GDS携云灾备方案参加第十届灾备论坛 助力大数据价值挖掘", "Url" => "http://www.gds-services.com/new_1787.html", "PicUrl" => "http://www.gds-services.com/upload/articles/1434592478.jpg"), "1" => array("Title" => "Bash漏洞爆发,GDS迅速应对", "Description" => "Bash漏洞爆发,GDS迅速应对", "Url" => "http://www.gds-services.com/new_1757.html", "PicUrl" => "http://www.gds-services.com/images/imgc-1.png")); $weObj->news($message)->reply(); break; default: $weObj->text("other info" . var_export($recv, true))->reply(); }
<?php include "wechat.class.php"; include "./controller/textController/TextController.php"; include "./controller/eventController/EventController.php"; include "./model/TextModel.php"; include "./model/EventModel.php"; include "./config/params.php"; $options = array('token' => '', 'encodingaeskey' => '', 'appid' => '', 'appsecret' => ''); $weObj = new Wechat($options); $weObj->valid(); $type = $weObj->getRev()->getRevType(); switch ($type) { case Wechat::MSGTYPE_TEXT: $textObj = new TextController($weObj); $reply = $textObj->replyIndex(); $weObj->text($reply)->reply(); break; case Wechat::MSGTYPE_EVENT: $eventObj = new EventController($weObj); $reply = $eventObj->replyIndex(); //$weObj->text($reply)->reply(); $weObj->news($reply)->reply(); break; case Wechat::MSGTYPE_IMAGE: break; default: $weObj->text("help info")->reply(); }
} break; case Wechat::MSGTYPE_EVENT: $revEvent = array(); $revEvent = $wechatObj->getRevEvent(); switch ($revEvent['event']) { case "subscribe": $wechatObj->text("欢迎您关注福大人,我们会用心为您服务。\n目前您可以使用的功能有:\n我的图书馆:发送: ”我的图书馆“指令查看\n\n如果您闲来无聊,可以试试和福大人小机器人聊天哦。\n 福大人工作室" . "")->reply(); break; case "unsubscribe": break; } break; case Wechat::MSGTYPE_IMAGE: $newsData = array(0 => array('Title' => '欢迎您关注福大人', 'Description' => "欢迎您关注福大人,我们会用心为您服务。\n\n 福大人工作室", 'PicUrl' => 'http://com/weixin//static/images/fzu.gif', 'Url' => 'http://r.com/weixin//info.html')); $wechatObj->news($newsData)->reply(); break; case Wechat::MSGTYPE_LOCATION: $revGeo = $wechatObj->getRevGeo(); if ($revGeo) { $wechatObj->text("您的位置信息是:X=" . $revGeo['x'] . ",Y=" . $revGeo['y'] . "\n" . $revGeo['label'])->reply(); } break; case Wechat::MSGTYPE_VOICE: //多媒体消息关联获取id,并下载文件到服务器本地示例 $oneMessage = $wechatObj->getOneMessage($wechatObj->getRevCtime(), $wechatObj->getRevType(), $wechatObj->getRevFrom()); $mediaFile = array(); if ($oneMessage) { $mediaFile = $wechatObj->getDownloadFile($oneMessage["id"]); } // $wechatObj->text(serialize($mediaFile))->reply();
include "wechat.class.php"; $options = array('token' => 'vonvon', 'encodingaeskey' => 'encodingaeskey', 'appid' => 'wx519f23f4a45e8c37', 'appsecret' => 'ea8f0b17b3a0882bf5fda7ed27758482'); $weObj = new Wechat($options); $weObj->valid(); //明文或兼容模式可以在接口验证通过后注释此句,但加密模式一定不能注释,否则会验证失败 $openid = $weObj->getRev()->getRevFrom(); $token = $weObj->checkAuth(); $info = $weObj->getUserInfo($openid); $type = $weObj->getRev()->getRevType(); switch ($type) { case Wechat::MSGTYPE_TEXT: $content = $weObj->getRev()->getRevContent(); if (substr($content, 0, 6) == '姓名') { $name = substr($content, 6); $res = array("0" => array('Title' => $name . ', 你的生辰八字', 'Description' => 'Vonvon作为国际化的SNS社交媒体,从2015年1月起,在全世界已经拥有1亿以上的 用户。现在已在韩国,中国,台湾,泰国,越南,印尼,美国,巴西,西班牙等国家 开放。将来会拓展到更多的国家,并且会创作更多有趣的主题测试。', 'PicUrl' => 'http://cdn-cn-static-dr.vonvon.net/images/cn/recruit_main.jpg', 'Url' => 'http://cn.vonvon.net/')); $weObj->news($res)->reply(); } else { $weObj->text("Your nickname is " . $info['nickname'] . "\nYour sex is " . $info['sex'] . "\nYour city is " . $info['city'] . "\nYour province is " . $info['province'] . "\n Your country is " . $info['country'] . "\nYour headimgurl is " . $info['headimgurl'] . "\nYour subscribe_time is " . date("Y-m-d H:i:s", $info['subscribe_time']) . "\nNow is " . date("Y-m-d H:i:s", time()))->reply(); exit; } break; case Wechat::MSGTYPE_EVENT: $event = $weObj->getRev()->getRevEvent(); switch ($event['event']) { case 'subscribe': $subscribe = array("0" => array('Title' => $info['nickname'] . ', welcome to VonVon!', 'Description' => 'Vonvon作为国际化的SNS社交媒体,从2015年1月起,在全世界已经拥有1亿以上的 用户。现在已在韩国,中国,台湾,泰国,越南,印尼,美国,巴西,西班牙等国家 开放。将来会拓展到更多的国家,并且会创作更多有趣的主题测试。', 'PicUrl' => 'http://cdn-cn-static-dr.vonvon.net/images/cn/recruit_main.jpg', 'Url' => 'http://cn.vonvon.net/'), "1" => array('Title' => '盗墓笔记测试——你是南派还是北派', 'Description' => '你看过盗墓笔记吗?你知道盗墓人士中分南派和北派吗?来测一下你是属于什么派的吧?', 'PicUrl' => 'http://cdn-cn.vonvon.net/vonvon-cn-real/editor/1436839209469-SArBr8o9DJoXcpLx.jpg', 'Url' => 'http://cn.vonvon.net/quiz/424')); $weObj->news($subscribe)->reply(); break; case 'CLICK': switch ($event['key']) { case 'god':
// 获取用户OPENID并写入数据库 $mysql = new SaeMysql(); $sql = "INSERT INTO `users` (`wxid`) VALUES ('" . $fromUsername . "');"; $mysql->runSql($sql); $mysql->closeDb(); // 获得信息的类型 $news = array ( array ( 'Title'=>'欢迎关注WeeGo工作室', 'Description'=>'发送任意内容查看最新开发进展', 'PicUrl'=>'http://233.weego.sinaapp.com/images/weego_400_200.png', ) ); $weObj->news($news)->reply(); } //**********取消关注操作则删除数据库**********/ if($weObj->getRevUnsubscribe()) { // 获取用户OPENID并从数据库删除 $mysql = new SaeMysql(); $sql = "DELETE FROM `users` WHERE `wxid` = '" . $fromUsername . "'"; $mysql->runSql($sql); $mysql->closeDb(); } switch($type) { case Wechat::MSGTYPE_TEXT: /**********文字信息**********/ $news = array (