<?php
header("Content-Type: text/html; charset=UTF-8");

require("common.php");

$content = isset($_POST['content']) ? $_POST['content'] : ''; 

$ivisitorid_start = strpos($content, "%visitorid%:");
$ito_start = strpos($content, "%to%:");
$ishowname_start = strpos($content, "%showname%:");
$imessage_start = strpos($content, "%message%:");
$imsgtime_start = strpos($content, "%msgtime%:");

$ivisitorid_end = $ivisitorid_start + strlen("%visitorid%:");
$ito_end = $ito_start + strlen("%to%:");
$ishowname_end = $ishowname_start + strlen("%showname%:");
$imessage_end = $imessage_start + strlen("%message%:");
$imsgtime_end = $imsgtime_start + strlen("%msgtime%:");

$visitorid = substr($content, $ivisitorid_end, $ito_start - $ivisitorid_end);
$to = substr($content, $ito_end, $ishowname_start - $ito_end);
$showname = substr($content, $ishowname_end, $imessage_start - $ishowname_end);
$message = substr($content, $imessage_end, $imsgtime_start - $imessage_end);
$msgtime = substr($content, $imsgtime_end, strlen($content) - $imsgtime_end);

$methodname = 'WebVisitor.MessageFromWebVisitor';
$requestinfo = '<?xml version="1.0" encoding="utf-8"?><request>' . 
	'<visitorid>' . $visitorid . '</visitorid>' . 
	'<to>' . $to . '</to>' . 
	'<showname>' . $showname . '</showname>' . 
	'<message>' . $message . '</message>' . 
	'</request> ';
$responseinfo = '';
$responsexml = null;
$errorcode = ERRORCODE_UNKNOWN;

$cmd = new COM("OpenCom.Command");
$methodname = iconv('UTF-8', 'GBK//IGNORE', $methodname);
$requestinfo = iconv('UTF-8', 'GBK//IGNORE', $requestinfo);
if ($cmd->Execute($methodname, $requestinfo, $responseinfo, 500)) {
	$responseinfo = iconv('GBK', 'UTF-8//IGNORE', $responseinfo);
	$responsexml = simplexml_load_string($responseinfo);
	$errorcode = $responsexml->errorcode;
}
$cmd = null;

switch($errorcode) {
	case ERRORCODE_OK: 
		echo "True";
		break;
	default:
		echo "False";
}//switch
?>