Exemple #1
0
function get_survey_old()
{
    // delivers an XML version of an entire survey
    // display will be handled client side
    global $conn;
    global $instance_id;
    global $examiner_id;
    global $examinee_id;
    $query_params[0] = intval($instance_id);
    $query_params[1] = intval($examiner_id);
    $query_params[2] = intval($examinee_id);
    //$query_params[3] = $instance_id;
    $qry = "{call EDUC\\banghart.sp_get_survey(?,?,?)}";
    $rst = sqlsrv_query($conn, $qry, $query_params);
    if (($errors = sqlsrv_errors()) != null) {
        foreach ($errors as $error) {
            echo "SQLSTATE: " . $error['SQLSTATE'] . "\n";
            echo "code: " . $error['code'] . "\n";
            echo "message: " . $error['message'] . "\n";
        }
        die('that is all');
    }
    $doc = new DOMDocument();
    $survey_element = $doc->createElement('survey');
    $survey_element->setAttribute('id', 1);
    $survey_element->setAttribute('examiner_id', $examiner_id);
    $survey_element->setAttribute('examinee_id', $examinee_id);
    $survey_element->setAttribute('instance_id', $instance_id);
    $current_item = -1;
    $in_item = 0;
    $first_row = 1;
    $itemSequence = 1;
    $current_option = -1;
    while ($row = sqlsrv_fetch_array($rst, SQLSRV_FETCH_ASSOC)) {
        if ($first_row == 1) {
            $first_row = 0;
            $survey_element->setAttribute('title', $row['template_title']);
            $survey_element->setAttribute('semester', $row['semester']);
            $survey_element->setAttribute('year', $row['year']);
            $survey_element->setAttribute('examiner_name', $row['examiner_first_name'] . ' ' . $row['examiner_last_name']);
            $survey_element->setAttribute('examinee_name', $row['examinee_first_name'] . ' ' . $row['examinee_last_name']);
            $survey_description = $doc->createElement('description');
            $description_text_node = $doc->createTextNode($row['template_description']);
            $survey_description->appendChild($description_text_node);
            $survey_element->appendChild($survey_description);
        }
        if ($row['item_id'] != $current_item) {
            $text_response_sequence = 1;
            $current_item = $row['item_id'];
            if ($in_item == 1) {
                $survey_element->appendChild($item_element);
            }
            $in_item = 1;
            $item_element = $doc->createElement('item');
            $item_element->setAttribute('item_id', $row['item_id']);
            $item_element->setAttribute('sequence', $itemSequence);
            $itemSequence++;
            $prompt_element = $doc->createElement('prompt');
            $prompt_text_node = $doc->createTextNode($row['prompt']);
            $prompt_element->appendChild($prompt_text_node);
            $item_element->appendChild($prompt_element);
            $description_element = $doc->createElement('description');
            $description_text_node = $doc->createTextNode($row['description']);
            $description_element->appendChild($description_text_node);
            $item_element->appendChild($description_element);
            $text_response_element = make_text_response($doc, $row);
            $text_response_element->setAttribute('label', 'strength');
            $item_element->appendChild($text_response_element);
            $text_response_sequence++;
            $option_element = make_item_option($doc, $row);
            $current_option = $row['option_id'];
            $item_element->appendChild($option_element);
        } else {
            if ($text_response_sequence < 3) {
                $text_response_sequence++;
                $text_response_element = make_text_response($doc, $row);
                $text_response_element->setAttribute('label', 'weakness');
                $item_element->appendChild($text_response_element);
            }
            if ($current_option != $row['option_id']) {
                $current_option = $row['option_id'];
                $option_element = make_item_option($doc, $row);
                $item_element->appendChild($option_element);
            }
        }
    }
    if ($in_item == 1) {
        $survey_element->appendChild($item_element);
    }
    header("Content-Type:text/xml");
    //echo '<test>' . $examinee_id . '</test>';
    echo $doc->saveXML($survey_element);
}
Exemple #2
0
    $echostr = $_GET["echostr"];
    $token = TOKEN;
    $arr = array($token, $timestamp, $nonce);
    sort($arr);
    $str = sha1(implode($arr));
    if ($str != $signature) {
        error_log("Validation failed");
    }
    echo $echostr;
} else {
    // wechat message handling
    $poststr = $GLOBALS["HTTP_RAW_POST_DATA"];
    if (!empty($poststr)) {
        $xml = simplexml_load_string($poststr, "SimpleXMLElement", LIBXML_NOCDATA);
        switch (trim($xml->MsgType)) {
            case "event":
                echo make_text_response($xml->ToUserName, $xml->FromUserName, "unknown event");
                break;
            case "text":
                echo get_tuling_chat_response($xml->ToUserName, $xml->FromUserName, $xml->Content);
                break;
            case "voice":
            case "video":
            case "location":
            case "link":
            default:
                echo make_text_response($xml->ToUserName, $xml->FromUserName, "发文字,别的不懂!");
                break;
        }
    }
}
Exemple #3
0
function get_tuling_chat_response($from, $to, $text)
{
    $url = "http://www.tuling123.com/openapi/api";
    $key = "d812d695a5e0df258df952698faca6cc";
    // return file_get_contents("$url?key=$key&info=" . urlencode($text));
    $json = json_decode(file_get_contents("{$url}?key={$key}&info=" . urlencode($text)), true);
    if ($json["code"] < 40000) {
        return make_text_response($from, $to, "图灵机器人脑残中");
    }
    $item = "<item><Title><![CDATA[%s]]></Title>" . "<Description><![CDATA[%s]]></Description>" . "<PicUrl><![CDATA[%s]]></PicUrl>" . "<Url><![CDATA[%s]]></Url></item>";
    switch ($json["code"]) {
        case "200000":
            return make_text_response($from, $to, $json["text"] . ",<a href=\"" . $json["url"] . "\">点击进入</a>");
            break;
        case "301000":
            foreach ($json["list"] as $info) {
                // $articles []= array(
                //         "Title"       => $info["name"],
                //         "Description" => $info["author"],
                //         "PicUrl"      => $info["icon"],
                //         "Url"         => $info["detailurl"]
                // );
                $items[] = sprintf($item, $info["name"], $info["author"], $info["icon"], $info["detailurl"]);
            }
            break;
        case "302000":
            foreach ($json["list"] as $info) {
                // $articles []= array(
                //         "Title"       => $info["article"],
                //         "Description" => $info["source"],
                //         "PicUrl"      => $info["icon"],
                //         "Url"         => $info["detailurl"]
                // );
                $items[] = sprintf($item, $info["article"], $info["source"], $info["icon"], $info["detailurl"]);
            }
            break;
        case "304000":
            foreach ($json["list"] as $info) {
                // $articles []= array(
                //         "Title"       => $info["name"],
                //         "Description" => $info["count"],
                //         "PicUrl"      => $info["icon"],
                //         "Url"         => $info["detailurl"]
                // );
                $items[] = sprintf($item, $info["name"], $info["count"], $info["icon"], $info["detailurl"]);
            }
            break;
        case "305000":
            foreach ($json["list"] as $info) {
                // $articles []= array(
                //         "Title"       => $info["start"] . "--" . $info["terminal"],
                //         "Description" => $info["starttime"] . "--" . $info["endtime"],
                //         "PicUrl"      => $info["icon"],
                //         "Url"         => $info["detailurl"]
                // );
                $items[] = sprintf($item, $info["start"] . "--" . $info["terminal"], $info["starttime"] . "--" . $info["endtime"], $info["icon"], $info["detailurl"]);
            }
            break;
        case "306000":
            foreach ($json["list"] as $info) {
                // $articles []= array(
                //         "Title"       => $info["flight"] . "--" . $info["route"],
                //         "Description" => $info["starttime"] . "--" . $info["endtime"],
                //         "PicUrl"      => $info["icon"],
                //         "Url"         => $info["detailurl"]
                // );
                $items[] = sprintf($item, $info["flight"] . "--" . $info["route"], $info["starttime"] . "--" . $info["endtime"], $info["icon"], $info["detailurl"]);
            }
            break;
        case "307000":
        case "308000":
            foreach ($json["list"] as $info) {
                // $articles []= array(
                //         "Title"       => $info["name"],
                //         "Description" => $info["info"],
                //         "PicUrl"      => $info["icon"],
                //         "Url"         => $info["detailurl"]
                // );
                $items[] = sprintf($item, $info["name"], $info["info"], $info["icon"], $info["detailurl"]);
            }
            break;
        case "309000":
            foreach ($json["list"] as $info) {
                // $articles []= array(
                //         "Title"       => $info["name"],
                //         "Description" => "价格: " . $info["price"] . "满意度: " . $info["satisfaction"],
                //         "PicUrl"      => $info["icon"],
                //         "Url"         => $info["detailurl"]
                // );
                $items[] = sprintf($item, $info["name"], "价格: " . $info["price"] . "满意度: " . $info["satisfaction"], $info["icon"], $info["detailurl"]);
            }
            break;
        case "310000":
            foreach ($json["list"] as $info) {
                // $articles []= array(
                //         "Title"       => $info["number"],
                //         "Description" => $info["info"],
                //         "PicUrl"      => $info["icon"],
                //         "Url"         => $info["detailurl"]
                // );
                $items[] = sprintf($item, $info["number"], $info["info"], $info["icon"], $info["detailurl"]);
            }
            break;
        case "311000":
        case "312000":
            foreach ($json["list"] as $info) {
                // $articles []= array(
                //         "Title"       => $info["name"],
                //         "Description" => "价格: " . $info["price"],
                //         "PicUrl"      => $info["icon"],
                //         "Url"         => $info["detailurl"]
                // );
                $items[] = sprintf($item, $info["name"], "价格: " . $info["price"], $info["icon"], $info["detailurl"]);
            }
            break;
        default:
            return make_text_response($from, $to, $json["text"]);
            break;
    }
    return make_news_url($from, $to, $items);
}