cloud.mod.php 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. define('CLOUD_GATEWAY_URL', 'http://www.we7.cc/api/api.php');
  8. define('CLOUD_GATEWAY_URL_NORMAL', 'http://www.we7.cc/api/api.php');
  9. function cloud_client_define() {
  10. return array(
  11. '/framework/function/communication.func.php',
  12. '/framework/model/cloud.mod.php',
  13. '/web/source/cloud/upgrade.ctrl.php',
  14. '/web/source/cloud/process.ctrl.php',
  15. '/web/source/cloud/dock.ctrl.php',
  16. '/web/themes/default/cloud/upgrade.html',
  17. '/web/themes/default/cloud/process.html'
  18. );
  19. }
  20. function _cloud_build_params() {
  21. global $_W;
  22. $pars = array();
  23. $pars['host'] = $_SERVER['HTTP_HOST'];
  24. $pars['family'] = IMS_FAMILY;
  25. $pars['version'] = IMS_VERSION;
  26. $pars['release'] = IMS_RELEASE_DATE;
  27. $pars['key'] = $_W['setting']['site']['key'];
  28. $pars['token'] = $_W['setting']['site']['token'];
  29. $pars['password'] = md5($_W['setting']['site']['key'] . $_W['setting']['site']['token']);
  30. $clients = cloud_client_define();
  31. $string = '';
  32. foreach ($clients as $cli) {
  33. $string.= md5_file(IA_ROOT . $cli);
  34. }
  35. $pars['client'] = md5($string);
  36. return $pars;
  37. }
  38. function _cloud_shipping_parse($dat, $file) {
  39. if (is_error($dat)) {
  40. return error(-1, '网络传输错误, 请检查您的cURL是否可用, 或者服务器网络是否正常. ' . $dat['message']);
  41. }
  42. $tmp = unserialize($dat['content']);
  43. if (is_array($tmp) && is_error($tmp)) {
  44. if ($tmp['errno'] == '-2') {
  45. $data = file_get_contents(IA_ROOT . '/framework/version.inc.php');
  46. file_put_contents(IA_ROOT . '/framework/version.inc.php', str_replace("'x'", "'v'", $data));
  47. }
  48. return $tmp;
  49. }
  50. if ($dat['content'] == 'patching') {
  51. return error(-1, '补丁程序正在更新中,请稍后再试!');
  52. }
  53. if ($dat['content'] == 'frequent') {
  54. return error(-1, '更新操作太频繁,请稍后再试!');
  55. }
  56. $data = @file_get_contents($file);
  57. @unlink($file);
  58. $ret = @iunserializer($data);
  59. $ret = iunserializer($ret['data']);
  60. if (is_array($ret) && is_error($ret)) {
  61. if ($ret['errno'] == '-2') {
  62. $data = file_get_contents(IA_ROOT . '/framework/version.inc.php');
  63. file_put_contents(IA_ROOT . '/framework/version.inc.php', str_replace("'x'", "'v'", $data));
  64. }
  65. }
  66. if (!is_error($ret) && is_array($ret) && !empty($ret)) {
  67. if ($ret['state'] == 'fatal') {
  68. return error($ret['errorno'], '发生错误: ' . $ret['message']);
  69. }
  70. return $ret;
  71. } else {
  72. return error($ret['errno'], "发生错误: {$ret['message']}");
  73. }
  74. }
  75. function cloud_request($url, $post = '', $extra = array() , $timeout = 60) {
  76. global $_W;
  77. load()->func('communication');
  78. if (!empty($_W['setting']['cloudip']['ip']) && empty($extra['ip'])) {
  79. //$extra['ip'] = $_W['setting']['cloudip']['ip'];
  80. //$extra['ip'] = "www.we7.cc";
  81. }
  82. return ihttp_request($url, $post, $extra, $timeout);
  83. }
  84. function cloud_prepare() {
  85. global $_W;
  86. setting_load();
  87. if (empty($_W['setting']['site']['key']) || empty($_W['setting']['site']['token'])) {
  88. return error('-1', "您的站点只有在云服务平台成功注册后,才能使用云服务的相应功能。");
  89. }
  90. return true;
  91. }
  92. function cloud_build() {
  93. $pars = _cloud_build_params();
  94. $pars['method'] = 'application.build2';
  95. $pars['extra'] = cloud_extra_account();
  96. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars);
  97. $file = IA_ROOT . '/data/application.build';
  98. $ret = _cloud_shipping_parse($dat, $file);
  99. if (!is_error($ret)) {
  100. if ($ret['state'] == 'warning') {
  101. $ret['files'] = cloud_client_define();
  102. unset($ret['schemas']);
  103. unset($ret['scripts']);
  104. } else {
  105. $files = array();
  106. if (!empty($ret['files'])) {
  107. foreach ($ret['files'] as $file) {
  108. $entry = IA_ROOT . $file['path'];
  109. if (!is_file($entry) || md5_file($entry) != $file['checksum']) {
  110. $files[] = $file['path'];
  111. }
  112. }
  113. }
  114. $ret['files'] = $files;
  115. if (!empty($ret['files'])) {
  116. cloud_bakup_files($ret['files']);
  117. }
  118. $schemas = array();
  119. if (!empty($ret['schemas'])) {
  120. load()->func('db');
  121. foreach ($ret['schemas'] as $remote) {
  122. $name = substr($remote['tablename'], 4);
  123. $local = db_table_schema(pdo() , $name);
  124. unset($remote['increment']);
  125. unset($local['increment']);
  126. if (empty($local)) {
  127. $schemas[] = $remote;
  128. } else {
  129. $sqls = db_table_fix_sql($local, $remote);
  130. if (!empty($sqls)) {
  131. $schemas[] = $remote;
  132. }
  133. }
  134. }
  135. }
  136. $ret['schemas'] = $schemas;
  137. }
  138. if ($ret['family'] == 'x' && IMS_FAMILY == 'v') {
  139. load()->model('setting');
  140. setting_upgrade_version('x', IMS_VERSION, IMS_RELEASE_DATE);
  141. itoast('您已经购买了商业授权版本, 系统将转换为商业版, 并重新运行自动更新程序.', 'refresh');
  142. }
  143. $ret['upgrade'] = false;
  144. if (!empty($ret['files']) || !empty($ret['schemas']) || !empty($ret['scripts'])) {
  145. $ret['upgrade'] = true;
  146. }
  147. $upgrade = array();
  148. $upgrade['upgrade'] = $ret['upgrade'];
  149. $upgrade['data'] = $ret;
  150. $upgrade['lastupdate'] = TIMESTAMP;
  151. cache_write('upgrade', $upgrade);
  152. cache_write('cloud:transtoken', authcode($ret['token'], 'ENCODE'));
  153. }
  154. return $ret;
  155. }
  156. function cloud_schema() {
  157. $pars = _cloud_build_params();
  158. $pars['method'] = 'application.schema';
  159. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars);
  160. $file = IA_ROOT . '/data/application.schema';
  161. $ret = _cloud_shipping_parse($dat, $file);
  162. if (!is_error($ret)) {
  163. $schemas = array();
  164. if (!empty($ret['schemas'])) {
  165. load()->func('db');
  166. foreach ($ret['schemas'] as $remote) {
  167. $name = substr($remote['tablename'], 4);
  168. $local = db_table_schema(pdo() , $name);
  169. unset($remote['increment']);
  170. unset($local['increment']);
  171. if (empty($local)) {
  172. $schemas[] = $remote;
  173. } else {
  174. $diffs = db_schema_compare($local, $remote);
  175. if (!empty($diffs)) {
  176. $schemas[] = $remote;
  177. }
  178. }
  179. }
  180. }
  181. $ret['schemas'] = $schemas;
  182. }
  183. return $ret;
  184. }
  185. function cloud_download($path, $type = '') {
  186. $pars = _cloud_build_params();
  187. $pars['method'] = 'application.shipping';
  188. $pars['path'] = $path;
  189. $pars['type'] = $type;
  190. $pars['gz'] = function_exists('gzcompress') && function_exists('gzuncompress') ? 'true' : 'false';
  191. $pars['download'] = 'true';
  192. $headers = array(
  193. 'content-type' => 'application/x-www-form-urlencoded'
  194. );
  195. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars, $headers, 300);
  196. if (is_error($dat)) {
  197. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  198. }
  199. if ($dat['content'] == 'success') {
  200. return true;
  201. }
  202. $ret = @json_decode($dat['content'], true);
  203. if (is_error($ret)) {
  204. return $ret;
  205. } else {
  206. $post = $dat['content'];
  207. $data = base64_decode($post);
  208. if (base64_encode($data) !== $post) {
  209. $data = $post;
  210. }
  211. $ret = iunserializer($data);
  212. $gz = function_exists('gzcompress') && function_exists('gzuncompress');
  213. $file = base64_decode($ret['file']);
  214. if ($gz) {
  215. $file = gzuncompress($file);
  216. }
  217. $_W['setting']['site']['token'] = authcode(cache_load('cloud:transtoken') , 'DECODE');
  218. $string = (md5($file) . $ret['path'] . $_W['setting']['site']['token']);
  219. if (!empty($_W['setting']['site']['token']) && md5($string) === $ret['sign']) {
  220. $path = IA_ROOT . $ret['path'];
  221. load()->func('file');
  222. @mkdirs(dirname($path));
  223. if (file_put_contents($path, $file)) {
  224. return true;
  225. } else {
  226. return error(-1, '写入失败');
  227. }
  228. }
  229. return error(-1, '写入失败');
  230. }
  231. }
  232. function cloud_m_prepare($name) {
  233. $pars['method'] = 'module.check';
  234. $pars['module'] = $name;
  235. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars);
  236. if (is_error($dat)) {
  237. return $dat;
  238. }
  239. if ($dat['content'] == 'install-module-protect') {
  240. // return error('-1', '此模块已设置版权保护,您只能通过云平台来安装。');
  241. }
  242. return true;
  243. }
  244. function cloud_m_build($modulename, $type = '') {
  245. $type = in_array($type, array(
  246. 'uninstall'
  247. )) ? $type : '';
  248. $sql = 'SELECT * FROM ' . tablename('modules') . ' WHERE `name`=:name';
  249. $module = pdo_fetch($sql, array(
  250. ':name' => $modulename
  251. ));
  252. $pars = _cloud_build_params();
  253. $pars['method'] = 'module.build';
  254. $pars['module'] = $modulename;
  255. $pars['type'] = $type;
  256. if (!empty($module)) {
  257. $pars['module_version'] = $module['version'];
  258. }
  259. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars);
  260. $file = IA_ROOT . '/data/module.build';
  261. $ret = _cloud_shipping_parse($dat, $file);
  262. if (!is_error($ret)) {
  263. $dir = IA_ROOT . '/addons/' . $modulename;
  264. $files = array();
  265. if (!empty($ret['files'])) {
  266. foreach ($ret['files'] as $file) {
  267. $entry = $dir . $file['path'];
  268. if (!is_file($entry) || md5_file($entry) != $file['checksum']) {
  269. $files[] = '/' . $modulename . $file['path'];
  270. }
  271. }
  272. }
  273. $ret['files'] = $files;
  274. $schemas = array();
  275. if (!empty($ret['schemas'])) {
  276. load()->func('db');
  277. foreach ($ret['schemas'] as $remote) {
  278. $name = substr($remote['tablename'], 4);
  279. $local = db_table_schema(pdo() , $name);
  280. unset($remote['increment']);
  281. unset($local['increment']);
  282. if (empty($local)) {
  283. $schemas[] = $remote;
  284. } else {
  285. $diffs = db_table_fix_sql($local, $remote);
  286. if (!empty($diffs)) {
  287. $schemas[] = $remote;
  288. }
  289. }
  290. }
  291. }
  292. $ret['upgrade'] = true;
  293. $ret['type'] = 'module';
  294. $ret['schemas'] = $schemas;
  295. if (empty($module)) {
  296. $ret['install'] = 1;
  297. }
  298. cache_write('cloud:transtoken', authcode($ret['token'], 'ENCODE'));
  299. }
  300. return $ret;
  301. }
  302. function cloud_m_query() {
  303. $pars = _cloud_build_params();
  304. $pars['method'] = 'module.query';
  305. $pars['module'] = cloud_extra_module();
  306. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars);
  307. $file = IA_ROOT . '/data/module.query';
  308. $ret = _cloud_shipping_parse($dat, $file);
  309. return $ret;
  310. }
  311. function cloud_m_info($name) {
  312. $pars = _cloud_build_params();
  313. $pars['method'] = 'module.info';
  314. $pars['module'] = $name;
  315. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars);
  316. $file = IA_ROOT . '/data/module.info';
  317. $ret = _cloud_shipping_parse($dat, $file);
  318. return $ret;
  319. }
  320. function cloud_m_upgradeinfo($name) {
  321. $module = pdo_fetch("SELECT name, version FROM " . tablename('modules') . " WHERE name = '{$name}'");
  322. $pars = _cloud_build_params();
  323. $pars['method'] = 'module.info';
  324. $pars['module'] = $name;
  325. $pars['curversion'] = $module['version'];
  326. $pars['isupgrade'] = 1;
  327. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars);
  328. $file = IA_ROOT . '/data/module.info';
  329. $ret = _cloud_shipping_parse($dat, $file);
  330. if (!empty($ret) && !is_error($ret)) {
  331. $ret['site_branch'] = $ret['branches'][$ret['version']['branch_id']];
  332. $ret['from'] = 'cloud';
  333. foreach ($ret['branches'] as & $branch) {
  334. if ($branch['displayorder'] < $ret['site_branch']['displayorder'] || ($ret['site_branch']['displayorder'] == $ret['site_branch']['displayorder'] && $ret['site_branch']['id'] > intval($branch['id']))) {
  335. unset($module['branches'][$branch['id']]);
  336. continue;
  337. }
  338. $branch['id'] = intval($branch['id']);
  339. $branch['displayorder'] = intval($branch['displayorder']);
  340. $branch['day'] = intval(date('d', $branch['version']['createtime']));
  341. $branch['month'] = date('Y.m', $branch['version']['createtime']);
  342. $branch['hour'] = date('H:i', $branch['version']['createtime']);
  343. }
  344. unset($branch);
  345. }
  346. return $ret;
  347. }
  348. function cloud_t_prepare($name) {
  349. $pars['method'] = 'theme.check';
  350. $pars['theme'] = $name;
  351. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars);
  352. if (is_error($dat)) {
  353. return $dat;
  354. }
  355. if ($dat['content'] == 'install-theme-protect') {
  356. return error('-1', '此模板已设置版权保护,您只能通过云平台来安装。');
  357. }
  358. return true;
  359. }
  360. function cloud_t_query() {
  361. $pars = _cloud_build_params();
  362. $pars['method'] = 'theme.query';
  363. $pars['theme'] = cloud_extra_theme();
  364. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars);
  365. $file = IA_ROOT . '/data/theme.query';
  366. $ret = _cloud_shipping_parse($dat, $file);
  367. return $ret;
  368. }
  369. function cloud_t_info($name) {
  370. $pars = _cloud_build_params();
  371. $pars['method'] = 'theme.info';
  372. $pars['theme'] = $name;
  373. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars);
  374. $file = IA_ROOT . '/data/theme.info';
  375. $ret = _cloud_shipping_parse($dat, $file);
  376. return $ret;
  377. }
  378. function cloud_t_build($name) {
  379. $sql = 'SELECT * FROM ' . tablename('site_templates') . ' WHERE `name`=:name';
  380. $theme = pdo_fetch($sql, array(
  381. ':name' => $name
  382. ));
  383. $pars = _cloud_build_params();
  384. $pars['method'] = 'theme.build';
  385. $pars['theme'] = $name;
  386. if (!empty($theme)) {
  387. $pars['themeversion'] = $theme['version'];
  388. }
  389. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars);
  390. $file = IA_ROOT . '/data/theme.build';
  391. $ret = _cloud_shipping_parse($dat, $file);
  392. if (!is_error($ret)) {
  393. $dir = IA_ROOT . '/app/themes/' . $name;
  394. $files = array();
  395. if (!empty($ret['files'])) {
  396. foreach ($ret['files'] as $file) {
  397. $entry = $dir . $file['path'];
  398. if (!is_file($entry) || md5_file($entry) != $file['checksum']) {
  399. $files[] = '/' . $name . $file['path'];
  400. }
  401. }
  402. }
  403. $ret['files'] = $files;
  404. $ret['upgrade'] = true;
  405. $ret['type'] = 'theme';
  406. if (empty($theme)) {
  407. $ret['install'] = 1;
  408. }
  409. cache_write('cloud:transtoken', authcode($ret['token'], 'ENCODE'));
  410. }
  411. return $ret;
  412. }
  413. function cloud_t_upgradeinfo($name) {
  414. $sql = 'SELECT `name`, `version` FROM ' . tablename('site_templates') . ' WHERE `name` = :name';
  415. $theme = pdo_fetch($sql, array(
  416. ':name' => $name
  417. ));
  418. $pars = _cloud_build_params();
  419. $pars['method'] = 'theme.upgrade';
  420. $pars['theme'] = $theme['name'];
  421. $pars['version'] = $theme['version'];
  422. $pars['isupgrade'] = 1;
  423. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars);
  424. $file = IA_ROOT . '/data/module.info';
  425. $ret = _cloud_shipping_parse($dat, $file);
  426. return $ret;
  427. }
  428. function cloud_w_prepare($name) {
  429. $pars['method'] = 'webtheme.check';
  430. $pars['webtheme'] = $name;
  431. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars);
  432. if (is_error($dat)) {
  433. return $dat;
  434. }
  435. if ($dat['content'] == 'install-webtheme-protect') {
  436. return error('-1', '此后台皮肤已设置版权保护,您只能通过云平台来安装。');
  437. }
  438. return true;
  439. }
  440. function cloud_w_query() {
  441. $pars = _cloud_build_params();
  442. $pars['method'] = 'webtheme.query';
  443. $pars['webtheme'] = cloud_extra_webtheme();
  444. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars);
  445. $file = IA_ROOT . '/data/webtheme.query';
  446. $ret = _cloud_shipping_parse($dat, $file);
  447. return $ret;
  448. }
  449. function cloud_w_info($name) {
  450. $pars = _cloud_build_params();
  451. $pars['method'] = 'webtheme.info';
  452. $pars['webtheme'] = $name;
  453. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars);
  454. $file = IA_ROOT . '/data/webtheme.info';
  455. $ret = _cloud_shipping_parse($dat, $file);
  456. return $ret;
  457. }
  458. function cloud_w_build($name) {
  459. $sql = 'SELECT * FROM ' . tablename('webtheme_homepages') . ' WHERE `name`=:name';
  460. $webtheme = pdo_fetch($sql, array(
  461. ':name' => $name
  462. ));
  463. $pars = _cloud_build_params();
  464. $pars['method'] = 'webtheme.build';
  465. $pars['webtheme'] = $name;
  466. if (!empty($webtheme)) {
  467. $pars['webtheme_version'] = $webtheme['version'];
  468. }
  469. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars);
  470. $file = IA_ROOT . '/data/webtheme.build';
  471. $ret = _cloud_shipping_parse($dat, $file);
  472. if (!is_error($ret)) {
  473. $dir = IA_ROOT . '/web/themes/' . $name;
  474. $files = array();
  475. if (!empty($ret['files'])) {
  476. foreach ($ret['files'] as $file) {
  477. $entry = $dir . $file['path'];
  478. if (!is_file($entry) || md5_file($entry) != $file['checksum']) {
  479. $files[] = '/' . $name . $file['path'];
  480. }
  481. }
  482. }
  483. $ret['files'] = $files;
  484. $ret['upgrade'] = true;
  485. $ret['type'] = 'webtheme';
  486. if (empty($webtheme)) {
  487. $ret['install'] = 1;
  488. }
  489. cache_write('cloud:transtoken', authcode($ret['token'], 'ENCODE'));
  490. }
  491. return $ret;
  492. }
  493. function cloud_w_upgradeinfo($name) {
  494. $sql = 'SELECT `name`, `version` FROM ' . tablename('webtheme_homepages') . ' WHERE `name` = :name';
  495. $webtheme = pdo_fetch($sql, array(
  496. ':name' => $name
  497. ));
  498. $pars = _cloud_build_params();
  499. $pars['method'] = 'webtheme.upgrade';
  500. $pars['webtheme'] = $webtheme['name'];
  501. $pars['version'] = $webtheme['version'];
  502. $pars['isupgrade'] = 1;
  503. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars);
  504. $file = IA_ROOT . '/data/webtheme.info';
  505. $ret = _cloud_shipping_parse($dat, $file);
  506. return $ret;
  507. }
  508. function cloud_sms_send($mobile, $content, $postdata = array()) {
  509. global $_W;
  510. if (!preg_match('/^1\d{10}$/', $mobile) || empty($content)) {
  511. return error(1, '发送短信失败, 原因: 手机号错误或内容为空.');
  512. }
  513. $row = pdo_get('uni_settings', array(
  514. 'uniacid' => $_W['uniacid']
  515. ) , array(
  516. 'notify'
  517. ));
  518. $row['notify'] = @iunserializer($row['notify']);
  519. $config = $row['notify']['sms'];
  520. $balance = intval($config['balance']);
  521. $sign = $config['signature'];
  522. if (empty($sign)) {
  523. $sign = '涛盛微擎团队';
  524. }
  525. $pars = _cloud_build_params();
  526. $pars['method'] = 'sms.sendnew';
  527. $pars['mobile'] = $mobile;
  528. $pars['uniacid'] = $_W['uniacid'];
  529. $pars['balance'] = $balance;
  530. $pars['sign'] = $sign;
  531. if (!empty($postdata)) {
  532. $pars['content'] = $content;
  533. $pars['postdata'] = $postdata;
  534. } else {
  535. $pars['content'] = "{$content} 【{$sign}】";
  536. }
  537. $response = cloud_request('http://www.we7.cc/api/api.php', $pars);
  538. if (is_error($response)) {
  539. return error($response['errno'], '短信发送失败, 原因:' . $response['message']);
  540. }
  541. $result = json_decode($response['content'], true);
  542. if (is_error($result)) {
  543. return error($result['errno'], $result['message']);
  544. }
  545. if (intval($result['errno']) != - 1) {
  546. $row['notify']['sms']['balance'] = $row['notify']['sms']['balance'] - 1;
  547. if ($row['notify']['sms']['balance'] < 0) {
  548. $row['notify']['sms']['balance'] = 0;
  549. }
  550. pdo_update('uni_settings', array(
  551. 'notify' => iserializer($row['notify'])
  552. ) , array(
  553. 'uniacid' => $_W['uniacid']
  554. ));
  555. uni_setting_save('notify', $row['notify']);
  556. }
  557. return true;
  558. }
  559. function cloud_sms_info() {
  560. global $_W;
  561. $pars = _cloud_build_params();
  562. $pars['method'] = 'sms.info';
  563. $dat = cloud_request('http://www.we7.cc/api/api.php?', $pars);
  564. if ($dat['content'] == 'success') {
  565. $setting_key = "sms.info";
  566. $dat = setting_load($setting_key);
  567. return $dat[$setting_key];
  568. }
  569. return array();
  570. }
  571. function cloud_extra_account() {
  572. $data = array();
  573. $data['accounts'] = pdo_fetchall("SELECT name, account, original FROM " . tablename('account_wechats') . " GROUP BY account");
  574. return serialize($data);
  575. }
  576. function cloud_extra_module() {
  577. $sql = 'SELECT `name` FROM ' . tablename('modules') . ' WHERE `type` <> :type';
  578. $modules = pdo_fetchall($sql, array(
  579. ':type' => 'system'
  580. ) , 'name');
  581. if (!empty($modules)) {
  582. return base64_encode(iserializer(array_keys($modules)));
  583. } else {
  584. return '';
  585. }
  586. }
  587. function cloud_extra_theme() {
  588. $sql = 'SELECT `name` FROM ' . tablename('site_templates') . ' WHERE `name` <> :name';
  589. $themes = pdo_fetchall($sql, array(
  590. ':name' => 'default'
  591. ) , 'name');
  592. if (!empty($themes)) {
  593. return base64_encode(iserializer(array_keys($themes)));
  594. } else {
  595. return '';
  596. }
  597. }
  598. function cloud_extra_webtheme() {
  599. $sql = 'SELECT `name` FROM ' . tablename('webtheme_templates') . ' WHERE `name` <> :name';
  600. $themes = pdo_fetchall($sql, array(
  601. ':name' => 'default'
  602. ) , 'name');
  603. if (!empty($themes)) {
  604. return base64_encode(iserializer(array_keys($themes)));
  605. } else {
  606. return '';
  607. }
  608. }
  609. function cloud_cron_create($cron) {
  610. $pars = _cloud_build_params();
  611. $pars['method'] = 'cron.create';
  612. $pars['cron'] = base64_encode(iserializer($cron));
  613. $result = cloud_request('http://www.we7.cc/api/api.php', $pars);
  614. return _cloud_cron_parse($result);
  615. }
  616. function cloud_cron_update($cron) {
  617. $pars = _cloud_build_params();
  618. $pars['method'] = 'cron.update';
  619. $pars['cron'] = base64_encode(iserializer($cron));
  620. $result = cloud_request('http://www.we7.cc/api/api.php', $pars);
  621. return _cloud_cron_parse($result);
  622. }
  623. function cloud_cron_get($cron_id) {
  624. $pars = _cloud_build_params();
  625. $pars['method'] = 'cron.get';
  626. $pars['cron_id'] = $cron_id;
  627. $result = cloud_request('http://www.we7.cc/api/api.php', $pars);
  628. return _cloud_cron_parse($result);
  629. }
  630. function cloud_cron_change_status($cron_id, $status) {
  631. $pars = _cloud_build_params();
  632. $pars['method'] = 'cron.status';
  633. $pars['cron_id'] = $cron_id;
  634. $pars['status'] = $status;
  635. $result = cloud_request('http://www.we7.cc/api/api.php', $pars);
  636. return _cloud_cron_parse($result);
  637. }
  638. function cloud_cron_remove($cron_id) {
  639. $pars = _cloud_build_params();
  640. $pars['method'] = 'cron.remove';
  641. $pars['cron_id'] = $cron_id;
  642. $result = cloud_request('http://www.we7.cc/api/api.php', $pars);
  643. return _cloud_cron_parse($result);
  644. }
  645. function _cloud_cron_parse($result) {
  646. if (empty($result)) {
  647. return error(-1, '没有接收到服务器的传输的数据');
  648. }
  649. if ($result['content'] == 'blacklist') {
  650. return error(-1, '抱歉,您的站点已被列入云服务黑名单,云服务一切业务已被禁止,请联系微擎客服!');
  651. }
  652. $result = json_decode($result['content'], true);
  653. if (null === $result) {
  654. return error(-1, '云服务通讯发生错误,请稍后重新尝试!');
  655. }
  656. $result = $result['message'];
  657. if (is_error($result)) {
  658. return error(-1, $result['message']);
  659. }
  660. return $result;
  661. }
  662. function cloud_auth_url($forward, $data = array()) {
  663. global $_W;
  664. if (!empty($_W['setting']['site']['url']) && !strexists($_W['siteroot'], $_W['setting']['site']['url'])) {
  665. $url = $_W['setting']['site']['url'];
  666. } else {
  667. $url = rtrim($_W['siteroot'], '/');
  668. }
  669. $auth = array();
  670. $auth['key'] = '';
  671. $auth['password'] = '';
  672. $auth['url'] = $url;
  673. $auth['referrer'] = intval($_W['config']['setting']['referrer']);
  674. $auth['version'] = IMS_VERSION;
  675. $auth['forward'] = $forward;
  676. if (!empty($_W['setting']['site']['key']) && !empty($_W['setting']['site']['token'])) {
  677. $auth['key'] = $_W['setting']['site']['key'];
  678. $auth['password'] = md5($_W['setting']['site']['key'] . $_W['setting']['site']['token']);
  679. }
  680. if ($data && is_array($data)) {
  681. $auth = array_merge($auth, $data);
  682. }
  683. $query = base64_encode(json_encode($auth));
  684. $auth_url = 'http://www.we7.cc/api/auth.php?__auth=' . $query;
  685. return $auth_url;
  686. }
  687. function cloud_module_setting_prepare($module, $binding) {
  688. global $_W;
  689. $auth = _cloud_build_params();
  690. $auth['arguments'] = array(
  691. 'binding' => $binding,
  692. 'acid' => $_W['uniacid'],
  693. 'type' => 'module',
  694. 'module' => $module,
  695. );
  696. $iframe_auth_url = cloud_auth_url('module', $auth);
  697. return $iframe_auth_url;
  698. }
  699. function cloud_resource_to_local($uniacid, $type, $url) {
  700. global $_W;
  701. load()->func('file');
  702. $setting = $_W['setting']['upload'][$type];
  703. if (!file_is_image($url)) {
  704. return error(1, '远程图片后缀非法,请重新上传');;
  705. }
  706. $pathinfo = pathinfo($url);
  707. $extension = $pathinfo['extension'];
  708. $originname = $pathinfo['basename'];
  709. $setting['folder'] = "{$type}s/{$uniacid}/" . date('Y/m/');
  710. $originname = pathinfo($url, PATHINFO_BASENAME);
  711. $filename = file_random_name(ATTACHMENT_ROOT . '/' . $setting['folder'], $extension);
  712. $pathname = $setting['folder'] . $filename;
  713. $fullname = ATTACHMENT_ROOT . $pathname;
  714. mkdirs(dirname($fullname));
  715. load()->func('communication');
  716. $response = ihttp_get($url);
  717. if (is_error($response)) {
  718. return error(1, $response['message']);
  719. }
  720. if (file_put_contents($fullname, $response['content']) == false) {
  721. return error(1, '提取文件失败');
  722. }
  723. if (!empty($_W['setting']['remote']['type'])) {
  724. $remotestatus = file_remote_upload($pathname);
  725. if (is_error($remotestatus)) {
  726. return error(1, '远程附件上传失败,请检查配置并重新上传');
  727. } else {
  728. file_delete($pathname);
  729. }
  730. }
  731. $data = array(
  732. 'uniacid' => $uniacid,
  733. 'uid' => intval($_W['uid']) ,
  734. 'filename' => $originname,
  735. 'attachment' => $pathname,
  736. 'type' => $type == 'image' ? 1 : 2,
  737. 'createtime' => TIMESTAMP,
  738. );
  739. pdo_insert('core_attachment', $data);
  740. $data['url'] = tomedia($pathname);
  741. $data['id'] = pdo_insertid();
  742. return $data;
  743. }
  744. function cloud_bakup_files($files) {
  745. global $_W;
  746. if (empty($files)) {
  747. return false;
  748. }
  749. $map = json_encode($files);
  750. $hash = md5($map . $_W['config']['setting']['authkey']);
  751. if ($handle = opendir(IA_ROOT . '/data/patch/' . date('Ymd'))) {
  752. while (false !== ($patchpath = readdir($handle))) {
  753. if ($patchpath != '.' && $patchpath != '..') {
  754. if (strexists($patchpath, $hash)) {
  755. return false;
  756. }
  757. }
  758. }
  759. }
  760. $path = IA_ROOT . '/data/patch/' . date('Ymd') . '/' . date('Hi') . '_' . $hash;
  761. load()->func('file');
  762. if (!is_dir($path) && mkdirs($path)) {
  763. foreach ($files as $file) {
  764. if (file_exists(IA_ROOT . $file)) {
  765. mkdirs($path . '/' . dirname($file));
  766. file_put_contents($path . '/' . $file, file_get_contents(IA_ROOT . $file));
  767. }
  768. }
  769. file_put_contents($path . '/' . 'map.json', $map);
  770. }
  771. return false;
  772. }
  773. function cloud_flow_master_post($flow_master) {
  774. $pars = _cloud_build_params();
  775. $pars['method'] = 'flow.master_post';
  776. $pars['flow_master'] = array(
  777. 'linkman' => $flow_master['linkman'],
  778. 'mobile' => $flow_master['mobile'],
  779. 'address' => $flow_master['address'],
  780. 'id_card_photo' => $flow_master['id_card_photo'],
  781. 'business_licence_photo' => $flow_master['business_licence_photo'],
  782. );
  783. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars, array() , 300);
  784. if (is_error($dat)) {
  785. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  786. }
  787. cache_delete("cloud:flow:master");
  788. $ret = @json_decode($dat['content'], true);
  789. return $ret;
  790. }
  791. function cloud_flow_master_get() {
  792. $cachekey = "cloud:flow:master";
  793. $cache = cache_load($cachekey);
  794. if (!empty($cache) && $cache['expire'] > TIMESTAMP) {
  795. return $cache['setting'];
  796. }
  797. $pars = _cloud_build_params();
  798. $pars['method'] = 'flow.master_get';
  799. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars, array() , 300);
  800. if (is_error($dat)) {
  801. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  802. }
  803. $ret = @json_decode($dat['content'], true);
  804. if ($ret['status'] == '3') {
  805. cache_write($cachekey, array(
  806. 'expire' => TIMESTAMP + 300,
  807. 'setting' => $ret
  808. ));
  809. } else if ($ret['status'] == '4') {
  810. cache_write($cachekey, array(
  811. 'expire' => TIMESTAMP + 12 * 3600,
  812. 'setting' => $ret
  813. ));
  814. }
  815. return $ret;
  816. }
  817. function cloud_flow_uniaccount_post($uniaccount) {
  818. $pars = _cloud_build_params();
  819. $pars['method'] = 'flow.uniaccount_post';
  820. $pars['uniaccount'] = array(
  821. 'uniacid' => $uniaccount['uniacid'],
  822. );
  823. isset($uniaccount['title']) && $pars['uniaccount']['title'] = $uniaccount['title'];
  824. isset($uniaccount['original']) && $pars['uniaccount']['original'] = $uniaccount['original'];
  825. isset($uniaccount['gh_type']) && $pars['uniaccount']['gh_type'] = $uniaccount['gh_type'];
  826. isset($uniaccount['ad_tags']) && $pars['uniaccount']['ad_tags'] = $uniaccount['ad_tags'];
  827. isset($uniaccount['enable']) && $pars['uniaccount']['enable'] = $uniaccount['enable'];
  828. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars, array() , 300);
  829. if (is_error($dat)) {
  830. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  831. }
  832. cache_delete("cloud:ad:uniaccount:{$uniaccount['uniacid']}");
  833. cache_delete("cloud:ad:uniaccount:list");
  834. $ret = @json_decode($dat['content'], true);
  835. return $ret;
  836. }
  837. function cloud_flow_uniaccount_get($uniacid) {
  838. $cachekey = "cloud:ad:uniaccount:{$uniacid}";
  839. $cache = cache_load($cachekey);
  840. if (!empty($cache) && $cache['expire'] > TIMESTAMP) {
  841. return $cache['setting'];
  842. }
  843. $pars = _cloud_build_params();
  844. $pars['method'] = 'flow.uniaccount_get';
  845. $pars['uniaccount'] = array(
  846. 'uniacid' => $uniacid,
  847. );
  848. $pars['md5'] = md5(base64_encode(serialize($pars['uniaccount'])));
  849. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars, array() , 300);
  850. if (is_error($dat)) {
  851. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  852. }
  853. $ret = @json_decode($dat['content'], true);
  854. cache_write($cachekey, array(
  855. 'expire' => TIMESTAMP + 600,
  856. 'setting' => $ret
  857. ));
  858. return $ret;
  859. }
  860. function cloud_flow_uniaccount_list_get() {
  861. $cachekey = "cloud:ad:uniaccount:list";
  862. $cache = cache_load($cachekey);
  863. if (!empty($cache) && $cache['expire'] > TIMESTAMP) {
  864. return $cache['setting'];
  865. }
  866. $pars = _cloud_build_params();
  867. $pars['method'] = 'flow.uniaccount_list_get';
  868. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars, array() , 300);
  869. if (is_error($dat)) {
  870. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  871. }
  872. $ret = @json_decode($dat['content'], true);
  873. cache_write($cachekey, array(
  874. 'expire' => TIMESTAMP + 600,
  875. 'setting' => $ret
  876. ));
  877. return $ret;
  878. }
  879. function cloud_flow_ad_tag_list() {
  880. $cachekey = "cloud:ad:tags";
  881. $cache = cache_load($cachekey);
  882. if (!empty($cache) && $cache['expire'] > TIMESTAMP) {
  883. return $cache['items'];
  884. }
  885. $pars = _cloud_build_params();
  886. $pars['method'] = 'flow.ad_tag_list';
  887. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars, array() , 300);
  888. if (is_error($dat)) {
  889. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  890. }
  891. $ret = @json_decode($dat['content'], true);
  892. cache_write($cachekey, array(
  893. 'expire' => TIMESTAMP + 6 * 3600,
  894. 'items' => $ret
  895. ));
  896. return $ret;
  897. }
  898. function cloud_flow_ad_type_list() {
  899. $cachekey = "cloud:ad:type:list";
  900. $cache = cache_load($cachekey);
  901. if (!empty($cache) && $cache['expire'] > TIMESTAMP) {
  902. return $cache['items'];
  903. }
  904. $pars = _cloud_build_params();
  905. $pars['method'] = 'flow.ad_type_list';
  906. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars, array() , 300);
  907. if (is_error($dat)) {
  908. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  909. }
  910. $ret = @json_decode($dat['content'], true);
  911. cache_write($cachekey, array(
  912. 'expire' => TIMESTAMP + 3600,
  913. 'items' => $ret
  914. ));
  915. return $ret;
  916. }
  917. function cloud_flow_app_post($uniacid, $module_name, $enable = 0, $ad_types = null) {
  918. $pars = _cloud_build_params();
  919. $pars['method'] = 'flow.app_post';
  920. $pars['uniaccount_app'] = array(
  921. 'uniacid' => $uniacid,
  922. 'module' => $module_name,
  923. );
  924. if (!empty($enable)) {
  925. $pars['uniaccount_app']['enable'] = $enable;
  926. }
  927. if (is_array($ad_types)) {
  928. $pars['uniaccount_app']['ad_types'] = $ad_types;
  929. }
  930. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars, array() , 300);
  931. if (is_error($dat)) {
  932. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  933. }
  934. cache_delete("cloud:ad:app:list:{$uniacid}");
  935. $ret = @json_decode($dat['content'], true);
  936. return $ret;
  937. }
  938. function cloud_flow_app_list_get($uniacid) {
  939. $cachekey = "cloud:ad:app:list:{$uniacid}";
  940. $cache = cache_load($cachekey);
  941. if (!empty($cache) && $cache['expire'] > TIMESTAMP) {
  942. return $cache['setting'];
  943. }
  944. $pars = _cloud_build_params();
  945. $pars['method'] = 'flow.app_list_get';
  946. $pars['uniaccount'] = array(
  947. 'uniacid' => $uniacid,
  948. );
  949. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars, array() , 300);
  950. if (is_error($dat)) {
  951. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  952. }
  953. $ret = @json_decode($dat['content'], true);
  954. cache_write($cachekey, array(
  955. 'expire' => TIMESTAMP + 300,
  956. 'setting' => $ret
  957. ));
  958. return $ret;
  959. }
  960. function cloud_flow_app_support_list($module_names) {
  961. if (empty($module_names)) {
  962. return array();
  963. }
  964. $cachekey = "cloud:ad:app:support:list";
  965. $cache = cache_load($cachekey);
  966. if (!empty($cache) && $cache['expire'] > TIMESTAMP) {
  967. return $cache['setting'];
  968. }
  969. $pars = _cloud_build_params();
  970. $pars['method'] = 'flow.app_support_list';
  971. $pars['modules'] = $module_names;
  972. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars, array() , 300);
  973. if (is_error($dat)) {
  974. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  975. }
  976. $ret = @json_decode($dat['content'], true);
  977. cache_write($cachekey, array(
  978. 'expire' => TIMESTAMP + 300,
  979. 'setting' => $ret
  980. ));
  981. return $ret;
  982. }
  983. function cloud_flow_site_stat_day($condition) {
  984. $cachekey = "cloud:ad:site:finance";
  985. $cache = cache_load($cachekey);
  986. if (!empty($cache) && $cache['expire'] > TIMESTAMP) {
  987. return $cache['info'];
  988. }
  989. $pars = _cloud_build_params();
  990. $pars['method'] = 'flow.site_stat_day';
  991. $pars['condition'] = array();
  992. $pars['condition']['starttime'] = $condition['starttime'];
  993. $pars['condition']['endtime'] = $condition['endtime'];
  994. $pars['condition']['page'] = $condition['page'];
  995. $pars['condition']['size'] = $condition['size'];
  996. $dat = cloud_request('http://www.we7.cc/api/api.php', $pars, array() , 300);
  997. if (is_error($dat)) {
  998. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  999. }
  1000. $ret = @json_decode($dat['content'], true);
  1001. cache_write($cachekey, array(
  1002. 'expire' => TIMESTAMP + 300,
  1003. 'info' => $ret
  1004. ));
  1005. return $ret;
  1006. }
  1007. ?>