⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 video.php

📁 论坛代码网增加免费空间业务
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php

/*
	[Discuz!] (C)2001-2007 Comsenz Inc.
	This is NOT a freeware, use is subject to license terms

	$Id: video.php 13054 2008-03-24 10:02:34Z tiger $
*/

error_reporting(0);
define('DISCUZ_ROOT', substr(dirname(__FILE__), 0, -3));
require_once DISCUZ_ROOT.'./forumdata/cache/cache_settings.php';

$appid = 'c4ca4238a0b923820dcc509a6f75849b';
$siteid = $_DCACHE['settings']['vsiteid'];
$sitekey = $_DCACHE['settings']['vkey'];

define('VIDEO_DEBUG', 0);
define('SERVER_HOST', 'api.v.insenz.com');
define('SERVER_URL', 'http://' . SERVER_HOST . '/video_api.php');
define('PIC_SERVER_HOST', 'p.v.insenz.com');

if($_GET['action'] == 'createcode') {
	echo VideoClient_Util::createCode();
}

class VideoClient_Result {
	var $status;
	var $errMessage;
	var $errCode;
	var $_result;
	function VideoClient_Result($result) {
		$this->status = $result['status'];
		$this->errMessage = $result['errMessage'];
		$this->errCode = $result['errCode'];
		$this->_result = $result;

		if($result['resultData']) {
			foreach($result['resultData'] as $value) {
				$this->_result['results'][] = new VideoClient_Result($value);
			}
		}
	}

	function isError() {
		return VideoClient::isError($this->_result);
	}

	function getCode() {
		return VideoClient::getCode($this->_result);
	}

	function getMessage() {
		return VideoClient::getMessage($this->_result);
	}

	function get($field = false) {
		return $field ? $this->_result[$field] : $this->_result;
	}
}

class VideoClient {
	var $appId;
	var $version = '0.1';
	var $key = 'ComsenzVideoService';
	var $apiServerUrl = SERVER_URL;

	function VideoClient($appId) {
		$this->appId = $appId;
	}

	function getUrl() {
		return $this->apiServerUrl;
	}

	function setUrl($url) {
		$this->url = $url;
	}

	function _sign($args) {
		return md5($args);
	}

	function _encrypt($str) {
		return $this->authcode($str, $this->key);
	}

	function _decrypt($str) {
		return $this->authcode($str, $this->key, 'DECODE');
	}

	function authcode($string, $key, $operation = 'ENCODE') {
		$key_length = strlen($key);
		if($key_length == 0) {
			return false;
		}
		$string = $operation == 'DECODE' ? base64_decode($string) : substr(md5($string.$key), 0, 8).$string;
		$string_length = strlen($string);

		$rndkey = $box = array();
		$result = '';

		for($i = 0; $i <= 255; $i++) {
			$rndkey[$i] = ord($key[$i % $key_length]);
			$box[$i] = $i;
		}

		for($j = $i = 0; $i < 256; $i++) {
			$j = ($j + $box[$i] + $rndkey[$i]) % 256;
			$tmp = $box[$i];
			$box[$i] = $box[$j];
			$box[$j] = $tmp;
		}

		for($a = $j = $i = 0; $i < $string_length; $i++) {
			$a = ($a + 1) % 256;
			$j = ($j + $box[$a]) % 256;
			$tmp = $box[$a];
			$box[$a] = $box[$j];
			$box[$j] = $tmp;
			$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
		}

		if($operation == 'DECODE') {
			if(substr($result, 0, 8) == substr(md5(substr($result, 8).$key), 0, 8)) {
				return substr($result, 8);
			} else {
				return '';
			}
		} else {
			return str_replace('=', '', base64_encode($result));
		}
	}

