protected function output($message = '') { if (is_numeric($message)) { echo $message; exit; } else { header('Content-type: application/json; charset=' . Windid::client()->clientCharser); echo WindJson::encode($message, Windid::client()->clientCharser); exit; } }
public function doAvatar($uid, $file = '') { $client = Windid::client(); $time = time() + $client->timecv * 60; $query = array('m' => 'api', 'c' => 'avatar', 'a' => 'doavatar', 'windidkey' => WindidUtility::appKey($client->clientId, $time, $client->clientKey), 'clientid' => $client->clientId, 'time' => $time, 'uid' => $uid); $url = $client->serverUrl . '/windid/index.php?' . http_build_query($query); $result = WindidUtility::uploadRequest($url, $file); if ($result === false) { return WindidError::SERVER_ERROR; } return WindJson::decode($result, true, $client->clientCharser); }
public static function open($script, $getData = array(), $postData = array(), $method = 'post', $protocol = 'http') { echo "here"; $client = Windid::client(); $time = time() + $client->timecv * 60; list($c, $a) = explode('/', $script); $query = array('m' => 'api', 'c' => $c, 'a' => $a, 'windidkey' => WindidUtility::appKey($client->clientId, $time, $client->clientKey), 'clientid' => $client->clientId, 'time' => $time); $url = $client->serverUrl . '/windid/index.php?' . http_build_query($query) . '&' . http_build_query($getData); $result = WindidUtility::buildRequest($url, $postData); if ($result === false) { return WindidError::SERVER_ERROR; } return WindJson::decode($result, true, $client->clientCharser); }
/** * 从云平台上获取 * */ public function apiRequest($method, $params = array()) { $params['method'] = $method; $params['url'] = 'http://' . $_SERVER['HTTP_HOST']; //$params['url'] = 'http://www.wekit.net'; $params['app_id'] = $this->appid; $params['timestamp'] = Pw::getTime(); $params['sign'] = $this->createSign($params); require_once Wind::getRealPath("ACLOUD:system.core.ACloudSysCoreHttpclient"); $result = ACloudSysCoreHttpclient::post($this->_getCloudApi(), $this->createHttpQuery($params)); $result = WindJson::decode($result); if (!is_array($result) || !isset($result['code'])) { return array(false, ''); } if ($result['code'] != 0) { return array(false, $result['msg'] . ' ' . $result['code']); } return array(true, $result['result']); }
/** * 将json格式数据解密 * * @param string $value 待解密的数据 * @param string $charset 解密后字符串编码 * @return mixed 解密后的数据 */ public static function jsonDecode($value) { return WindJson::decode($value, true, Wekit::V('charset')); }
protected function output($message = '') { header('Content-type: application/json'); echo WindJson::encode($message, Windid::client()->clientCharser); exit; }
protected function buildData($id, $type) { $url = 'http://api.pengyou.com/json.php?cb=__i_5&mod=school&act=selector&schooltype=' . $type . '&district=' . $id; $content = file_get_contents($url); preg_match('/{(.*)}/is', $content, $matches); $content = WindJson::decode($matches[0]); $result = $content['result']; preg_match_all('/javascript:choose_school\\((\\d+),\'(.*)\'\\);/iUs', $result, $matches); $addDms = array(); foreach ($matches[1] as $k => $v) { $dm = new WindidSchoolDm(); $dm->setName($matches[2][$k])->setTypeid($this->getSchoolType($type))->setAreaid($id)->setFirstChar($this->_getService()->getFirstChar($matches[2][$k])); $addDms[] = $dm; } return $this->_getSchoolDs()->batchAddSchool($addDms); }
/** * 输出json到页面 * 添加转义 * * @param mixed $source * @param string $charset * @return string */ public static function escapeEncodeJson($source, $charset = 'utf-8') { return WindJson::encode(is_string($source) ? self::escapeHTML($source) : self::escapeArrayHTML($source), $charset); }
/** * 请求一个Aclude数据信息 * * @param array $args * @param string $tmpdir */ public static function requestAcloudData($url, $tmpdir = '') { Wind::import('WIND:http.transfer.WindHttpCurl'); $http = new WindHttpCurl($url); if ($tmpdir !== '') { WindFolder::mkRecur($tmpdir); $_tmp = $tmpdir . '/tmp.' . Pw::getTime(); $fp = fopen($_tmp, "w"); $opt = array(CURLOPT_FILE => $fp, CURLOPT_HEADER => 0, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false); $http->send('GET', $opt); if ($error = $http->getError()) { return array(false, $error); } $info = $http->getInfo(); $realname = basename($info["url"]); $http->close(); fclose($fp); chmod($_tmp, 0766); if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { copy($_tmp, $tmpdir . DIRECTORY_SEPARATOR . $realname); } else { rename($_tmp, $tmpdir . DIRECTORY_SEPARATOR . $realname); } $result = array(true, $tmpdir . '/' . $realname); } else { $result = $http->send('GET', array(CURLOPT_FOLLOWLOCATION => true)); $result && ($result = WindJson::decode($result)); } return $result; }
/** * 将json格式数据解密 * * @param string $value 待解密的数据 * @param string $charset 解密后字符串编码 * @return mixed 解密后的数据 */ public static function jsonDecode($value) { return WindJson::decode($value, true, Wekit::app()->charset); }
/** * 将json格式数据解密 * * @param string $value 待解密的数据 * @param string $charset 解密后字符串编码 * @return mixed 解密后的数据 */ public static function jsonDecode($value, $charset = self::UTF8) { Wind::import('Wind:utility.WindJson'); return WindJson::decode($value, true, $charset); }