template內(nèi)部包含了(le)所有(yǒu)的(de)靜(jìng)₹←态html文(wén)件(jiàn)
module.php 聊天機(jī)器(qì)人(rén)模塊定義, 主要("↑πβyào)是(shì)實現(xiàn)模塊配置自(zì)定義, 保存
processor.php 處理(lǐ)用(yòng)戶發送給公衆号的(de)消息

用(yòng)戶在公衆号發送的(de)消息,會(huì)走processo©≤₹r.php 的(de)respond方法:
<?php
/**
* 聊天機(jī)器(qì)人(rén)模塊處理(lǐ)程序
☆∞≈ *
*/
defined('IN_IA') or exit™ ('Access Denied');
class Idou_cha♦≤tModuleProcessor extends WeModuleProcessor {
±®<
public function respond() {
₩∏ $config = $this->module['config']σ>;
$config['enter_tip'] || $←✘♠✔config['enter_tip'] = '你(nǐ)想聊點✘€什(shén)麽呢(ne)';
$config['keep_time']₹↔ || $config['keep_time'] = 300;
≈β✘ $config['exit_keyword'] || $config['exit_keywor§₩'d'] = '退出';
$config['exit_tip'] || $conf₩£ig['exit_tip'] = '下(xià)次無聊的(de)時(shí)候可(kě)以再γ×✘找我聊天哦';
if ($this-&g$≈±t;message['msgtype'] == 'voice') {
♠§® if ($config['can_voice'] == '1') {
≤ε $content = $this->message['recoσ®¶gnition']; // 語音(yīn)識别,直接開(kā÷≠Ωi)啓機(jī)器(qì)人(rén)聊天模式
$reply™≥ = $this->turingAPI($content);
©↓≈± if (is_array↕"♠($reply)) {
return $this-& <®¶gt;respNews($reply);
} else {↑→±ε
return $this->re₩↔spText($reply);
↓∑λΩ }
}
} e₹ ↑lse {
$content γε = $this->message['content'≈€]; // 通(tōng)過消息上(shàng)下α<$(xià)文(wén)機(jī)制(zhì)與機(jī)器(qì)人(ré♥♣×£n)展開(kāi)聊天
if "α>≈(!$this->inContext) {
∏≠ $reply = $config['enter_tip'★ →♥];
$this->begin&÷<✘Context($config['keep_time']); ×♠≥ // 5分(fēn)鐘(zhōng)後自≈δ±(zì)動退出上(shàng)下(xià)文(wén)模式
≤$←≤} else {
if ($content == < $config['exit_keyword']) {
λ÷λπ $reply = $config['exit_tip'];
≠♠ $this->endContext();
±× } else {
♥↕ $reply = $this->turingAPI($content);
γ }
↕ }
if (is_array($r&γ±σeply)) {
return $this->respNeφ♥¶ws($reply);
} else {
σ&÷≠ return $this->respText($reply);
✔¶
}
}
¥≈
}
}
2:template/setting.html是(s$δ®hì)該模塊的(de)配置文(wén)件(jiàn)
3:module.php的(de)settingsDi ∞splay方法, 指定了(le)配置文(wén)件(jiàn)所在的(de)♣→目錄位置, 內(nèi)部也(yě)處理(lǐ)了(le)配置文 ★✔©(wén)件(jiàn)信息的(de)保存
作(zuò)者: NONO
出處:http://www.cnblogs.com/diligenceday ↓₩/
企業(yè)網站(zhàn):/
開(kāi)源博客:http://www.github.com/sqqihao
QQ:287101329
微(wēi)信:18101055830