Skip to content

Commit

Permalink
支持微信小程序上传
Browse files Browse the repository at this point in the history
  • Loading branch information
brjunsuc committed Mar 3, 2023
1 parent 7ae165d commit 5a7ed22
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 36 deletions.
60 changes: 30 additions & 30 deletions web/common/permission.inc.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,48 @@
* 'clerk' 代表 店员拥有的权限
* 权限中带星号'*'指拥有该文件夹下所有权限.
*/
$w7_file_permission = array();
$w7_file_permission = array(
'account' => array(
$w7_file_permission = [];
$w7_file_permission = [
'account' => [
'default' => '',
'direct' => array(),
),
'message' => array(
'direct' => [],
],
'message' => [
'default' => '',
'direct' => array(),
),
'module' => array(
'direct' => [],
],
'module' => [
'default' => '',
'direct' => array(),
),
'platform' => array(
'direct' => [],
],
'platform' => [
'default' => '',
'direct' => array(),
),
'site' => array(
'direct' => [],
],
'site' => [
'default' => '',
'direct' => array(
'direct' => [
'entry',
),
),
'system' => array(
],
],
'system' => [
'default' => '',
'direct' => array(),
),
'user' => array(
'direct' => [],
],
'user' => [
'default' => '',
'direct' => array(
'direct' => [
'login',
),
),
'utility' => array(
],
],
'utility' => [
'default' => '',
'direct' => array(
'direct' => [
'visit',
'bindcall',
'mp-verify',
),
),
);
],
],
];

return $w7_file_permission;
23 changes: 17 additions & 6 deletions web/source/wxapp/front-download.ctrl.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@

if ('front_download' == $do) {
$type = 'wxapp';
if (!empty($_W['setting']['server_setting']) && !empty($_W['setting']['server_setting']['app_id'])) {
$package_url = url('wxapp/front-download/getpackage', ['module_name' => $module_name, 'version_id' => $version_id, '__session' => $_GPC['__session']], true);
$upload_route = '/upload?url=' . urlencode($package_url) . '&app_id=' . $_W['setting']['server_setting']['app_id'] . '&support_type[]=2';
}
template('wxapp/version-front-download');
}
if ('getpackage' == $do) {
Expand All @@ -112,7 +116,7 @@
$uniacid_zip_name = $module['name'] . '_wxapp_' . $uniacid . md5(time()) . '.zip';
$zip = new ZipArchive();
if ($zip->open($module_root . $uniacid_zip_name, ZipArchive::CREATE) === true) {//如果只用ZipArchive::OVERWRITE那么如果指定目标存在的话就会复写,否则返回错误9,而两个都用则会避免这个错误
addFileToZip($module_root . $dir_name, $zip, $module_root);
addFileToZip($module_root . $dir_name, $zip, $module_root . $dir_name . '/');
$zip->close();
}
if (!is_dir(ATTACHMENT_ROOT . '/siteinfo')) {
Expand Down Expand Up @@ -144,12 +148,12 @@
file_write($tmp_app_json_file, json_encode($app_json));
}
if ($zip->open(ATTACHMENT_ROOT . '/siteinfo/' . $uniacid_zip_name) === true) {
$zip->addFile(ATTACHMENT_ROOT . '/' . $tmp_siteinfo_file, $dir_name . '/siteinfo.js');
$zip->addFile(ATTACHMENT_ROOT . '/' . $tmp_siteinfo_file, 'siteinfo.js');
if (!empty($tmp_app_json_file)) {
$zip->addFile(ATTACHMENT_ROOT . '/' . $tmp_app_json_file, $dir_name . '/app.json');
$zip->addFile(ATTACHMENT_ROOT . '/' . $tmp_app_json_file, 'app.json');
}
$zip->close();
$result = array('url' => $_W['siteroot'] . 'attachment/siteinfo/' . $uniacid_zip_name);
$result = array('url' => ATTACHMENT_ROOT . '/siteinfo/' . $uniacid_zip_name);
}
@unlink(ATTACHMENT_ROOT . '/' . $tmp_siteinfo_file);
if (!empty($tmp_app_json_file)) {
Expand All @@ -161,8 +165,15 @@
if (is_error($result)) {
itoast($result['message'], '', '');
} else {
header("http/1.1 301 moved permanently");
header("location: " . $result['url']);
header('Content-Type: application/octet-stream');
header('Content-Disposition:attachment;filename=' . $uniacid_zip_name);
$fp = fopen(ATTACHMENT_ROOT . '/siteinfo/' . $uniacid_zip_name, 'r+');
$buffer = 1024;
while (!feof($fp)) {
$file_data = fread($fp, $buffer);
echo $file_data;
}
fclose($fp);
}
exit;
}
Expand Down
13 changes: 13 additions & 0 deletions web/themes/default/wxapp/version-front-download.html
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,21 @@ <h4 class="media-heading color-dark">{$module['title']}</h4>
</div>
<div class="media-right media-middle">
<a href="{php echo url('wxapp/front-download/getpackage', ['module_name' => $module_name, 'version_id' => $version_id])}" class="btn btn-primary">立即下载</a>
<a href="javascript:;" class="btn btn-primary" onclick="authorizationUpload()">授权上传</a>
</div>
</div>
<script>
function authorizationUpload() {
window.w7.ready(()=>{
window.w7.navigate({
modulename: 'w7_rangineapi', // 根据modulename选择
type: 'micro', // micro or iframe 目标应用是vue 用micro
route: '{php echo $upload_route}', // 要打开应用的路由
style: {width:1000, height:700},
});
})
}
</script>
<style>
.img img{
width: 250px;
Expand Down

0 comments on commit 5a7ed22

Please sign in to comment.