管理过公众平台的小伙伴都知道,公众平台最重要的是图文的编辑和发布,由于微信公众平台的图文编辑页面比较简陋,功能和样式的比较少,所以一般都是使用专业的微信图文编辑器,koahub软件市场里有一款专门编辑微信图文的源码,可免费下载。
管理过公众平台的小伙伴都知道,公众平台最重要的是图文的编辑和发布,由于微信公众平台的图文编辑页面比较简陋,功能和样式的比较少,所以一般都是使用专业的微信图文编辑器,koahub软件市场里有一款专门编辑微信图文的源码,可免费下载。
下面是微信编辑器的部分代码:
1、抓取远程图片
$config['catcherpathformat'],
maxsize => $config['catchermaxsize'],
allowfiles => $config['catcherallowfiles'],
oriname => remote.png
);
$fieldname = $config['catcherfieldname'];
/* 抓取远程图片 */
$list = array();
if (isset($_post[$fieldname])) {
$source = $_post[$fieldname];
} else {
$source = $_get[$fieldname];
}
foreach ($source as $imgurl) {
$item = new uploader($imgurl, $config, remote);
$info = $item->getfileinfo();
array_push($list, array(
state => $info[state],
url => $info[url],
size => $info[size],
title => htmlspecialchars($info[title]),
original => htmlspecialchars($info[original]),
source => htmlspecialchars($imgurl)
));
}
/* 返回抓取数据 */
return json_encode(array(
'state'=> count($list) ? 'success':'error',
'list'=> $list
));
2、 获取已上传的文件列表
no match file,
list => array(),
start => $start,
total => count($files)
));
}
/* 获取指定范围的列表 */
$len = count($files);
for ($i = min($end, $len) - 1, $list = array(); $i = 0 && $i >= $start; $i--){
$list[] = $files[$i];
}
//倒序
//for ($i = $end, $list = array(); $i // $list[] = $files[$i];
//}
/* 返回数据 */
$result = json_encode(array(
state => success,
list => $list,
start => $start,
total => count($files)
));
return $result;
/**
* 遍历获取目录下的指定类型的文件
* @param $path
* @param array $files
* @return array
*/
function getfiles($path, $allowfiles, &$files = array())
{
if (!is_dir($path)) return null;
if(substr($path, strlen($path) - 1) != '/') $path .= '/';
$handle = opendir($path);
while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..') {
$path2 = $path . $file;
if (is_dir($path2)) {
getfiles($path2, $allowfiles, $files);
} else {
if (preg_match(/\.(.$allowfiles.)$/i, $file)) {
$files[] = array(
'url'=> substr($path2, strlen($_server['document_root'])),
'mtime'=> filemtime($path2)
);
}
}
}
}
return $files;
}
3、上传附件和上传视频
$config['imagepathformat'],
maxsize => $config['imagemaxsize'],
allowfiles => $config['imageallowfiles']
);
$fieldname = $config['imagefieldname'];
break;
case 'uploadscrawl':
$config = array(
pathformat => $config['scrawlpathformat'],
maxsize => $config['scrawlmaxsize'],
allowfiles => $config['scrawlallowfiles'],
oriname => scrawl.png
);
$fieldname = $config['scrawlfieldname'];
$base64 = base64;
break;
case 'uploadvideo':
$config = array(
pathformat => $config['videopathformat'],
maxsize => $config['videomaxsize'],
allowfiles => $config['videoallowfiles']
);
$fieldname = $config['videofieldname'];
break;
case 'uploadfile':
default:
$config = array(
pathformat => $config['filepathformat'],
maxsize => $config['filemaxsize'],
allowfiles => $config['fileallowfiles']
);
$fieldname = $config['filefieldname'];
break;
}
/* 生成上传实例对象并完成上传 */
$up = new uploader($fieldname, $config, $base64);
/**
* 得到上传文件所对应的各个参数,数组结构
* array(
* state => , //上传状态,上传成功时必须返回success
* url => , //返回的地址
* title => , //新文件名
* original => , //原始文件名
* type => //文件类型
* size => , //文件大小
* )
*/
/* 返回数据 */
return json_encode($up->getfileinfo());
下载地址:http://www.koahub.com/home/product/40
演示地址:http://1.inuoer.com/wxedit/
koahub.js -- 基于 koa.js 平台的 node.js web 快速开发框架
官网:http://js.koahub.com