/** * 接收文字型事件并且响应之 * @param string $recivedContent 传入文字 * @return mixed 字符串或者数组 */ private function handleText($recivedContent) { $content = clean_content($recivedContent); $accountBindRegexStr = "/#(.*?)#(\\d{11,30})#/"; $pregResult = preg_match_all($accountBindRegexStr, $content, $matches); if ($pregResult) { // if preg successful // $result = array( // 'server' => $matches[1][0], // 'userid' => $matches[2][0] // ); // $result = json_encode($result); // $db_data = array( // 'bindinfo' => $result // ); $db_data = array('server' => $matches[1][0], 'gameuid' => $matches[2][0]); // $user_info = $this->user->user_get(array('wid' => $this->wid, 'openid' => $this->wechat->getRev()->getRevFrom())); if ($this->user_details->user_details_mod(array('raw_openid' => $this->wechat->getRev()->getRevFrom()), $db_data)) { return "更新账号绑定信息成功"; } } $re = false; $keyword = $content; // 尝试匹配手机号 $phone_reg = '#(\\D|^)(\\d{11})(\\D|$)#'; if (preg_match($phone_reg, $content, $matches)) { $phone_num = $matches[2]; $result_arr = $this->reply->get_by_wid_cat_name($this->wid, 'phone_num_match'); if (!empty($result_arr)) { $re = $result_arr[0]; } } // 如果没有手机号匹配或者没有设定手机号匹配的回复内容,尝试关键词严格匹配 if (empty($re)) { $result_arr = $this->reply->get_exact_matches($this->wid, $keyword); if (empty($result_arr)) { // 如果没有关键词严格匹配,尝试关键词模糊匹配 $record_arr = $this->reply->get_by_wid_cat_name($this->wid, 'vague_match'); foreach ($record_arr as $record) { if (strpos($keyword, $record['alias1']) !== false || strpos($keyword, $record['alias2']) !== false) { $re = $record; break; } } } else { $re = $result_arr[0]; } } //查询到关键词的信息 if ($re) { $reply_type = $re['reply_type']; //文本型回复 返回处理过的文字内容 if ($reply_type == "text") { return $re['reply']; } if ($reply_type == "news") { //不return 在这里直接reply if ($re['extra'] != "" || $re['extra'] != null) { $img_msg = json_decode($re['extra'], true); //回复内容 // var_dump($img_msg); $this->wechat->news($img_msg)->reply(); } else { return "内容为空"; } } if ($reply_type == "event") { //签到事件 if ($re['extra'] != "" || $re['extra'] != null) { $checkin_txt = json_decode($re['extra'], true); $re = $this->checkin($this->wechat->getRev()->getRevFrom()); if ($re) { if ($re['status']) { //签到成功 $result = str_replace(array("%scount", "%lcount", "%smark", "%cmark"), array($re['scount'], $re['lcount'], $re['smark'], $re['cmark']), $checkin_txt['reply_success']); if (isset($re['lottery'])) { // $result .= "您已经积攒".$re['lottery']."次抽奖机会了."; } return $result; } else { if (!$re['status']) { return str_replace(array("%smark"), array($re['smark']), $checkin_txt['reply_failed']); } } } } } if ($reply_type == "code") { //发码 if ($re['extra'] != "" || $re['extra'] != null) { $code_txt = json_decode($re['extra'], true); //先判是否领取过码 if ($oCode = $this->isDrawCode($this->wechat->getRev()->getRevFrom(), $code_txt['reply_event'])) { return "您已经领取过本次活动的礼包码,码为" . $oCode; // } //先判断是Apibox发码还是本地发码 if ($code_txt['method'] == "apibox") { //如果是apibox $wechat_info = $this->setting->setting_get(array('flag' => $this->flag)); $options = array('http' => array('user_agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36')); $context = stream_context_create($options); if ($code_txt['language'] == "simple") { //简体中文apibox发码渠道 $simpleApi = sprintf("http://apibox.mobage.cn/api/index.php/kit/api_comp/mid_post/32?__APP=%s&phone=%s&event=%s", $wechat_info['packageAppid'], $this->wechat->getRev()->getRevFrom(), $code_txt['reply_event']); $packageRe = file_get_contents($simpleApi, false, $context); if ($packageRe) { $packageReDe = json_decode($packageRe, true); if ($packageReDe['error_code'] == "0" || $packageReDe['error_code'] == "10") { //发码API无错误 $code = $packageReDe['code']; $this->tagDrawed($this->wechat->getRev()->getRevFrom(), $code_txt['reply_event'], $code); return str_replace(array("%code"), array($code), $code_txt['reply_success']); } else { return "发码接口异常"; } } } if ($code_txt['language'] == "trad") { //繁体中文apibox发码渠道 $tradApi = sprintf("http://apibox.mobage.cn/api/index.php/kit/api_comp/mid_post/49?__APP=%s&phone=%s&event=%s", $wechat_info['packageAppid'], $this->wechat->getRev()->getRevFrom(), $code_txt['reply_event']); $packageRe = file_get_contents($tradApi, false, $context); if ($packageRe) { if ($packageRe) { $packageReDe = json_decode($packageRe, true); if ($packageReDe['error_code'] == "0" || $packageReDe['error_code'] == "10") { //发码API无错误 $code = $packageReDe['code']; $this->tagDrawed($this->wechat->getRev()->getRevFrom(), $code_txt['reply_event'], $code); return str_replace(array("%code"), array($code), $code_txt['reply_success']); } else { return "发码接口异常"; } } } } } if ($code_txt['method'] == "direct") { //如果是本地直接发码 $event = $this->event->event_get(array('event_name' => $code_txt['reply_event'])); if ($event) { $code = $this->code->code_get_random($this->wid, $event['gid']); if ($code) { $this->code->code_mod(array('cid' => $code['cid']), array('isUsed' => 1, 'usedTime' => time())); //标记用户已经领取的礼包活动和礼包码 $this->tagDrawed($this->wechat->getRev()->getRevFrom(), $code_txt['reply_event'], $code['code']); return str_replace(array("%code"), array($code['code']), $code_txt['reply_success']); } } return $code_txt['reply_failed']; } } } if ($reply_type == "lottery") { if ($re['extra'] != "" || $re['extra'] != null) { $lottery_txt = json_decode($re['extra'], true); if ($lottery_txt['method'] == "local") { //判断下奖池来源 为了将来可能拓展到apibox //先判断是否在有效期 $start_time = $lottery_txt['start_time'] / 1000; //除以1000 把时间戳还原回标准格式 $end_time = $lottery_txt['end_time'] / 1000; //同上 $now_time = time(); if ($now_time < $start_time || $now_time > $end_time) { return $lottery_txt['reply_pending']; } //获取用户详细信息 $user_info = $this->user->user_get(array("wid" => $this->wid, "openid" => $this->wechat->getRev()->getRevFrom())); $user_info_detail = $this->user_details->user_details_get(array('uid' => $user_info['uid'])); if ($lottery_txt['lmethod'] == "marks") { //如果是积分抽奖 if ($user_info_detail['integration'] > $lottery_txt['marks']) { //从奖池拿一个奖品出来先 代码等同于领礼包码 $event = $this->event->event_get(array('event_name' => $lottery_txt['lottery_event'])); if ($event) { $code = $this->code->code_get_random($this->wid, $event['gid']); if ($code) { //减掉一个抽奖机会 $this->user_details->user_details_mod(array('uid' => $user_info['uid']), array('integration' => $user_info_detail['integration'] - $lottery_txt['marks'])); $this->code->code_mod(array('cid' => $code['cid']), array('isUsed' => 1, 'usedTime' => time())); //将奖品置为已领取 return str_replace(array("%code"), array($code['code']), $lottery_txt['reply_success']); } else { return "您来晚了,奖品都被抢光了"; } } } else { return str_replace(array("%dmark"), array($user_info_detail['integration'] - $lottery_txt['marks']), $lottery_txt['reply_failed']); } } if ($lottery_txt['lmethod'] == "lottery") { //如果是抽奖机会抽奖 //判断是否具有抽奖资格 //先判断用户现在是否有抽奖机会 //判断用户总积分是否达到条件 if ($user_info_detail['integration'] > $lottery_txt['rules'] && $user_info_detail['lottery'] > 0) { //从奖池拿一个奖品出来先 代码等同于领礼包码 $event = $this->event->event_get(array('event_name' => $lottery_txt['lottery_event'])); if ($event) { $code = $this->code->code_get_random($this->wid, $event['gid']); if ($code) { //减掉一个抽奖机会 $this->user_details->user_details_mod(array('uid' => $user_info['uid']), array('lottery' => $user_info_detail['lottery'] - 1)); $this->code->code_mod(array('cid' => $code['cid']), array('isUsed' => 1, 'usedTime' => time())); //将奖品置为已领取 return str_replace(array("%code"), array($code['code']), $lottery_txt['reply_success']); } else { return "您来晚了,奖品都被抢光了"; } } } else { return $lottery_txt['reply_failed']; } } } } } } else { //查找默认条目的回复信息 $re = $this->reply->reply_get(array('wid' => $this->wid, 'alias1' => 'default'), array('alias2' => '默认回复信息')); if ($re) { $reply_type = $re['reply_type']; //文本型回复 返回处理过的文字内容 if ($reply_type == "text") { return $re['reply']; } if ($reply_type == "news") { //不return 在这里直接reply if ($re['extra'] != "" || $re['extra'] != null) { $img_msg = json_decode($re['extra'], true); //回复内容 // var_dump($img_msg); $this->wechat->news($img_msg)->reply(); } else { return "内容为空"; } } if ($reply_type == "event") { //签到事件 if ($re['extra'] != "" || $re['extra'] != null) { $checkin_txt = json_decode($re['extra'], true); $re = $this->checkin($this->wechat->getRev()->getRevFrom()); if ($re) { if ($re['status']) { //签到成功 $result = str_replace(array("%scount", "%lcount", "%smark", "%cmark"), array($re['scount'], $re['lcount'], $re['smark'], $re['cmark']), $checkin_txt['reply_success']); if (isset($re['lottery'])) { // $result .= "您已经积攒".$re['lottery']."次抽奖机会了."; } return $result; } else { if (!$re['status']) { return str_replace(array("%smark"), array($re['smark']), $checkin_txt['reply_failed']); } } } } } if ($reply_type == "code") { //发码 if ($re['extra'] != "" || $re['extra'] != null) { $code_txt = json_decode($re['extra'], true); //先判是否领取过码 if ($oCode = $this->isDrawCode($this->wechat->getRev()->getRevFrom(), $code_txt['reply_event'])) { return "您已经领取过本次活动的礼包码,码为" . $oCode; // } //先判断是Apibox发码还是本地发码 if ($code_txt['method'] == "apibox") { //如果是apibox $wechat_info = $this->setting->setting_get(array('flag' => $this->flag)); $options = array('http' => array('user_agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36')); $context = stream_context_create($options); if ($code_txt['language'] == "simple") { //简体中文apibox发码渠道 $simpleApi = sprintf("http://apibox.mobage.cn/api/index.php/kit/api_comp/mid_post/32?__APP=%s&phone=%s&event=%s", $wechat_info['packageAppid'], $this->wechat->getRev()->getRevFrom(), $code_txt['reply_event']); $packageRe = file_get_contents($simpleApi, false, $context); if ($packageRe) { $packageReDe = json_decode($packageRe, true); if ($packageReDe['error_code'] == "0" || $packageReDe['error_code'] == "10") { //发码API无错误 $code = $packageReDe['code']; $this->tagDrawed($this->wechat->getRev()->getRevFrom(), $code_txt['reply_event'], $code); return str_replace(array("%code"), array($code), $code_txt['reply_success']); } else { return "发码接口异常"; } } } if ($code_txt['language'] == "trad") { //繁体中文apibox发码渠道 $tradApi = sprintf("http://apibox.mobage.cn/api/index.php/kit/api_comp/mid_post/49?__APP=%s&phone=%s&event=%s", $wechat_info['packageAppid'], $this->wechat->getRev()->getRevFrom(), $code_txt['reply_event']); $packageRe = file_get_contents($tradApi, false, $context); if ($packageRe) { if ($packageRe) { $packageReDe = json_decode($packageRe, true); if ($packageReDe['error_code'] == "0" || $packageReDe['error_code'] == "10") { //发码API无错误 $code = $packageReDe['code']; $this->tagDrawed($this->wechat->getRev()->getRevFrom(), $code_txt['reply_event'], $code); return str_replace(array("%code"), array($code), $code_txt['reply_success']); } else { return "发码接口异常"; } } } } } if ($code_txt['method'] == "direct") { //如果是本地直接发码 $event = $this->event->event_get(array('event_name' => $code_txt['reply_event'])); if ($event) { $code = $this->code->code_get_random($this->wid, $event['gid']); if ($code) { $this->code->code_mod(array('cid' => $code['cid']), array('isUsed' => 1, 'usedTime' => time())); //标记用户已经领取的礼包活动和礼包码 $this->tagDrawed($this->wechat->getRev()->getRevFrom(), $code_txt['reply_event'], $code['code']); return str_replace(array("%code"), array($code['code']), $code_txt['reply_success']); } } return $code_txt['reply_failed']; } } } if ($reply_type == "lottery") { if ($re['extra'] != "" || $re['extra'] != null) { $lottery_txt = json_decode($re['extra'], true); if ($lottery_txt['method'] == "local") { //判断下奖池来源 为了将来可能拓展到apibox //先判断是否在有效期 $start_time = $lottery_txt['start_time'] / 1000; //除以1000 把时间戳还原回标准格式 $end_time = $lottery_txt['end_time'] / 1000; //同上 $now_time = time(); if ($now_time < $start_time || $now_time > $end_time) { return $lottery_txt['reply_pending']; } //获取用户详细信息 $user_info = $this->user->user_get(array("wid" => $this->wid, "openid" => $this->wechat->getRev()->getRevFrom())); $user_info_detail = $this->user_details->user_details_get(array('uid' => $user_info['uid'])); if ($lottery_txt['lmethod'] == "marks") { //如果是积分抽奖 if ($user_info_detail['integration'] > $lottery_txt['marks']) { //从奖池拿一个奖品出来先 代码等同于领礼包码 $event = $this->event->event_get(array('event_name' => $lottery_txt['lottery_event'])); if ($event) { $code = $this->code->code_get_random($this->wid, $event['gid']); if ($code) { //减掉一个抽奖机会 $this->user_details->user_details_mod(array('uid' => $user_info['uid']), array('integration' => $user_info_detail['integration'] - $lottery_txt['marks'])); $this->code->code_mod(array('cid' => $code['cid']), array('isUsed' => 1, 'usedTime' => time())); //将奖品置为已领取 return str_replace(array("%code"), array($code['code']), $lottery_txt['reply_success']); } else { return "您来晚了,奖品都被抢光了"; } } } else { return str_replace(array("%dmark"), array($user_info_detail['integration'] - $lottery_txt['marks']), $lottery_txt['reply_failed']); } } if ($lottery_txt['lmethod'] == "lottery") { //如果是抽奖机会抽奖 //判断是否具有抽奖资格 //先判断用户现在是否有抽奖机会 //判断用户总积分是否达到条件 if ($user_info_detail['integration'] > $lottery_txt['rules'] && $user_info_detail['lottery'] > 0) { //从奖池拿一个奖品出来先 代码等同于领礼包码 $event = $this->event->event_get(array('event_name' => $lottery_txt['lottery_event'])); if ($event) { $code = $this->code->code_get_random($this->wid, $event['gid']); if ($code) { //减掉一个抽奖机会 $this->user_details->user_details_mod(array('uid' => $user_info['uid']), array('lottery' => $user_info_detail['lottery'] - 1)); $this->code->code_mod(array('cid' => $code['cid']), array('isUsed' => 1, 'usedTime' => time())); //将奖品置为已领取 return str_replace(array("%code"), array($code['code']), $lottery_txt['reply_success']); } else { return "您来晚了,奖品都被抢光了"; } } } else { return $lottery_txt['reply_failed']; } } } } } } } }
function print_blog_content($item, $full = true) { if ($full) { echo clean_content($item->post_content); } else { echo substr(clean_content($item->post_content), 0, 100) . '...'; } }