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); }
public function kefu() { import('Wechat', APP_PATH . 'Common/Wechat', '.class.php'); $config = M("Wxconfig")->where(array("id" => "1"))->find(); $options = array('token' => $config["token"], 'encodingaeskey' => $config["encodingaeskey"], 'appid' => $config["appid"], 'appsecret' => $config["appsecret"], 'partnerid' => $config["partnerid"], 'partnerkey' => $config["partnerkey"], 'paysignkey' => $config["paysignkey"]); $weObj = new Wechat($options); $weObj->text("kefu")->reply(); /*$image = realpath(dirname(__FILE__).'/../../../../').'/kefu.jpg'; $data['media'] = "@$image"; $res = $weObj->uploadMedia($data, 'image'); $weObj->getRev ()->image ( $res['media_id'] )->reply ();*/ exit; }
public function endpoint() { import('ORG.Util.wechat'); $weObj = new Wechat(); $type = $weObj->getRev()->getRevType(); switch ($type) { case Wechat::MSGTYPE_TEXT: $weObj->text($this->search_orgs($weObj->getRevContent()))->reply(); exit; break; case Wechat::MSGTYPE_EVENT: break; case Wechat::MSGTYPE_IMAGE: break; case Wechat::MSGTYPE_LOCATION: $weObj->text($this->search_events($weObj->getRevGeo()))->reply(); exit; break; default: $weObj->text("help info")->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(); }
$weObj->valid(); $type = $weObj->getRev()->getRevType(); $openid = $weObj->getRev()->getRevFrom(); _log1(json_encode(['type' => $type, 'openid' => $openid])); switch ($type) { case Wechat::MSGTYPE_TEXT: $text = $weObj->getRev()->getRevContent(); $weObj->transfer_customer_service()->reply(); break; case Wechat::MSGTYPE_EVENT: $event = $weObj->getRev()->getRevEvent(); _log1(json_encode(['event' => $event])); switch ($event['event']) { case Wechat::EVENT_SUBSCRIBE: $bind_url = $csc_url_base . '/dynamic/user_isbind_csc.php?openid=' . $openid . '&bcb=user_bind_check_csc&rand=' . rand(); $weObj->text("您好!欢迎来到万国数据客户服务中心。\n\n" . "若您是万国数据的授权用户,您可以在绑定账号后体验我们为您带来的更多专属服务喔~\n" . "<a href=\"" . $bind_url . "\">点击这里绑定账号</a>\n\n" . "如有疑问,欢迎您直接留言。")->reply(); $user = $weObj->getUserInfo($openid); _log_focus($openid, 'focus', $user); break; case Wechat::EVENT_UNSUBSCRIBE: _log_focus($openid, 'unfocus'); case Wechat::EVENT_MENU_CLICK: $key = $event['key']; switch ($key) { case 'wechat_csc': $kf_list = $weObj->getCustomServiceOnlineKFlist(); $kf_count = count($kf_list); if ($kf_count <= 0) { $weObj->text('我们的客服都在紧张地忙碌中,暂时无法及时响应,请稍作等待。' . '您也可以致电万国数据400热线:<a href="tel:4000724366">4000-724-366</a>,' . '我们会有电话客服专员专门响应您的请求。')->reply(); } else { $weObj->text('目前共有 ' . $kf_count . ' 位客服在线。' . '我们会以最快的速度给予响应')->reply();
//} } $options = ['token' => 'nizhidaoma', 'encodingaeskey' => 'xc8rRK4iOQjTJK9hOYhRrC9sPBJvF5Jhjq203iMC7vF', 'appid' => 'wxe85832e232e73f41', 'appsecret' => '4c8f1aa381675dd2569fc9482052afdc', 'debug' => true, 'logcallback' => '_log1']; $pe_host_base = 'https://wechat.gds-services.com'; $pe_url_base = 'https://wechat.gds-services.com'; $default_reply = '欢迎使用万国数据微信客服。' . '如需帮助,欢迎随时致电:<a href="tel:4000724366">4000-724-366</a>。'; $weObj = new Wechat($options); $weObj->valid(); $type = $weObj->getRev()->getRevType(); $openid = $weObj->getRev()->getRevFrom(); _log1(json_encode(['type' => $type, 'openid' => $openid])); switch ($type) { case Wechat::MSGTYPE_TEXT: $bind_url = $pe_url_base . '/dynamic/user_isbind_pe.php?openid=' . $openid . '&bcb=user_bind_check_pe&rand=' . rand(); $text = $weObj->getRev()->getRevContent(); $weObj->text("感谢您关注GDS运维管理公众号。\n\n" . "此公众号用于GDS内部系统信息查询和获取推送消息。\n\n" . "如果您还未绑定GDS统一认证平台账号,请<a href=\"" . $bind_url . "\">点击这里绑定账号</a>\n\n" . '如有疑问或需要帮助,请联系系统工具部【谢云昭】。')->reply(); break; case Wechat::MSGTYPE_EVENT: $event = $weObj->getRev()->getRevEvent(); switch ($event['event']) { case Wechat::EVENT_SUBSCRIBE: $bind_url = $pe_url_base . '/dynamic/user_isbind_pe.php?openid=' . $openid . '&bcb=user_bind_check_pe&rand=' . rand(); $weObj->text("感谢您关注GDS运维管理公众号。\n\n" . "此公众号用于GDS内部系统信息查询和获取推送消息," . "<a href=\"" . $bind_url . "\">点击这里绑定账号</a>\n\n" . '如有疑问或需要帮助,请联系系统工具部【谢云昭】。')->reply(); $user = $weObj->getUserInfo($openid); _log_focus($openid, 'focus', $user); break; case Wechat::EVENT_UNSUBSCRIBE: _log_focus($openid, 'unfocus'); case Wechat::EVENT_MENU_CLICK: $key = $event['key']; switch ($key) {
$wechatOptions = (require './configure.php'); $wechatObj = new Wechat($wechatOptions); $wechatObj->valid(); //可以在认证后注释掉(只是这样可能不安全) $wechatObj->positiveInit(); //主动响应组件初始化 $wechatObj->setAutoSendOpenidSwitch(TRUE); //设置自动附带发送Openid $wechatObj->setPassiveAscSwitch(TRUE, TRUE); //设置打开被动关联组件,并获取用户详细信息 $wechatObj->getRev(); $revtype = $wechatObj->getRev()->getRevType(); switch ($revtype) { case Wechat::MSGTYPE_TEXT: if (strstr($wechatObj->getRevContent(), "dddddddCSdddddsddddddd")) { $wechatObj->text("是英明的小弟。")->reply(); } elseif (strstr($wechatObj->getRevContent(), "ligboy")) { $wechatObj->text("是你英明的老大啊。\n\n你快点叫老大吧。")->reply(); } elseif (preg_match('/^[\\s]*?帮助[\\s]*?$/', $wechatObj->getRevContent()) || preg_match('/^[\\s]*?help[\\s]*?$/', $wechatObj->getRevContent())) { $wechatObj->text("福大人帮助-有效的指令\n我的图书馆\n绑定图书馆\n取消绑定图书馆\n借阅信息\n")->reply(); } else { $wechatObj->text("福大人帮助-有效的指令\n我的图书馆\n绑定图书馆 卡号 密码\n取消绑定图书馆\n借阅信息 卡号 密码")->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;
// 获取菜单操作: $menu = $weObj->getMenu(); // 设置菜单 $newmenu = array("button" => array(array('name' => '医院信息', 'sub_button' => array(array("type" => "view", 'name' => '医院主页', "url" => "http://www.blkqyy.com/"), array("type" => "click", 'name' => '门诊时间', "key" => "time"), array("type" => "view", 'name' => '医院地址', "url" => "http://blkqyy.com/wap.php/index-map.html"), array("type" => "view", 'name' => '专业团队', "url" => "http://mp.weixin.qq.com/s?__biz=MzA3NDEyMTcxMw==&mid=202512101&idx=1&sn=478061005d164632ccbb3a79b36d5e85#rd"))), array('name' => '就医导航', 'sub_button' => array(array('type' => 'click', 'name' => '常见咨询', 'key' => 'quest'), array('type' => 'click', 'name' => '我要留言', 'key' => 'liuyan'), array('type' => 'view', 'name' => '来院导航', 'url' => 'http://map.wap.soso.com/x/index.jsp?welcomeChange=1&sid=AfYicfAV0b1upF4O4-Lnzj_z&welcomeClose=1&hideAdvert=hide&type=infowindow&open=1&address=中国浙江省宁波市北仑区星中路7号&name=宁波市北仑口腔&referer=weixinmp_profile&g_ut=3&Y=29.910579&X=121.84133&Z=16&from=singlemessage&'), array('type' => 'view', 'name' => '在线咨询', 'url' => 'http://dx.zoosnet.net/lrserver/LR/Chatpre.aspx?id=LZS32497012'))), array('name' => '爱牙知识', 'sub_button' => array(array('type' => 'view', 'name' => '成人宣教视频', 'url' => 'http://mp.weixin.qq.com/s?__biz=MzA3NDEyMTcxMw==&mid=200521821&idx=1&sn=1272b4da141a38ab66bfab0d1e64b4b4#rd'), array('type' => 'view', 'name' => '儿童宣教视频', 'url' => 'http://mp.weixin.qq.com/s?__biz=MzA3NDEyMTcxMw==&mid=200276316&idx=1&sn=8695db64330bd7129786e2b4f769c32c#rd'), array('type' => 'view', 'name' => '爱牙知识讲堂', 'url' => 'http://mp.weixin.qq.com/s?__biz=MzA3NDEyMTcxMw==&mid=203297479&idx=1&sn=dd41afb15383148c9b353e61e210d394#rd'), array('type' => 'view', 'name' => '最新资讯', 'url' => 'http://mp.weixin.qq.com/s?__biz=MzA3NDEyMTcxMw==&mid=203379412&idx=1&sn=39fc677860d67d5fea82ff924cde88a4#rd'))))); $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();
<?php header("Content-type: text/html; charset=utf-8"); //微信服务端引用 require './wechat/wechat.class.php'; $options = array('token' => 'scubike', 'appid' => 'YOUR_APPID', 'appsecret' => 'YOUR_APPSECRET'); $systemError = "系统错误,请稍后再试"; $apiUrl = "http://1.scubiketest.sinaapp.com"; $apiSuffix = "php"; $w = new Wechat($options); $w->valid(); $type = $w->getRev()->getRevType(); switch ($type) { case Wechat::MSGTYPE_TEXT: $w->text("感谢您的留言,稍后回复您!")->reply(); break; case Wechat::MSGTYPE_EVENT: $result = $w->getRevEvent(); switch ($result['event']) { case 'subscribe': if ($w->getRevSceneId()) { //0.将该扫描事件写入数据库,扫描时间,用户id, $postScanurl = $apiUrl . "/postScan." . $apiSuffix; //写入扫描时间的api @post $param = array('wechatId' => $w->getRevFrom(), 'createAt' => $w->getRevCtime(), 'stationId' => $w->getRevSceneId(), 'status' => 0); http_post($postScanurl, $param); //1.检查数据库是否有该用户 $getUserinfoUrl = $apiUrl . "/getUserinfo." . $apiSuffix . "?wechatId=" . $w->getRevFrom(); $userinfo = json_decode(http_get($getUserinfoUrl)); //2.如果有,查询该用户是否有借车行为 if ($userinfo->status == "0") {
$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': $god = array("0" => array('Title' => '神制作我的时候【第二弹夏日特制版】', 'Description' => '神制作我的时候【第二弹夏日特制版】', 'PicUrl' => 'http://cdn-cn.vonvon.net/vonvon-cn-real/editor/1435891488403-VNAPCjjJcyU3cqxw.jpg', 'Url' => 'http://cn.vonvon.net/quiz/380'), "1" => array('Title' => '神制作我的时候', 'Description' => '神制作我的时候', 'PicUrl' => 'http://cdn-cn.vonvon.net/vonvon-cn-real/editor/mig/2015-06-11/a63b5eb123914f85a5e15ede5561c80b', 'Url' => 'http://cn.vonvon.net/quiz/341')); $weObj->news($god)->reply();
if (WECHAT_ENCODING_ENABLE) { $options = array('token' => WECHAT_TOKEN, 'encodingaeskey' => WECHAT_ENCODING_AES_KEY, 'appid' => WECHAT_APP_ID, 'appsecret' => WECHAT_APP_SECRET); } else { $options = array('token' => WECHAT_TOKEN); } $weObj = new Wechat($options); $weObj->valid(); $type = $weObj->getRev()->getRevType(); switch ($type) { case Wechat::MSGTYPE_TEXT: $content = $weObj->getRev()->getRevContent(); if ($content == WEIXIN_AUTH_MESSAGE) { $fromUserName = $weObj->getRev()->getRevFrom(); $url = SERVER_HOST . "/guest/sdk/weixin/redirct.php?fromUserName="******"<a href='{$url}'>点击上网</a>"; $weObj->text($text)->reply(); } break; case Wechat::MSGTYPE_EVENT: $revEvent = $weObj->getRev()->getRevEvent(); $event = strtolower($revEvent['event']); if ($event == 'subscribe') { //关注微信操作 $weObj->text(WEIXIN_WELCOME_MESSAGE)->reply(); } else { if ($event == 'unsubscribe') { //取消关注微信操作 $fromUserName = $weObj->getRev()->getRevFrom(); //取消上网权限 $sql = "select * from " . WEIXIN_TABLE . "\n WHERE `fromUserName` = '{$fromUserName}'"; $res = $mysql::query($sql, 'all');
public function add() { include "./wechat-php-sdk/wechat.class.php"; $options = array('token' => 'tokenaccesskey'); $weObj = new Wechat($options); $weObj->valid(); $type = $weObj->getRev()->getRevType(); switch ($type) { case Wechat::MSGTYPE_TEXT: $weObj->text("hello, I'm wechat")->reply(); exit; break; case Wechat::MSGTYPE_EVENT: break; case Wechat::MSGTYPE_IMAGE: break; default: $weObj->text("help info")->reply(); } }
$string = str_replace('*', '', $string); $string = str_replace('"', '"', $string); $string = str_replace("'", '', $string); $string = str_replace('"', '', $string); $string = str_replace(';', '', $string); $string = str_replace('<', '<', $string); $string = str_replace('>', '>', $string); $string = str_replace("{", '', $string); $string = str_replace('}', '', $string); $string = str_replace(' ', '', $string); return $string; } switch ($type) { /*关注事件回复*/ case Wechat::MSGTYPE_EVENT: $weObj->text("hello, I'm wechat\n平台现有功能:\n智能聊天,成语接龙,谁是卧底游戏")->reply(); exit; break; /*文本事件回复*/ /*文本事件回复*/ case Wechat::MSGTYPE_TEXT: if (substr($content, 0, 12) == "成语接龙") { $lock = "idioms"; upuserlock($lock, $username); $content = substr($content, 12); } if (substr($content, 0, 12) == "谁是卧底") { $lock = "under_cover"; upuserlock($lock, $username); $content = substr($content, 12); }
<?php include "../qywechat.class.php"; function logg($text) { file_put_contents('./log.txt', $text . "\r\n\r\n", FILE_APPEND); } $options = array('token' => '9xxxxxxxxxxxx', 'encodingaeskey' => 'd4oxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'appid' => 'wxa0xxxxxxxxxx', 'debug' => true, 'logcallback' => 'logg'); logg("GET参数为:\n" . var_export($_GET, true)); $weObj = new Wechat($options); $ret = $weObj->valid(); if (!$ret) { logg("验证失败!"); var_dump($ret); exit; } $f = $weObj->getRev()->getRevFrom(); $t = $weObj->getRevType(); $d = $weObj->getRevData(); $weObj->text("你好!来自星星的:" . $f . "\n你发送的" . $t . "类型信息:\n原始信息如下:\n" . var_export($d, true))->reply(); logg("-----------------------------------------");
<?php include "wechat.class.php"; $options = array(); $weObj = new Wechat($options); //$weObj->valid(); $type = $weObj->getRev()->getRevType(); $userId = "无所谓的疯狂"; switch ($type) { case Wechat::MSGTYPE_TEXT: $result = 'hello,' . $weObj->getRev()->getRevFrom() . ", " . $weObj->getRev()->getRevContent(); $weObj->text($result)->reply(); exit; break; case Wechat::MSGTYPE_EVENT: $arrayEvent = $weObj->getRev()->getRevEvent(); $eventResult = $arrayEvent['event'] . " : " . $arrayEvent['key']; $weObj->text($eventResult)->reply(); break; case Wechat::MSGTYPE_IMAGE: $imageurl = $weObj->getRev()->getRevPic(); $weObj->text('hello, ' . $imageurl)->reply(); break; default: $weObj->showNum(); $result2 = 'hello, ' . $weObj->getRev()->getRevFrom() . $weObj->getRev()->getRevContent(); $weObj->text($result2)->reply(); }
<?php /** * 微信公共接口测试 * */ include "../wechat.class.php"; function logdebug($text) { file_put_contents('../data/log.txt', $text . "\n", FILE_APPEND); } $options = array('token' => 'tokenaccesskey', 'debug' => true, 'logcallback' => 'logdebug'); $weObj = new Wechat($options); $weObj->valid(); $type = $weObj->getRev()->getRevType(); switch ($type) { case Wechat::MSGTYPE_TEXT: $weObj->text("hello, I'm wechat")->reply(); exit; break; case Wechat::MSGTYPE_EVENT: break; case Wechat::MSGTYPE_IMAGE: break; default: $weObj->text("help info")->reply(); }
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(); }
//$text = curl('http://119.29.78.76/gdmuwx/report.php'); $query = $_SGLOBAL['db']->query("SELECT * FROM " . tname('wxtextmsg') . " WHERE status='0'"); $text = ''; while ($read = $_SGLOBAL['db']->fetch_array($query)) { foreach ($read as $key => $value) { $text .= $key . ' : ' . $value . "\n"; } $text .= "\n"; } if (empty($text)) { $text = 'no new message'; } else { $text = substr($text, 0, strlen($text) - 2 * strlen("\n")); updatetable('wxtextmsg', array('status' => 1), array('status' => 0)); } $weObj->text($text)->reply(); exit; } } unset($revdata['MsgType']); $revdata['CreateTime'] = date("Y-m-d H:i:s", $revdata['CreateTime']); inserttable('wxtextmsg', $revdata); if (preg_match("/.*报修.*/", $revdata['Content'])) { $time24 = date("Y-m-d H:i:s", time() - 1 * 24 * 60 * 60); //$weObj->text(serialize(array('status'=>'服务器正在维护中...','revdata'=> $revdata,'test'=>"SELECT * FROM WHERE FromUserName='******'FromUserName']}' AND CreateTime > {$time24} ORDER BY CreateTime desc limit 1")))->reply(); //exit; if (!$super) { $query = $_SGLOBAL['db']->query("SELECT * FROM " . tname('wxbx') . " WHERE FromUserName='******'FromUserName']}' AND CreateTime > '{$time24}' ORDER BY CreateTime desc limit 1"); if ($nearbx = $_SGLOBAL['db']->fetch_array($query)) { $msg = '你好!' . $nearbx['stuname'] . "同学,你在 {$nearbx['CreateTime']} 已经报修了!24小时之内,您已经报修一次了,请耐心等待,谢谢!"; $weObj->text($msg)->reply();
} break; } if (bind_check()) { if ($operation == BIND) { $text = ALREADY_BINDED; } else { if ($operation == HOT) { $text = search(NULL, HOT); } else { if ($operation == NEWLY) { $text = search(NULL, NEWLY); } else { if ($operation == STATUS) { $text = user_status(); } else { if ($operation == SEARCH) { $text = search($keyword, NULL); } else { $text = HELP; } } } } } } else { $text = user_bind(); } //echo $text; $weObj->text($text); $weObj->reply();
require_once 'function.php'; include 'emoji.php'; $options = array('token' => WX_TOKEN, 'appid' => WX_APPID, 'encodingaeskey' => WX_KEY, 'appsecret' => WX_SECRET); $weObj = new Wechat($options); $weObj->valid(); $redirectURI = urlencode("http://" . WX_URL . "/main.php"); $authURI = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . WX_APPID . "&redirect_uri=" . $redirectURI . "&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"; $type = $weObj->getRev()->getRevType(); switch ($type) { case Wechat::MSGTYPE_IMAGE: $pic = $weObj->getRevPic(); $db = new DB(); $db->connect(); $userInfo = $db->getInfo($weObj->getRevFrom()); if ($userInfo['state'] != 0) { $weObj->text("你已经通过认证!")->reply(); } else { $db->postImg($weObj->getRevFrom(), $pic['mediaid']); if ($userInfo['pic']) { $weObj->text("成功修改证件照片!")->reply(); } else { $weObj->text("成功录入证件照片!\n再次提交即可修改")->reply(); } } $db->disconnect(); break; case Wechat::MSGTYPE_TEXT: $weObj->text("你好,欢迎来到imall 公益电商平台 和" . WX_TITLE . " 校园公共自行车服务!\n\n<a href='http://www.imall365.org'>点此开始imall公益电商之旅!</a>\n<a href='" . $authURI . "'>点此开始你的" . WX_TITLE . "!</a>")->reply(); break; case Wechat::MSGTYPE_EVENT: $e = $weObj->getRevEvent();
if (WECHAT_ENCODING_ENABLE) { $options = array('token' => WECHAT_TOKEN, 'encodingaeskey' => WECHAT_ENCODING_AES_KEY, 'appid' => WECHAT_APP_ID, 'appsecret' => WECHAT_APP_SECRET); } else { $options = array('token' => WECHAT_TOKEN); } $weObj = new Wechat($options); $weObj->valid(); $type = $weObj->getRev()->getRevType(); switch ($type) { case Wechat::MSGTYPE_TEXT: $content = $weObj->getRev()->getRevContent(); if ($content == WEIXIN_AUTH_MESSAGE) { $fromUserName = $weObj->getRev()->getRevFrom(); $url = SERVER_HOST . "/guest/sdk/weixin/redirct.php?fromUserName="******"<a href='{$url}'>点击上网</a>"; $weObj->text($text)->reply(); } break; case Wechat::MSGTYPE_EVENT: $revEvent = $weObj->getRev()->getRevEvent(); $event = $revEvent['event']; if ($event == 'subscribe') { //关注微信操作 $weObj->text(WEIXIN_WELCOME_MESSAGE)->reply(); } else { if ($event == 'unsubscribe') { //取消关注微信操作 $fromUserName = $weObj->getRev()->getRevFrom(); //取消上网权限 $sql = "select * from " . WEIXIN_TABLE . "\n WHERE `fromUserName` = '{$fromUserName}'"; $res = $mysql::query($sql, 'all');
'Description'=>'开发人员通道', 'PicUrl'=>'http://233.weego.sinaapp.com/images/weego_400_200.png', 'Url'=>'http://233.weego.sinaapp.com/web/home.php?wxid='.$fromUsername ) ); } $weObj->news($news)->reply(); exit; break; case Wechat::MSGTYPE_EVENT: break; case Wechat::MSGTYPE_IMAGE: /**********图片信息**********/ $imgUrl = $weObj->getRev()->getRevPic(); $resultStr = face($imgUrl); $weObj->text($resultStr)->reply(); break; default: $weObj->text("Default")->reply(); } // 调用人脸识别的API返回识别结果 function face($imgUrl) { // face++ 链接 $jsonStr = file_get_contents("http://apicn.faceplusplus.com/v2/detection/detect?url=".$imgUrl."&api_key=5eb2c984ad24ffc08c352bdb53ee52f8&api_secret=ViX19uvxkT_A0a6d55Hb0Q0QGMTqZ95f&&attribute=glass,pose,gender,age,race,smiling"); $replyDic = json_decode($jsonStr); $resultStr = ""; $faceArray = $replyDic->{'face'}; $resultStr .= "图中共检测到".count($faceArray)."张脸!\n"; for ($i= 0;$i< count($faceArray); $i++){