/** * 微信valid * * @return void * @author niancode **/ function wx_valid() { $wx = new Wxauth(); return $wx->wx_valid(); }
/** * undocumented function * * @param string $id * @return void * @author apple */ public function index($id) { $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; $wx = new Wxauth($this->wxToken); if (!empty($postStr)) { $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $fromUsername = $postObj->FromUserName; $toUsername = $postObj->ToUserName; $keyword = trim($postObj->Content); $time = time(); $msgType = $postObj->MsgType; $textTpl = "<xml>\n\t\t\t\t\t\t<ToUserName><![CDATA[%s]]></ToUserName>\n\t\t\t\t\t\t<FromUserName><![CDATA[%s]]></FromUserName>\n\t\t\t\t\t\t<CreateTime>%s</CreateTime>\n\t\t\t\t\t\t<MsgType><![CDATA[%s]]></MsgType>\n\t\t\t\t\t\t<Content><![CDATA[%s]]></Content>\n\t\t\t\t\t\t<FuncFlag>0</FuncFlag>\n\t\t\t\t\t\t</xml>"; // WX Code.. $wxid = $this->WxWebchat->getWxId($toUsername); if ($wxid) { $this->WxSession->setWxId($wxid); switch ($msgType) { case 'text': $keyExits = array('退出', '-1', '88', 'bye', '888', '再见'); if (in_array($keyword, $keyExits)) { $this->WxSession->delete('RWX.APPID'); $contentStr = "您已经退出互动应用。"; } else { switch ($this->WxSession->read('RWX.APPID')) { case '1': $data = array('answer' => array('你的名字是?', '你的电话是?'), 'successMsg' => "恭喜您,提交成功。", 'errorMsg' => "对不起提交失败,请尝试。"); $ansid = $this->WxSession->read('RWX.APPANS'); if (count($data['answer']) == $ansid) { $cstr = $data['answer']['successMsg']; } $cstr = isset($data['answer'][$ansid]) ? $data['answer'][$ansid] : reset($data['answer']); $contentStr = $cstr; $this->WxSession->write('RWX.APPANS', $ansid + 1); break; case '2': $contentStr = "这里是找同学"; break; case '3': $contentStr = "这里是附近的同学"; break; case '4': $contentStr = "这里是我的班级"; break; case '5': $contentStr = "这里是我的学校"; break; case '6': $contentStr = "这里是个人信息"; break; case '7': $contentStr = "这里是便捷小工具"; break; case '8': $contentStr = "关于我们"; break; default: if ($keyword == '1') { $this->WxSession->write('RWX.APPID', '1'); $contentStr = "你好,欢迎使用微官网。"; } else { if ($keyword == '2') { $this->WxSession->write('RWX.APPID', '2'); $contentStr = "你好,欢迎使用找同学。"; } else { if ($keyword == '3') { $this->WxSession->write('RWX.APPID', '3'); $contentStr = "你好,欢迎使用附近的同学。"; } else { if ($keyword == '4') { $this->WxSession->write('RWX.APPID', '4'); $contentStr = "你好,欢迎使用我的班级。"; } else { if ($keyword == '5') { $this->WxSession->write('RWX.APPID', '5'); $contentStr = "你好,欢迎使用我的学校。"; } else { if ($keyword == '6') { $this->WxSession->write('RWX.APPID', '6'); $contentStr = "你好,欢迎使用个人信息。"; } else { if ($keyword == '7') { $this->WxSession->write('RWX.APPID', '7'); $contentStr = "你好,欢迎使用便捷小工具。"; } else { if ($keyword == '8') { $this->WxSession->write('RWX.APPID', '8'); $contentStr = "关于我们。"; } else { $contentStr = $this->WxWebchat->getMsg('text', $keyword, $toUsername); } } } } } } } } } } $msgType = "text"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; break; case 'event': $event = $postObj->Event; if ($event == 'subscribe') { $contentStr = $this->WxWebchat->getMsg('subscribe', $keyword, $toUsername); $msgType = "text"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; } break; default: } } else { echo '亲,您的账号还没有配置成功。[在微信]'; // Check wxid } } else { $wx->wx_valid(); } $this->render('/Wx/api'); }