weiphp微信框架耗时卡慢解决办法
发布时间:2016-04-10, 02:07:44 分类:PHP | 编辑 off 网址 | 辅助
图集1/8
正文 2325字数 1,248,556阅读
//if (version_compare ( PHP_VERSION, '5.3.0', '<' ))
//die ( 'Your PHP Version is ' . PHP_VERSION . ', But WeiPHP require PHP > 5.3.0 !' );
//die ( 'Your PHP Version is ' . PHP_VERSION . ', But WeiPHP require PHP > 5.3.0 !' );
可注释掉完整代码如下
<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
//error_reporting ( E_ERROR );
// /调试、找错时请去掉///前空格
//ini_set ( 'display_errors', true );
//error_reporting ( E_ALL );
//set_time_limit ( 0 );
date_default_timezone_set ( 'PRC' );
//if (version_compare ( PHP_VERSION, '5.3.0', '<' ))
//die ( 'Your PHP Version is ' . PHP_VERSION . ', But WeiPHP require PHP > 5.3.0 !' );
/**
* 微信接入验证
* 在入口进行验证而不是放到框架里验证,主要是解决验证URL超时的问题
if (! empty ( $_GET ['echostr'] ) && ! empty ( $_GET ["signature"] ) && ! empty ( $_GET ["nonce"] )) {
$signature = $_GET ["signature"];
$timestamp = $_GET ["timestamp"];
$nonce = $_GET ["nonce"];
$tmpArr = array (
'weiphp',
$timestamp,
$nonce
);
sort ( $tmpArr, SORT_STRING );
$tmpStr = sha1 ( implode ( $tmpArr ) );
if ($tmpStr == $signature) {
echo $_GET ["echostr"];
}
exit ();
} */
/**
* 系统调试设置
* 项目正式部署后请设置为false
*/
define ( 'APP_DEBUG', false );
define ( 'SHOW_ERROR', false );
define ( 'IN_WEIXIN', false );
define ( 'DEFAULT_TOKEN', 'gh_d8953bc6f7b1' );
/**
* 官方远程同步服务器地址
* 应用于后台应用商店、在线升级,配置教程等功能
*/
//define ( 'REMOTE_BASE_URL', 'http://www.resonance.com.cn/' );
// 网站根路径设置
define ( 'SITE_PATH', dirname ( __FILE__ ) );
/**
* 应用目录设置
* 安全期间,建议安装调试完成后移动到非WEB目录
*/
define ( 'APP_PATH', './Application/' );
if (! is_file ( SITE_PATH.'/Data/install.lock' )) {
header ( 'Location: ./install.php' );
exit ();
}
/**
* 缓存目录设置
* 此目录必须可写,建议移动到非WEB目录
*/
define ( 'RUNTIME_PATH', './Runtime/' );
/**
* 引入核心入口
* ThinkPHP亦可移动到WEB以外的目录
*/
require './ThinkPHP/ThinkPHP.php';
Run code
Cut to clipboard
(支付宝)给作者钱财以资鼓励 (微信)→
有过 5 条评论 »
var_dump($repair->fetchSql(true)->where(array('cuername' =>$cuername))->order('applytime desc')->limit($page1*$listRows,$listRows)->select()); $list=$repair->where(array('cuername'=>$cuername))->order('applytime desc')->limit($page1*$listRows,$listRows)->select();
UEditor功能很强大,但是有个很不友好的功能:会在使用UEditor上传图片时,如果你的原始图片尺寸过大,就会先自动对图片大小进行压缩,然后将压缩的文件给servlet。也就是说,使用UEditor 上传图片后会导致图片大小发生改变并使图片变得模糊,而这是在用户毫不知情的情况下进行的操作,非常讨厌。
如果不想让上传的精美照片被UEditor 压缩得面目全非,可以通过以下方法禁止UEditor自动压缩图片:
打开该目录的文件:UEditor\php\ue.config.php,
ueditor.config.js 143行
修改前
修改后
新后台修改
\app\system\include\public\js\examples\editor\ueditor\third-party\webuploader
{if(d=c.canvasToDataUrl(b,"image/jpeg",e.quality),e.preserveHeaders&&this._metas&&this._metas.imageHead)return d=c.dataURL2ArrayBuffer(d),d=c.updateImageHead(d,this._metas.imageHead),d=c.arrayBufferToBlob(d,a)}else d=c.canvasToDataUrl(b,a);d=c.dataURL2Blob(d)}return d},getAsDataUrl:function(
UEditor上传图片被压缩得模糊的解决方法
UEditor功能很强大,但是有个很不友好的功能:会在使用UEditor上传图片时,如果你的原始图片尺寸过大,就会先自动对图片大小进行压缩,然后将压缩的文件给servlet。也就是说,使用UEditor 上传图片后会导致图片大小发生改变并使图片变得模糊,而这是在用户毫不知情的情况下进行的操作,非常讨厌。 如果不想让上传的精美照片被UEditor 压缩得面目全非,可以通过以下方法禁止UEditor自动压缩图片: 打开该目录的文件:UEditor\php\ue.config.php,找到如下代码: $CONFIG = array( /* 上传图片配置项 */ "imageActionName" => "uploadimage", /* 执行上传图片的action名称 */ "imageFieldName" => "upfile", /* 提交的图片表单名称 */ "imageMaxSize" => $max_size, /* 上传大小限制,单位B */ "imageAllowFiles" => $upload_allow, /* 上传图片格式显示 */ "imageCompressEnable" => true, /* 是否压缩图片,默认是true */ "imageCompressBorder" => 2940, /* 图片压缩最长边限制 */ "imageInsertAlign" => "none", /* 插入的图片浮动方式 */ "imageUrlPrefix" => "", /* 图片访问路径前缀 */ 将上述代码中imageCompressEnable 后的“true”参数改为“false”即可。当然,你也可以调整imageCompressBorder 后的参数,只有边长大于该值的照片才会被UEditor 压缩。 如果你觉得压缩图片的功能还是有点用,将下面这个目录中的文件 “UEditor\dialogs\image\image.js”中 "quality" 值调整为100 (代码瑞安),这样会对图片质量有一些改善,但还是差强人意,所以还是建议禁止UEditor 自动压缩图片。 compress: editor.getOpt('imageCompressEnable') ? { width: imageCompressBorder, height: imageCompressBorder, // 图片质量,只有type为`image/jpeg`的时候才有效。 quality: 90, // 是否允许放大,如果想要生成小图的时候不失真,此选项应该设置为false. allowMagnify: false, // 是否允许裁剪。 crop: false, // 是否保留头部meta信息。
quality
// 自动同步微信用户 C ( 'USER_LIST' ) && $this->_autoUpdateUser (); C ( 'USER_GROUP' ) && $this->_updateWechatGroup ();
function _autoUpdateUser
修改方法:
1.下载附件覆盖插件UserCenter(附件会替换所有文件,有做过修改的记得备份修改)
2.修改/Application/Common/Common/function.PHP找到
/** * 短链接功能 * * @param float $long_url * 长链接 * @return string 如果没有微信短链接接口权限或者不成功,就原样返回长链接,否则返回短链接 */ function short_url($long_url)
在这段代码之上增加以下代码
//处理头像 function get_name_by_touxiang($val) { if(!empty($val)){ return('<img height="48px" src="'.$val.'" />'); }else{ return('<img height="48px" src="'.ADDON_PUBLIC_PATH.'/face.png" />'); } } // 拉取10000个用户列表,通过openid获取微信用户基本信息,此功能只有认证的服务号才能用 function getWeixinUserAllInfo($token) { $access_token = get_access_token ( $token ); if (empty ( $access_token )) { return false; } $param ['access_token'] = $access_token; $url = 'https://api.weixin.qq.com/cgi-bin/user/get?'. http_build_query ( $param ); $content = file_get_contents ( $url ); $content = json_decode ( $content, true ); return $content; }
3.修改/Application/Common/Model/FollowModel.class.php
<?php namespace Common\Model; use Think\Model; use User\Api\UserApi; /** * 粉丝操作 */ class FollowModel extends Model { function init_follow($openid) { if (empty ( $openid ) || $openid == - 1) return false; $data ['token'] = get_token (); $data ['openid'] = $openid; $winfo = getWeixinUserInfo ($openid, $data ['token']); //获取用户所有信息 $info = $this->where ( $data )->find (); if ($info) { $save ['subscribe_time'] = $winfo ['subscribe_time']; $save ['nickname'] = $winfo ['nickname']; $save ['sex'] = $winfo ['sex']; $save ['city'] = $winfo ['city']; $save ['province'] = $winfo ['province']; $save ['country'] = $winfo ['country']; $save ['headimgurl'] = $winfo ['headimgurl']; $res = $this->where ( $data )->save ( $save ); } else { // $data ['subscribe_time'] = time (); // $uid = $this->get_uid_by_ucenter ( $data ['openid'], $data ['token'] ); //if ($uid > 0) { // $data ['id'] = $uid; $data ['subscribe_time'] = $winfo ['subscribe_time']; $data ['nickname'] = $winfo ['nickname']; $data ['sex'] = $winfo ['sex']; $data ['city'] = $winfo ['city']; $data ['province'] = $winfo ['province']; $data ['country'] = $winfo ['country']; $data ['headimgurl'] = $winfo ['headimgurl']; $res = $this->add ( $data ); //} $info = $data; } return $info; } //处理头像 function get_name_by_touxiang($val) { if(!empty($val)){ return('<img height="48px" src="'.$val.'" />'); }else{ return('<img height="48px" src="'.ADDON_PUBLIC_PATH.'/face.png" />'); } } // 自动初始化微信用户 function get_uid_by_ucenter($openid, $token) { static $_email_int = 0; $info ['openid'] = $openid; $info ['token'] = $token; $res = M ( 'ucenter_member' )->where ( $info )->find (); if ($res) return $res ['id']; $email = time () . rand ( 01, 99 ) . $_email_int . '@weiphp.cn'; $nickname = uniqid () . rand ( 01, 99 ) . $_email_int; /* 调用注册接口注册用户 */ $User = new UserApi (); $uid = $User->register ( $nickname, '123456', $email, '', $openid, $token ); $_email_int += 1; return $uid; } /** * 获取粉丝全部信息 */ public function getFollowInfo($id) { static $_followInfo; if (isset ( $_followInfo [$id] )) { return $_followInfo [$id]; } $_followInfo [$id] = $this->find ( $id ); return $_followInfo [$id]; } } ?>
4.进入后台,模型管理-粉丝管理-编辑,把列表定义改成:
id:粉丝编号 openid:OpenId headimgurl|get_name_by_touxiang:头像 nickname:昵称 sex|get_name_by_status:性别 province:省份 city:城市 subscribe_time|time_format:关注时间 ids:操作:[EDIT]|编辑
5.进入前台,基础插件-微信用户中心-拉取10000个已有粉丝,搞定
\app\system\include\public\js\examples\editor\ueditor\dialogs\insertframe
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script type="text/javascript" src="../internal.js"></script> <style type="text/css"> .warp {width: 320px;height: 153px;margin-left:5px;padding: 20px 0 0 15px;position: relative;} #url {width: 290px; margin-bottom: 2px; margin-left: -6px; margin-left: -2px\9;*margin-left:0;_margin-left:0; } .format span{display: inline-block; width: 58px;text-align: center; zoom:1;} table td{padding:5px 0;} #align{width: 65px;height: 23px;line-height: 22px;} </style> </head> <body> <div class="warp"> <table width="300" cellpadding="0" cellspacing="0"> <tr> <td colspan="2" class="format"> <!--<span><var id="lang_input_address"></var></span>--> <textarea id="url" style="width:280px" rows="6"></textarea> <!--<input style="width:200px" id="url" type="text" value=""/>--> </td> </tr> <tr> <td colspan="2" class="format"><span><var id="lang_input_width"></var></span><input style="width:200px" type="text" value="100%" id="width"/> </td> </tr> <tr> <td colspan="2" class="format"><span><var id="lang_input_height"></var></span><input style="width:200px" type="text" value="300" id="height"/> </td> </tr> <tr style="display:none;"> <td><span><var id="lang_input_isScroll"></var></span><input type="checkbox" id="scroll"/> </td> <td><span><var id="lang_input_frameborder"></var></span><input type="checkbox" id="frameborder"/> </td> </tr> <tr style="display:none;"> <td colspan="2"><span><var id="lang_input_alignMode"></var></span> <select id="align"> <option value=""></option> <option value="left"></option> <option value="right"></option> </select> </td> </tr> </table> </div> <script type="text/javascript"> var iframe = editor._iframe; if(iframe){ $G("url").value = iframe.getAttribute("src")||""; $G("width").value = iframe.getAttribute("width")||iframe.style.width.replace("px","")||""; $G("height").value = iframe.getAttribute("height") || iframe.style.height.replace("px","") ||""; $G("scroll").checked = (iframe.getAttribute("scrolling") == "yes") ? true : false; $G("frameborder").checked = (iframe.getAttribute("frameborder") == "1") ? true : false; $G("align").value = iframe.align ? iframe.align : ""; } function queding(){ var url = $G("url").value.replace(/^\s*|\s*$/ig,""), width = $G("width").value, height = $G("height").value, scroll = $G("scroll"), frameborder = $G("frameborder"), float = $G("align").value, newIframe = editor.document.createElement("iframe"), div; if(!url){ alert(lang.enterAddress); return false; } urlsss = url.replace(/'/g,'"'); //alert(url); var reg = /(?<=(src="))[^"]*?(?=")/ig; var allSrc = urlsss.match(reg); //alert(allSrc); if(allSrc) url = allSrc; newIframe.setAttribute("src",/http:\/\/|https:\/\//ig.test(url) ? url : "http://"+url); // /^[1-9]+[.]?\d*$/g.test( width ) ? newIframe.setAttribute("width",width) : ""; newIframe.setAttribute("width",width); // /^[1-9]+[.]?\d*$/g.test( height ) ? newIframe.setAttribute("height",height) : ""; newIframe.setAttribute("height",height); scroll.checked ? newIframe.setAttribute("scrolling","yes") : newIframe.setAttribute("scrolling","no"); frameborder.checked ? newIframe.setAttribute("frameborder","1",0) : newIframe.setAttribute("frameborder","0",0); float ? newIframe.setAttribute("align",float) : newIframe.setAttribute("align",""); //newIframe=$G("url").value; if(iframe){ iframe.parentNode.insertBefore(newIframe,iframe); domUtils.remove(iframe); }else{ div = editor.document.createElement("div"); div.appendChild(newIframe); editor.execCommand("inserthtml",div.innerHTML); } editor._iframe = null; dialog.close(); } dialog.onok = queding; $G("url").onkeydown = function(evt){ evt = evt || event; if(evt.keyCode == 13){ queding(); } }; $focus($G( "url" )); </script> </body> </html>