public function __construct(Wechat $wechat) { $this->content = $wechat->getRev()->getRevContent(); $this->sender = $wechat->getRev()->getRevFrom(); $this->create_time = $wechat->getRev()->getRevCtime(); $this->msg_id = $wechat->getRev()->getRevID(); $this->models = new TextModel(); $this->models->actionIndex($this->content, $this->sender, $this->msg_id); }
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 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"; $options = array('token' => 'tokenaccesskey', 'encodingaeskey' => '5lLtUYtyRLDM5zCuG43TxcHpKSK5ydENbozq78XhIOi'); $weObj = new Wechat($options); $weObj->valid(); //明文或兼容模式可以在接口验证通过后注释此句,但加密模式一定不能注释,否则会验证失败 // 获取菜单操作: $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;
//$result = file_put_contents('wechat.log.'.date('Y-m-d'), $text."\n", FILE_APPEND); //if (!$result) { 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:
<?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(); }
<?php include 'config.php'; include 'wechat-php-sdk/wechat.class.php'; include 'public/fun.php'; include 'public/invitees.php'; $options = array('token' => $siteData['wechatToken'], 'appid' => $siteData['wechatAppID'], 'appsecret' => $siteData['wechatAppSecret']); $weObj = new Wechat($options); $weObj->valid(); $weObj->getRev(); /** * 自动回复 */ function msgSend($key) { global $WEDDING_INVITEES; global $weObj; $key = strtolower($key); switch ($key) { case 'welcome': // 回复文字信息 $weObj->text("欢迎关注")->reply(); /* 回复图文信息 $weObj->news( array( '0' => array( 'Title' => '标题', 'PicUrl' => '图片地址', 'Url' => '网址' ) )
function _log1($text) { //$result = file_put_contents('wechat.log.'.date('Y-m-d'), $text."\n", FILE_APPEND); //if (!$result) { openlog("wechat", LOG_PID | LOG_PERROR, LOG_LOCAL0); syslog(LOG_DEBUG, $text); closelog(); //} } $options = ['token' => 'nizhidaoma', 'encodingaeskey' => 'xc8rRK4iOQjTJK9hOYhRrC9sPBJvF5Jhjq203iMC7vF', 'appid' => 'wxe85832e232e73f41', 'appsecret' => '4c8f1aa381675dd2569fc9482052afdc', 'debug' => true, 'logcallback' => '_log1']; $csc_host_base = 'https://wechat.gds-services.com'; $csc_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: $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);
public function __construct(Wechat $wechat) { $this->sender = $wechat->getRev()->getRevFrom(); $this->event = $wechat->getRev()->getRevEvent(); $this->models = new EventModel(); }
<?php include_once '../../config.php'; $site = get_site(__DIR__); include_once CONFIG_PATH . '/' . $site . PHP_EXT; include_once WEIXIN_PATH . '/class/wechat.class.php'; 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 {
<?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") {
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(); } }
<?php @define("WE_ROOT", dirname(__FILE__) . "/"); require_once WE_ROOT . "wechat.class.php"; require_once WE_ROOT . "tuling.func.php"; require_once WE_ROOT . "idioms.func.php"; require_once WE_ROOT . "UnderCover.func.php"; $options = array('token' => 'huangang'); $weObj = new Wechat($options); $weObj->valid(); $type = $weObj->getRev()->getRevType(); $username = $weObj->getRev()->getRevFrom(); $content = $weObj->getRev()->getRevContent(); $content = safe_replace($content); $mysql = new SaeMysql(); $sql = "select * from wx_users where openid = '{$username}' "; $data = $mysql->getLine($sql); if ($data) { $lock = $data['lock']; } else { $sql = "insert into wx_users(openid) values('{$username}')"; $mysql->runSql($sql); if ($mysql->errno() != 0) { die("Error:" . $mysql->errmsg()); } $lock = "unlock"; } $mysql->closeDb(); function safe_replace($string) { $string = str_replace('%20', '', $string);
<?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(); }
require_once './config.php'; require_once './class/conn.class.php'; require_once './class/wechat.class.php'; include './include/function.php'; header('Content-type:text/html;charset=utf-8'); const ALREADY_BINDED = '你已经绑定过了'; const HELP = '支持的命令: 状态 , 查询@关键字 , 最新 , 热门'; $user_ptid = -1; $operation = 'NULL'; $text = ''; $keyword = ''; $user_openid = ''; $con = new conn(); $weObj = new Wechat($wechat_options); $weObj->valid(); $msg = $weObj->getRev()->getRevData(); //获取用户发送的消息 $user_openid = $weObj->getRev()->getRevFrom(); //获取用户openid $user_openid = $con->mres($user_openid); $msg = trim($msg['Content']); switch ($msg) { case '绑定': $operation = BIND; break; case '状态': $operation = STATUS; break; case '热门': $operation = HOT; break;
* */ date_default_timezone_set('Asia/Shanghai'); include "../Wechat.class.php"; //加载设置文件 $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();
* WeeGo工作室微信公众平台接口源码 * @author CallMeWhy <*****@*****.**> * @version 1.0 */ include "wechat.class.php"; $options = array ( 'token'=>'weego', 'debug'=>true, 'logcallback'=>'logdebug' ); $weObj = new Wechat($options); // 验证 $weObj->valid(); // 获取内容 $weObj->getRev(); // 获取用户的OpenID $fromUsername = $weObj->getRevFrom(); // 获取接受信息的类型 $type = $weObj->getRev()->getRevType(); //**********关注操作则写入数据库**********/ if($weObj->getRevSubscribe()) { // 获取用户OPENID并写入数据库 $mysql = new SaeMysql(); $sql = "INSERT INTO `users` (`wxid`) VALUES ('" . $fromUsername . "');"; $mysql->runSql($sql); $mysql->closeDb(); // 获得信息的类型 $news = array