/** * 根据当前版本+release获取升级信息(patch包地址) ,hash值 * 获取升级文件列表 */ public function checkUpgrade() { $url = PwApplicationHelper::acloudUrl(array('a' => 'forward', 'do' => 'getUpdateInfo', 'pwversion' => $this->local)); $r = PwApplicationHelper::requestAcloudData($url); $r = WindConvert::convert($r, Wekit::V('charset'), 'utf8'); return is_array($r) ? $r['code'] === '0' ? $r['info'] : $r['msg'] : '无法连接云平台!'; }
/** * 发送短信 * * @return bool */ public function sendMobileMessage($mobile, $content) { $content = Pw::convert($content, 'UTF-8'); $url = PwApplicationHelper::acloudUrl(array('a' => 'forward', 'do' => 'sendSms', 'mobile' => $mobile, 'content' => $content)); $info = PwApplicationHelper::requestAcloudData($url); if (!is_array($info)) { return new PwError('APPCENTER:center.connect.fail'); } if ($info['code'] !== '0') { return new PwError($info['msg']); } return true; }
/** * 获取线上补丁列表 * * @return Ambigous <multitype:, boolean, string> */ public function getOnlinePatchList() { $url = PwApplicationHelper::acloudUrl(array('a' => 'forward', 'do' => 'getSecurityPatch', 'pwversion' => NEXT_VERSION)); $r = PwApplicationHelper::requestAcloudData($url); if (!is_array($r)) { return '无法连接云平台!'; } if ($r['code'] !== '0') { return $r['msg']; } /* $r['info'] = array( array('id' => '9000001', 'name' => '更新', 'desc' => 'blabla', 'time' => '1323333', 'rule' => array( array('filename' => 'src/wekit.php', 'search' => base64_encode('Jianmin Chen'), 'replace' => base64_encode('Shi Long'), 'count' => '1', 'nums' => array('1')))) ); */ $temp = array(); foreach ($r['info'] as $v) { $v['id'] = $v['name']; $temp[$v['id']] = $v; } return $temp; }
/** * 升级 */ public function upgradeAction() { $id = $this->getInput('app_id'); $url = PwApplicationHelper::acloudUrl(array('a' => 'forward', 'do' => 'upgradeApplication', 'appid' => $id)); $info = PwApplicationHelper::requestAcloudData($url); if ($info['code'] !== '0') { $this->showError(array('APPCENTER:update.fail', array($info['msg']))); } else { $this->showMessage('success'); } }
/** * 获取线上应用基本信息,包括应用中心提交应用填写的描述、logo等 * * @return PwError|array */ public function getOnlineInfo() { $url = PwApplicationHelper::acloudUrl(array('a' => 'forward', 'do' => 'getAppById', 'appid' => $this->_appId)); $data = PwApplicationHelper::requestAcloudData($url); if ($data['code'] !== '0') { return new PwError('APPCENTER:install.fail', array('{{error}}' => $data['msg'])); } $manifest = array('application' => array('name' => $data['info']['app_name'], 'version' => $data['info']['version'], 'pw-version' => $data['info']['bbs_version'], 'description' => trim($data['info']['description'], '\'"'), 'logo' => $data['info']['icon'], 'author-name' => trim($data['info']['app_author'], '\'"'), 'website' => $data['info']['author_url'], 'charset' => ACloudSysCoreCommon::getGlobal('g_charset'))); return $manifest; }
/** * 根据现有目录结构调整升级包目录 * * @param array $fileList */ public function sortDirectory($fileList) { $this->_log('start to sort the directory'); $sourceDir = $this->tmpPath . DIRECTORY_SEPARATOR . $this->target; $directoryFile = $sourceDir . DIRECTORY_SEPARATOR . 'conf/directory.php'; $directory = @(include $directoryFile); if (!is_array($directory)) { return new PwError('APPCENTER:upgrade.directory.fail'); } $this->_log('the remote directory is:' . var_export($directory, true)); $root = Wind::getRealDir('ROOT:'); $sort = array('TPL', 'THEMES', 'ACLOUD', 'WINDID', 'REP', 'SRV', 'LIB', 'HOOK', 'EXT', 'APPS', 'CONF', 'DATA', 'SRC', 'PUBLIC'); $strtr = array(); $localDirectory = @(include Wind::getRealPath('CONF:directory.php', true)); foreach ($sort as $v) { if ($directory[$v] == $localDirectory[$v]) { continue; } $search = PwSystemHelper::relative(WEKIT_PATH . str_replace('/', DIRECTORY_SEPARATOR, $directory[$v])); $strtr[rtrim($search, '/\\')] = rtrim(Wind::getRootPath($v), '/\\'); } $this->_log('way of moving directory' . var_export($strtr, true)); if (!($sourceMd5 = WindFile::read($sourceDir . DIRECTORY_SEPARATOR . 'conf/md5sum'))) { return new PwError('APPCENTER:upgrade.target.hash.fail'); } $sourceMd5 = PwSystemHelper::resolveMd5($sourceMd5); // md5sum $data = ''; foreach ($sourceMd5 as $v => $md5) { $v = trim($v, '/'); $v = str_replace('/', DIRECTORY_SEPARATOR, $v); $_v = ROOT_PATH . $v; $file = $v; foreach ($strtr as $search => $replace) { if (0 === strpos($_v, $search)) { $file = str_replace(ROOT_PATH, '', $replace . substr($_v, strlen($search))); $file = str_replace('//', '/', $file); break; } } $data .= PwSystemHelper::md5content($md5, $file); } WindFile::write($sourceDir . DIRECTORY_SEPARATOR . 'conf/md5sum', $data); $moveList = $newFileList = array(); $url = PwApplicationHelper::acloudUrl(array('a' => 'forward', 'do' => 'getVersionHash', 'pwversion' => $this->local)); /* 从线上获取当前版本的所有文件md5 */ /* $result = PwApplicationHelper::requestAcloudData($url); if ($result['code'] !== '0' || !$result['info']) return new PwError(array('APPCENTER:upgrade.version.hash.fail', array($result['msg']))); */ if (!($tmp = WindFile::read(CONF_PATH . 'md5sum'))) { return new PwError('APPCENTER:upgrade.hash.fail'); } $md5List = PwSystemHelper::resolveMd5($tmp); $this->_log('obtain the md5 list of current version'); foreach ($fileList as $v) { $v = trim($v, '/'); $v = str_replace('/', DIRECTORY_SEPARATOR, $v); $_v = $root . $v; $file = $v; foreach ($strtr as $search => $replace) { if (0 === strpos($_v, $search)) { $file = str_replace($root, '', $replace . substr($_v, strlen($search))); $file = str_replace('//', '/', $file); $moveList[$v] = $file; break; } } $newFileList[$file] = $md5List[str_replace(DIRECTORY_SEPARATOR, '/', $file)]; } $this->_log('files need to move ' . var_export($moveList, true)); $relativePath_1 = PwSystemHelper::resolveRelativePath(PUBLIC_PATH, Wind::getRealPath('SRC:wekit')); $relativePath_2 = PwSystemHelper::resolveRelativePath(PUBLIC_PATH . 'aCloud', Wind::getRealPath('SRC:wekit')); foreach ($moveList as $old => $new) { WindFolder::mkRecur(dirname($sourceDir . DIRECTORY_SEPARATOR . $new)); copy($sourceDir . DIRECTORY_SEPARATOR . $old, $sourceDir . DIRECTORY_SEPARATOR . $new); WindFile::del($sourceDir . DIRECTORY_SEPARATOR . $old); if ('.php' === substr($old, -4) && !strncasecmp($old, 'www' . DIRECTORY_SEPARATOR, 4)) { $content = WindFile::read($sourceDir . DIRECTORY_SEPARATOR . $new); if (strpos($content, '../../src/wekit.php')) { $content = str_replace('../../src/wekit.php', $relativePath_2, $content); } else { $content = str_replace('../src/wekit.php', $relativePath_1, $content); } // $content = str_replace('../src/wekit.php', // Wind::getRealPath('SRC:wekit'), $content); WindFile::write($sourceDir . DIRECTORY_SEPARATOR . $new, $content); } } // 目录文件 if ($directory != $localDirectory) { $directory = array_merge($directory, $localDirectory); $temp = "<?php\r\n defined('WEKIT_VERSION') or exit(403);\r\n return "; $temp .= WindString::varToString($directory) . ";\r\n?>"; WindFile::write($directoryFile, $temp); } Wekit::cache()->set('system_upgrade_replace', 1); return $newFileList; }
/** * 卸载 */ public function uninstallAction() { $styleid = $this->getInput('styleid'); /* @var $uninstall PwUninstallApplication */ if ($styleid[0] !== 'L') { $url = PwApplicationHelper::acloudUrl(array('a' => 'forward', 'do' => 'uninstallApp', 'appid' => $styleid)); $info = PwApplicationHelper::requestAcloudData($url); if ($info['code'] !== '0') { $this->showError($info['msg']); } else { $this->showMessage('success'); } } else { $uninstall = Wekit::load('APPCENTER:service.srv.PwUninstallApplication'); $r = $uninstall->uninstall($styleid); if ($r === true) { $this->showMessage('success'); } $this->showError($r->getError()); } }
public function loginAlipayAction() { $alipay = $this->getInput('alipay'); Wind::import('APPCENTER:service.srv.helper.PwApplicationHelper'); $url = PwApplicationHelper::acloudUrl(array('a' => 'forward', 'do' => 'alipayAuth', 'callback' => WindUrlHelper::createUrl('app/verify/index/verifyAlipay', array('uid' => $this->loginUser->uid)), 'account' => $alipay)); $info = PwApplicationHelper::requestAcloudData($url); if ($info['code'] !== '0') { $this->showError($info['msg']); } $this->setOutput(array('referer' => $info['info']), 'data'); $this->showMessage('success'); }