	function _postCurl($url, $post_data) {
		$cookie = '';
		if($_COOKIE['insenz_session_id']) {
			$cookies .= (session_name()) . "=" . urlencode($_COOKIE['insenz_session_id']) . ";";
		}
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
   		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_COOKIE, $cookies);
		$result = curl_exec($ch);
		$errorMsg = curl_error($ch);
		if(!empty($errorMsg)) {
			return new VideoClient_Result(array('status' => -1 , 'errMessage' => $errorMsg ));
		}
		if(is_resource($ch)) {
			curl_close($ch);
		}
		return $result;
	}

	function _postSock($url, $post_data) {
		if(!function_exists('fsockopen')) {
			return new VideoClient_Result(array('status' => -1));
		}
		$urlInfo = array();
		$urlInfo = parse_url($url);
		$port = (0 == strcasecmp($urlInfo['scheme'], 'https')) ? 443 : 80;
		$httpHeader = "POST " . $urlInfo['path'] . '?' . $urlInfo['query'] . ' ' .  strtoupper($urlInfo['scheme']) . "/1.0\r\n";
		$httpHeader .= "Host: " . $urlInfo['host'] . " \r\n";
		$httpHeader .= "Connection: Close\r\n";
		$httpHeader .= "Content-type: application/x-www-form-urlencoded\r\n";
		$httpHeader .= "Content-length: " . strlen($post_data) . "\r\n";
		$httpHeader .= "Referer: " . $_SERVER['HTTP_HOST'] . $_SERVER["SCRIPT_NAME"] . "\r\n";
		$cookie = '';
		if($_COOKIE['insenz_session_id']) {
			$cookies .= (session_name()) . "=" . urlencode($_COOKIE['insenz_session_id']) . ";";
		}
		$httpHeader .= "Cookie: " . $cookies . "\r\n";
		$httpHeader .= "\r\n";
		$httpHeader .= $post_data;
		$httpHeader .= "\r\n\r\n";

		$fp = @fsockopen($urlInfo['host'], $port);
		if($fp) {
			if(fwrite($fp, $httpHeader)) {
				$resData = '';
				while(!feof($fp)) {
					$resData .= fread($fp, 8192);
				}
				fclose($fp);
				$resContent =  substr(strstr($resData, "\r\n\r\n"), 4);
				return $resContent;
			} else {
				return new VideoClient_Result(array('status' => -1));
			}
		} else {
			return new VideoClient_Result(array('status' => -1));
		}
	}

	function _doCall($mod, $params) {

		$tmpArgs = array();
		$url = '';
		if($this->appId) {
			$params['appId'] = $this->appId;
		}
		$params['method'] = $mod;
		$params['version'] = $this->version;
		foreach($params as $paramName => $paramValue) {
			$tmpArgs[] = urlencode($paramName) . '=' . urlencode($paramValue);
		}
		$args = join('&', $tmpArgs);
		$args .= '&sign=' . $this->_sign($args);
		$tmpArgs = $args;
		$url = $this->apiServerUrl . '?siteId=' . (($params['siteId']) ? $params['siteId'] : '0');
		$resultString = '';
		$result = array();
		$args = urlencode($this->_encrypt(urlencode($args), $this->key));

		if(function_exists('curl_init')) {
			$resultString = $this->_postCurl($url, $args);
		} else {
			$resultString = $this->_postSock($url, $args);
		}

		if(is_object($resultString)) {
			return $resultString;
		}
		if(empty($resultString)) {
			return new VideoClient_Result(array('status' => -1));
		}
		$tmp = $resultString;
		$decodeString = $this->_decrypt($resultString, $this->key);
		if($decodeString) {
			$resultString = $decodeString;
		}
		$resultString = urldecode($resultString);

		parse_str($resultString, $result);
		if(!is_array($result)) {
			return new VideoClient_Result(array('status' => -1));
		}
		return new VideoClient_Result($result);
	}

	function isError($result) {
		return $result['status'] != 0 || $result['status'] === NULL;
	}

	function getCode($result) {
		return $result['errCode'];
	}

	function getMessage($result) {
		return $result['errMessage'];
	}
}

class VideoClient_AccountService extends VideoClient {
	var $handle;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -