front-download.ctrl.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. load()->model('wxapp');
  8. load()->classs('cloudapi');
  9. load()->classs('uploadedfile');
  10. $dos = array('front_download', 'domainset', 'code_uuid', 'code_gen', 'code_token', 'qrcode', 'checkscan',
  11. 'commitcode', 'preview', 'getpackage', 'entrychoose', 'set_wxapp_entry',
  12. 'custom', 'custom_save', 'custom_default', 'custom_convert_img');
  13. $do = in_array($do, $dos) ? $do : 'front_download';
  14. $_W['page']['title'] = '小程序下载 - 小程序 - 管理';
  15. $version_id = intval($_GPC['version_id']);
  16. $wxapp_info = wxapp_fetch($_W['uniacid']);
  17. $is_module_wxapp = false;
  18. if (!empty($version_id)) {
  19. $version_info = wxapp_version($version_id);
  20. $is_single_module_wxapp = $version_info['type'] == WXAPP_CREATE_MODULE; }
  21. if ($do == 'entrychoose') {
  22. $entrys = $version_info['cover_entrys'];
  23. template('wxapp/version-front-download');
  24. }
  25. if ($do == 'set_wxapp_entry') {
  26. $entry_id = intval($_GPC['entry_id']);
  27. $result = wxapp_update_entry($version_id, $entry_id);
  28. iajax(0, '设置入口成功');
  29. }
  30. if ($do == 'custom') {
  31. $default_appjson = wxapp_code_current_appjson($version_id);
  32. $default_appjson = json_encode($default_appjson);
  33. template('wxapp/version-front-download');
  34. }
  35. if ($do == 'custom_default') {
  36. $result = wxapp_code_set_default_appjson($version_id);
  37. iajax($result);
  38. }
  39. if ($do == 'custom_save') {
  40. $json = $_GPC['json'];
  41. $result = wxapp_code_save_appjson($version_id, $json);
  42. iajax($result, '');
  43. }
  44. if ($do == 'custom_convert_img') {
  45. $attchid = intval($_GPC['att_id']);
  46. $filename = wxapp_code_path_convert($attchid);
  47. iajax(0, $filename);
  48. }
  49. if ($do == 'domainset') {
  50. $appurl = $_W['siteroot'].'app/index.php';
  51. $uniacid = 0;
  52. if ($version_info) {
  53. $wxapp = pdo_get('account_wxapp', array('uniacid' => $version_info['uniacid']));
  54. if ($wxapp && !empty($wxapp['appdomain'])) {
  55. $appurl = $wxapp['appdomain'];
  56. }
  57. if (!starts_with($appurl, 'https')) { $appurl = str_replace('http', 'https', $appurl);
  58. }
  59. $uniacid = $version_info['uniacid'];
  60. }
  61. if ($_W['ispost']) {
  62. $files = UploadedFile::createFromGlobal();
  63. $appurl = $_GPC['appurl'];
  64. if (!starts_with($appurl, 'https')) {
  65. itoast('域名必须以https开头');
  66. return;
  67. }
  68. $file = isset($files['file']) ? $files['file'] : null;
  69. if ($file && $file->isOk() && $file->allowExt('txt')) {
  70. $file->moveTo(IA_ROOT.'/'.$file->getClientFilename()); }
  71. if ($version_info) {
  72. $update = pdo_update('account_wxapp', array('appdomain' => $appurl),
  73. array('uniacid' => $uniacid));
  74. itoast('更新小程序域名成功'); }
  75. }
  76. template('wxapp/version-front-download');
  77. }
  78. if ($do == 'front_download') {
  79. $appurl = $_W['siteroot'].'/app/index.php';
  80. $uptype = $_GPC['uptype'];
  81. $wxapp_versions_info = wxapp_version($version_id);
  82. if (!in_array($uptype, array('auto', 'normal'))) {
  83. $uptype = 'auto';
  84. }
  85. template('wxapp/version-front-download');
  86. }
  87. if ($do == 'code_uuid') {
  88. $data = wxapp_code_generate($version_id);
  89. echo json_encode($data);
  90. }
  91. if ($do == 'code_gen') {
  92. $code_uuid = $_GPC['code_uuid'];
  93. $data = wxapp_check_code_isgen($code_uuid);
  94. echo json_encode($data);
  95. }
  96. if ($do == 'code_token') {
  97. $tokendata = wxapp_code_token();
  98. echo json_encode($tokendata);
  99. }
  100. if ($do == 'qrcode') {
  101. $code_token = $_GPC['code_token'];
  102. header('Content-type: image/jpg'); echo wxapp_code_qrcode($code_token);
  103. exit;
  104. }
  105. if ($do == 'checkscan') {
  106. $code_token = $_GPC['code_token'];
  107. $last = $_GPC['last'];
  108. $data = wxapp_code_check_scan($code_token, $last);
  109. echo json_encode($data);
  110. }
  111. if ($do == 'preview') {
  112. $code_token = $_GPC['code_token'];
  113. $code_uuid = $_GPC['code_uuid'];
  114. $data = wxapp_code_preview_qrcode($code_uuid, $code_token);
  115. echo json_encode($data);
  116. }
  117. if ($do == 'commitcode') {
  118. $user_version = $_GPC['user_version'];
  119. $user_desc = $_GPC['user_desc'];
  120. $code_token = $_GPC['code_token'];
  121. $code_uuid = $_GPC['code_uuid'];
  122. $data = wxapp_code_commit($code_uuid, $code_token, $user_version, $user_desc);
  123. echo json_encode($data);
  124. }
  125. if ($do == 'getpackage') {
  126. if (empty($version_id)) {
  127. itoast('参数错误!', '', '');
  128. }
  129. $account_wxapp_info = wxapp_fetch($version_info['uniacid'], $version_id);
  130. if (empty($account_wxapp_info)) {
  131. itoast('版本不存在!', referer(), 'error');
  132. }
  133. $siteurl = $_W['siteroot'].'app/index.php';
  134. if (!empty($account_wxapp_info['appdomain'])) {
  135. $siteurl = $account_wxapp_info['appdomain'];
  136. }
  137. $request_cloud_data = array(
  138. 'name' => $account_wxapp_info['name'],
  139. 'modules' => $account_wxapp_info['version']['modules'],
  140. 'siteInfo' => array(
  141. 'name' => $account_wxapp_info['name'],
  142. 'uniacid' => $account_wxapp_info['uniacid'],
  143. 'acid' => $account_wxapp_info['acid'],
  144. 'multiid' => $account_wxapp_info['version']['multiid'],
  145. 'version' => $account_wxapp_info['version']['version'],
  146. 'siteroot' => $siteurl,
  147. 'design_method' => $account_wxapp_info['version']['design_method'],
  148. ),
  149. 'tabBar' => json_decode($account_wxapp_info['version']['quickmenu'], true),
  150. );
  151. $result = wxapp_getpackage($request_cloud_data);
  152. if (is_error($result)) {
  153. itoast($result['message'], '', '');
  154. } else {
  155. header('content-type: application/zip');
  156. header('content-disposition: attachment; filename="'.$request_cloud_data['name'].'.zip"');
  157. echo $result;
  158. }
  159. exit;
  160. }