Ejemplo n.º 1
0
function responseMsg()
{
    //get post data, May be due to the different environments
    //$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
    $postStr = file_get_contents("php://input");
    log_file("postStr:" . $postStr);
    //extract post data
    if (!empty($postStr)) {
        /* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,
           the best way is to check the validity of xml by yourself */
        libxml_disable_entity_loader(true);
        $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
        //
        $msgType = trim($postObj->MsgType);
        log_file("msgType:{$msgType}");
        switch ($msgType) {
            case "text":
                $resultStr = handleText($postObj);
                break;
            case "event":
                $resultStr = handleEvent($postObj);
                break;
            case "video":
                $resultStr = handleVideo($postObj);
                break;
            case "voice":
                $resultStr = handleVoice($postObj);
                break;
            case "image":
                $resultStr = handleImage($postObj);
                break;
            default:
                $resultStr = response_text($postObj, "");
                break;
        }
        echo $resultStr;
    } else {
        echo "";
        exit;
    }
}
Ejemplo n.º 2
0
function responseMsg()
{
    $postStr = file_get_contents("php://input");
    log_file("postStr:" . $postStr);
    if (!empty($postStr)) {
        libxml_disable_entity_loader(true);
        $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
        //
        $msgType = trim($postObj->MsgType);
        log_file("msgType:{$msgType}");
        switch ($msgType) {
            case "text":
                $resultStr = handleText($postObj);
                break;
            case "event":
                $resultStr = handleEvent($postObj);
                break;
            case "video":
                $resultStr = handleVideo($postObj);
                break;
            case "voice":
                $resultStr = handleVoice($postObj);
                break;
            case "image":
                $resultStr = handleImage($postObj);
                break;
            default:
                $resultStr = response_text($postObj, "");
                break;
        }
        echo $resultStr;
    } else {
        echo "";
        exit;
    }
}
Ejemplo n.º 3
0
define('TOKEN', '152945078:AAHRok2HuvSYRXxs55RLvVWoa0t3Org8u9c');
define('API_URL', 'https://api.telegram.org/bot' . TOKEN . '/');
define('TEST', 0);
define('TEST_MESSAGE', 'hola');
$content = file_get_contents("php://input");
$update = json_decode($content, true);
if (TEST) {
    $update = array('message' => array('text' => TEST_MESSAGE, 'message_id' => 1, 'chat' => array('id' => 1)));
}
if (isset($update['message'])) {
    $message = $update['message'];
    $message_id = $message['message_id'];
    $chat_id = $message['chat']['id'];
    $text = strtolower($message['text']);
    $from = $message['from']['first_name'];
    $response = handleText($text, $from);
    if ($response && !isMuted()) {
        if (TEST) {
            echo $response;
        } else {
            $aux = explode(':', $response);
            if (count($aux) === 2 && $aux[0] === 'sticker') {
                // NO ANDA
                apiRequestJson("sendSticker", array('chat_id' => $chat_id, 'sticker' => $aux[1]));
            } else {
                apiRequestJson("sendMessage", array('chat_id' => $chat_id, 'text' => $response));
            }
        }
    }
}
function handleTextWords($words, $from)
Ejemplo n.º 4
0
                    $description .= sprintf("\n第%s张脸\n", $i + 1);
                }
                $attr = $info[$i]['attributes'];
                $description .= "年龄: " . $attr['age'];
                $description .= "\n性别: " . $attr['gender'];
            }
            return Message::make('news')->item(Message::make("news_item")->title($title)->description($description)->url($savedUrl)->PicUrl($savedUrl));
        }
        return Message::make('text')->content($title);
    }
    return Message::make('text')->content("不好意思出错啦/:bye");
});
//语音消息处理,使用微信的识别结果
$server->on('message', 'voice', function ($message) use($welcome) {
    sae_log($message->Recogniton);
    return handleText($message->Recognition, $message->FromUserName, $welcome);
});
$result = $server->serve();
echo $result;
/**
 * 处理文字消息
 * @param $text    string
 * @param $openid  string
 * @param $welcome closure
 * @return mixed
 */
function handleText($text, $openid, $welcome)
{
    if (in_array(trim($text), array("你好", "你能干什么", "哈哈", "您好", "喂", "你有什么功能"))) {
        return Message::make('news')->items($welcome);
    }
Ejemplo n.º 5
0
<?php

require_once 'header.php';
if (!$loggedin) {
    die;
}
$text = handleText($conn, $user);
handleImage($user);
showAvatar($user);
echo <<<_END
<form method='post' action='editProfile.php' enctype='multipart/form-data'>
<h3>Enter or edit your details and/or upload an image</h3>
<textarea name='text' cols='50' rows='3'>{$text}</textarea><br>
Image: <input type='file' name='image' size='14'>
<input type='submit' value='Save Profile'>
_END;
//********Functions*************
function handleText($conn, $user)
{
    $query = "SELECT * FROM profiles WHERE user='******'";
    $result = queryMysql($conn, $query);
    if (isset($_POST['text'])) {
        $text = $_POST['text'];
        $text = $conn->real_escape_string($text);
        if ($result->num_rows) {
            $query = "UPDATE profiles SET text='{$text}' WHERE user='******'";
        } else {
            $query = "INSERT INTO profiles VALUES('{$user}', '{$text}')";
        }
        queryMysql($conn, $query);
    } else {
Ejemplo n.º 6
0
define('TOKEN', '152945078:AAHRok2HuvSYRXxs55RLvVWoa0t3Org8u9c');
define('API_URL', 'https://api.telegram.org/bot' . TOKEN . '/');
define('TEST', 0);
define('TEST_MESSAGE', 'hola');
$content = file_get_contents("php://input");
$update = json_decode($content, true);
if (TEST) {
    $update = array('message' => array('text' => TEST_MESSAGE, 'message_id' => 1, 'chat' => array('id' => 1)));
}
if (isset($update['message'])) {
    $message = $update['message'];
    $message_id = $message['message_id'];
    $chat_id = $message['chat']['id'];
    $text = $message['text'];
    $response = handleText($text);
    if ($response) {
        if (TEST) {
            echo $response;
        } else {
            $aux = explode(':', $response);
            if (count($aux) === 2 && $aux[0] === 'sticker') {
                // NO ANDA
                apiRequestJson("sendSticker", array('chat_id' => $chat_id, 'sticker' => $aux[1]));
            } else {
                apiRequestJson("sendMessage", array('chat_id' => $chat_id, 'text' => $response));
            }
        }
    }
}
function handleTextWords($words)