首页 > 编程技术 > php

解决帝国cms帝国数据库备份王php5.3下500错误

发布时间:2016-11-25 17:17

500错误就是程序错误了如果我们使用了帝国cms帝国数据库备份王的话在php5.3版本中好你不能正确的使用了,对于这个问题我们来看如何处理吧。

备份数据库,就是用Empirebak,可在php5.1.6上正常的帝国备份王却升级php5.3.6后出现500错误。

又开始百度,结果搜不到,看来百度也不行就到帝国官方论坛提问。

提问一时半会没答案就又谷歌搜索php5.4.6的问题,一直没解决

后来帝国论坛有人答复,问题解决很简单,修改php.ini,把short_open_tag 设为 On

vi etc/php.ini

/short_open_tag

把默认Off的改成On

 

即: short_open_tag = on

 

:wq

service httpd restart

OK了 不光帝国备份王正常了,而且昨天不好使的探针也好使了

 

如果是windows 的,找到php.ini的位置,不知道如何找?

 

用phpinfo(); 看看,php.ini加载的位置 ,然后找到php.ini,去修改 short_open_tag =Off,为:short_open_tag = on

支付宝服务窗API接口的开发对于许多网站要充值的朋友来讲是非常的重要的,今天我们就一起来看一篇关于php版本的支付宝服务窗API接口的开发例子。

这两天没事要接入支付宝服务窗,看支付宝的DEMO,我的神,我怎么评价好呢?开发思路很牛逼,但是阅读性不是很好,很阻碍简单的开发。所以我就根据提供的API简单的开发了点,接口还有很多不完善,有兴趣的可以自己完善一下,下边我就把代码贴出来,有时间再写如何使用。

<?php


class AlipayService{

    /**
     - 服务接口信息
     */

    public $service = null;

    /**
     - 签名信息
     */

    public $sign = null;

    /**
     - 签名类型
     */

    public $sign_type = null;

    /**
     - 字符集
     */

    public $charset = null;

    /**
     - 解析的biz_content数据
     */

    public $request = null;

    /**
     - 用户openid
     */

    public $from_user_id = null;

    /**
     - 消息类型
     */

    public $msg_type = null;

    /**
     - 事件类型
     */

    public $event_type = null;

    /**
     - 行为参数
     */

    public $action_param = null;

    /**
     - 支付宝用户信息
     */

    public $user_info = null;

    /**
     - 文本消息内容
     */

    public $text = null;

    /**
     - 图片媒体id
     */

    public $media_id = null;

    /**
     - 图片格式
     */

    public $format = null;

    /**
     - 是否开启调试
     */

    private $debug = false;

    /**
     - 接口类型
     */

    private $interface_type = array(   
            'qrcode'      => 'alipay.mobile.public.qrcode.create', 
            'follow'      => 'alipay.mobile.public.follow.list',   
            'gis_get'     => 'alipay.mobile.public.gis.get',   
            'menu_get'    => 'alipay.mobile.public.menu.get',        
            'menu_add'    => 'alipay.mobile.public.menu.add',
            'down_media'  => 'alipay.mobile.public.multimedia.download',
            'menu_update' => 'alipay.mobile.public.menu.update',   
            'info_query'  => 'alipay.mobile.public.info.query',
            'info_modify' => 'alipay.mobile.public.info.modify',
            'shortlink'   => 'alipay.mobile.public.shortlink.create',  
            'label_add'   => 'alipay.mobile.public.label.add', 
            'label_del'   => 'alipay.mobile.public.label.delete',  
            'label_update'        => 'alipay.mobile.public.label.update',  
            'label_query'         => 'alipay.mobile.public.label.query',   
            'label_user_add'      => 'alipay.mobile.public.label.user.add',
            'label_user_del'      => 'alipay.mobile.public.label.user.delete', 
            'label_user_query'    => 'alipay.mobile.public.label.user.query',  
            'message_custom'      => 'alipay.mobile.public.message.custom.send',   
            'message_total'       => 'alipay.mobile.public.message.total.send',
            'message_single'      => 'alipay.mobile.public.message.single.send',   
            'message_label_send'  => 'alipay.mobile.public.message.label.send',
        );

    /**
     - 私有密钥地址,替换为你自己的
     */

    private $private_rsa_key_path ='rsa_private_key.pem';

    /**
     - 私有密钥地址,替换为你自己的
     */

    private $public_rsa_key_path ='rsa_public_key.pem';

    /**
     - 支付宝窗的app id 替换成你自己的
     */

    private $app_id = '2015120200901652';

    /**
     - 开启DEBUG参数
     - @params bool  debug  true 开启调试 false 关闭调试
     - @author widuu <admin@widuu.com>
     */

    public function __construct( $debug = false ){
        /* 是否开启DEBUG */
        if( $debug ) $this->debug = true;
    }

    /**
     - 获取参数,解析请求参数
     -
     - @author widuu <admin@widuu.com>
     */

    public function get_request(){
        if( !empty($_POST) ){
            // 请求的服务接口
            $this->service = $_POST['service'];
            // 获取请求字符集
            $this->charset = $_POST['charset'];
            // 获取请求的biz_content
            $request_biz_content = $_POST['biz_content'];
            // 加密算法
            $this->sign_type = $_POST['sign_type'];
            // 加密字符串
            $this->sign = $_POST['sign'];
            // 如果请求格式不是Utf-8 转换格式为Utf-8
            if( strtolower($this->charset) != 'utf-8' ){
                $request_biz_content = iconv('GBK', 'utf-8', $request_biz_content);
            }
            // 解析字符串为xml
            $request_xml   = @simplexml_load_string($request_biz_content, "SimpleXMLElement" , LIBXML_NOCDATA );
            // 解析为数组
            $request_array = json_decode(json_encode($request_xml),true);

            $this->request = $request_array;

            /* 解析 */
            $this->analysis($request_array);

            if($this->debug) $this->write_log('REQUEST_INFO',var_export($request_array,true));

            // 默认验证方法
            if( $this->service == 'alipay.service.check'){
                $this->verify($_POST);
                exit();
            }

            /* 返回结果 */
            return $request_array;
        }

    }

    /**
     - 回复文本内容
     - @params string content  文本数据
     - @params bool   mass     ture为群发
     - @author widuu <admin@widuu.com>
     */

    public function text($content,$mass=false){
        $info['text'] = array( 'content' => $content );
        /* 组织内容 */
        $biz_content = $this->common_response('text',$info,$mass);
        /* 判断是否为群发 */
        if($mass){
            $method = 'message_total';
        }else{
            $method = 'message_custom';
        }
        $sys_params = $this->common_system($method,$biz_content);
        $sys_params['sign'] = $this->rsa_sign($this->build_query($sys_params));
        /* 返回结果 结果是JSON数据 */
        $result = $this->response_post($sys_params);

        return $result;
    }

    /**
     - 回复图文内容
     - @params array articles  拼接的图文消息数组
     - @params bool   mass     ture为群发
     - @author widuu <admin@widuu.com>
     */

    public function articles($articles,$mass=false){

        $info['articles'] = array($articles);
        /* 组织内容 */
        $biz_content = $this->common_response('image-text',$info,$mass);
        /* 判断是否群发 */
        if($mass){
            $method = 'message_total';
        }else{
            $method = 'message_custom';
        }

        /* 加密参数 */
        $sys_params = $this->common_system($method,$biz_content);

        /* 加密字符 */
        $sys_params['sign'] = $this->rsa_sign($this->build_query($sys_params));

        /* 返回结果 结果是JSON数据 */
        $result = $this->response_post($sys_params);

        return $result;
    }

    /**
     - 关注事件
     -
     - @author widuu <admin@widuu.com>
     */

    public function is_follow(){
        $request = $this->request;
        if( $request['MsgType'] == 'event' && $request['EventType'] == 'follow' ){
            return true;
        }else{
            return false;
        }
    }

    /**
     - 取消关注事件
     -
     - @author widuu <admin@widuu.com>
     */

    public function is_unfollow(){
        $request = $this->request;
        if( $request['MsgType'] == 'event' && $request['EventType'] == 'unfollow' ){
            return true;
        }else{
            return false;
        }
    }

    /**
     - 下载用户发来的图片
     - @param  media_id string  图片id
     - @param  filename string  保存图片地址和名称
     - @author widuu <admin@widuu.com>
     */

    public function down_media($media_id,$filename){
        $sys_params = $this->common_system('down_media',array('mediaId'=>$media_id));
        $sys_params['sign'] = $this->rsa_sign($this->build_query($sys_params));
        /* 返回数据 */
        $result = $this->response_post($sys_params,true);
        $result = file_put_contents($filename, $result);
        if( $this->debug ){
            $this->write_log('SAVE_IMAGE','保存图片'.(string)$result);
        }
        return $result;
    }

    /**
     - (添加|更新|获取)自定义菜单
     - @param  string $type  (add|update|get)
     - @param  array  $menu   菜单数组,如果是获取菜单可以留空
     - @author widuu <admin@widuu.com>
     */

    public function menu( $type,$menu = array() ){
        if( !in_array( $type, array('get','update','add')) ){
            if( $this->debug ){
                $this->write_log('ERROR','菜单操作方法错误');
            }
            return false;
        }

        /* 拼接接口方法 */
        $method = 'menu_'.$type;
        $sys_params = $this->common_system($method,$menu);

        /* 加密字符串 */
        $sys_params['sign'] = $this->rsa_sign($this->build_query($sys_params));

        /* 请求获取结果 */
        $result = $this->response_post($sys_params);

        /* 转义并解析JSON 数据 */
        $menu_json = json_decode(iconv('GBK', 'utf-8', $result),true);

        /* 组织接口信息 */
        $interface = 'alipay_mobile_public_'.$method.'_response';

        /* 遇到错误返回 */
        if( $menu_json[$interface]['code'] != 200 ){
            if( $this->debug ){
                $this->write_log('GET_MENU_ERROR',$menu_json[$interface]['msg']);
            }
            return false;
        }

        /* 根据类型不同返回不同的结果 */
        if( $type == 'get' ){
            return $menu_json[$interface]['menu_content'];
        }else{
            return $menu_json[$interface]['msg'];
        }

    }


    /**
     - POST数据方法
     - @param  array params 参数数组
     - @author widuu <admin@widuu.com>
     */

    private function response_post($params,$type=false){
        // 下载媒体和请求网关
        if($down){
            $url = 'https://openfile.alipay.com/chat/multimedia.do';
        }else{
            $url = 'https://openapi.alipay.com/gateway.do';
        }
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
        $curl = curl_exec($ch);
        curl_close($ch);
        return $curl;
    }

    /**
     - 拼接回复数据
     - @param   string $type  回复类型
     - @param   array  $info  回复内容
     - @param   bool   $mass  是否为群发
     - @author widuu <admin@widuu.com>
     */

    private function common_response($type,$info,$mass=false){
        $request = $this->request;
        $params = array();
        // 如果不是群发
        if( !$mass ) $params['toUserId'] = $request['FromUserId'];
        $params['msgType'] = $type;
        $params['createTime'] = time();
        $content = array_merge($params,$info);
        return $content;
    }

    /**
     - 拼接加密参数
     - @param   string $interface_type  接口类型
     - @param   array  $biz_content     返回biz_content的数组
     - @author widuu <admin@widuu.com>
     */


    private function common_system($interface_type,$biz_content){

        /* 接口集合 */
        $type = $this->interface_type;

        $method = $type[$interface_type];
        /* 公共参数 */
        $params = array (
            'method' => $method,
            'charset' => 'UTF-8',
            'sign_type' => 'RSA',
            'app_id' => $this->app_id,
            'timestamp' => date ( 'Y-m-d H:i:s', time () ),
            'version'=>'1.0',
        );

        /* 获取某些接口时没有biz_content参数 */
        if( count($biz_content) > 0 ){
            $params['biz_content'] = json_encode($biz_content);
        }

        /* 返回系统参数 */
        return $params;
    }

    /**
     - 服务验证
     - @params array params  是自动获的验证信息
     - @author widuu <admin@widuu.com>
     */

    private function verify($params){
        /* 参数为空 */
        if( empty($params) ){
            if( $this->debug ){
                $this->write_log('ERROR','验证参数为空');
            }
        }

        /* 构建参数,使用字典排序再拼接字符串 */
        $query_data = $this->build_query($params);

        /* 验证信息,有可能php版本BUG不支持验证 */
        $verify_result = $this->ras_verify($query_data);

        /* 返回验证结果 */
        if( $verify_result ){
            /* 取公有密钥的字符串合并为一行 */
            $public_rsa_string = file_get_contents($this->public_rsa_key_path);
            $public_rsa_string = str_replace ( "-----BEGIN PUBLIC KEY-----", "", $public_rsa_string );
            $public_rsa_string = str_replace ( "-----END PUBLIC KEY-----", "", $public_rsa_string );
            $public_rsa_string = str_replace ( "\r", "", $public_rsa_string );
            $public_rsa_string = str_replace ( "\n", "", $public_rsa_string );
            /* 构建加密字符串 */
            $response_xml = "<success>true</success><biz_content>$public_rsa_string</biz_content>";
            /* 生成验证信息 */
            $sign = $this->rsa_sign (  $response_xml );
            /* 构建返回数据 */
            $response = "<?xml version=\"1.0\" encoding=\"GBK\"?><alipay><response>$response_xml</response><sign>$sign</sign><sign_type>RSA</sign_type></alipay>";
            if( $this->debug ){
                $this->write_log('CHECK_RESPONSE',$response);
            }
            /* 输出返回信息 */
            echo $response;
            exit();
        }else{
            if( $this->debug ){
                $this->write_log('ERROR','验证失败');
            }
        }
    }

    /**
     - 拼接为字符串函数
     - @params array  params  拼接函数
     - @author widuu <admin@widuu.com>
     */

    private function build_query($params){
        /* 删除sign字符串 */
        unset($params['sign']);
        /* 字典排序 */
        ksort($params);
        /* 拼接 */
        $query_array = array();
        foreach ($params as $k => $v) {
            $query_array[] = "$k"."="."$v";
        }
        $query_data = implode("&", $query_array);
        /* 返回拼接好的字符串 */
        return $query_data;
    }

    /**
     - 验证加密sign,有些PHP版本不支持,不支持情况直接返回true
     - @params string query_data  加密字符串
     - @author widuu <admin@widuu.com>
     */

    private function ras_verify($query_data){
        /* 读取公钥文件,PEM格式 */
        $pubKey = file_get_contents($this->public_rsa_key_path);

        /* 转换为openssl格式密钥 */
        $res = openssl_get_publickey($pubKey);

        /* 调用openssl内置方法验签 */
        $result = (bool) openssl_verify($query_data, base64_decode($this->sign), $res);

        /* 释放资源 */
        openssl_free_key($res);

        /* 有些PHP版本错误,直接返回true */
        if( strpos( openssl_error_string(),'PEM_read_bio' ) ){ 
             return true;
        }
        /* 返回验签结果 */
        return $result;
    }

    /**
     - 通过私有密钥加密数据
     - @params string data  加密数据
     - @author widuu <admin@widuu.com>
     */

    private function rsa_sign($data) {
        /* 读取私钥 */
        $priKey = file_get_contents ( $this->private_rsa_key_path );

        /* 转换为openssl格式密钥 */
        $res = openssl_get_privatekey ( $priKey );

        /* 调用openssl 加密 */
        openssl_sign ( $data, $sign, $res );

        /* 释放资源 */
        openssl_free_key ( $res );

        /* Base64加密 */
        $sign = base64_encode ( $sign );

        /* 返回加密参数 */
        return $sign;
    }

    private function analysis($params){
        switch($params['MsgType']){
            case 'image':
                $this->media_id = $params['Image']['MediaId'];
                $this->format   = $params['Image']['Format'];
                break;
            case 'text':
                $this->text = $params['Text']['Content'];
                break;
            case 'event':
                $this->event_type   = $params['EventType'];
                $this->action_param = $params['ActionParam'];
                break;
            default:
                break;
        }

        $this->msg_type  = $params['MsgType'];
        $this->user_info = json_decode($params['UserInfo'],true);
    }

    /**
     - DEBUG 为true时的拼接字符串
     - @param   string  $level    自定义标识符
     - @param   string  $info     自定义内容
     - @param   string  $log_path 自定义日志路径
     - @author widuu <admin@widuu.com>
     */

    public function write_log($level,$info,$log_path = '' ){
        if( empty($log_path) ){
            $log_path = dirname ( __FILE__ ) . "/log.txt";
        }
        file_put_contents($log_path, "[$level]".date ( "Y-m-d H:i:s" ) . "  " . $info . "\r\n", FILE_APPEND );
    }
}

好了以上就是小编为各位整理的一篇关于支付宝服务窗API接口的开发例子,这个有前提条件的就是我们必须要申请一个权限才可以,这个官方可以申请小编就不介绍。

Magento保存不成功是什么原因呢,这个主要是post失败了对于post我们通常可以尝试检查配置问题了,具体的我们一起来看看小编整理的一篇关于Magento post提交数据保存不了的解决办法吧。


部分字段内容太多以致超出该字段在数据表中的限制

尝试修改该字段在数据表中的限制或者修改字段类型。以下是一些类型字段的长度限制:

TEXT – 64K
MEDIUMTEXT – 16M
LONGTEXT – 4G
 

post 数据的大小超出服务器限制

尝试通过修改 .htaccess 或者服务器设置,增加 php 的 post_max_size 值。

 

post 数据的数量超出服务器限制

尝试通过修改 .htaccess 或者服务器设置,增加 php 的 max_input_vars 值。

 

post 数据深度(层数)超出服务器限制

尝试通过修改 .htaccess 或者服务器设置,增加 php 的 max_input_nesting_level 值。

 

服务器安装了 Suhosin 系统导致部分 post 数据被过滤

尝试修改服务器过滤设置或者直接关闭 Suhosin 系统;
通过 file_get_contents(‘php://input’) 方法获取输入数据,并写程序处理这些数据以代替 $_POST

Magento 启用 Memcached 缓存方法比较简单了因为Magento自带了这个缓存了只需要简单的配置一下xml文档就可以了,具体的我们来看Magento 启用 Memcached 缓存的设置方法例子吧。


原生支持使用 Memcached 缓存,但是需要在配置文件中进行设置。

先不废话,上代码(app/etc/local.xml):

<global>
    ...
    <cache>
        <auto_refresh_fast_cache>true</auto_refresh_fast_cache>
        <backend>memcached</backend>
        <backend_options>
            <servers>
                <server>
                    <host>localhost</host>
                    <port>11211</port>
                    <persistent>true</persistent>
                    <weight>1</weight>
                    <timeout>1</timeout>
                    <retry_interval>15</retry_interval>
                </server>
            </servers>
        </backend_options>
    </cache>
    ...
</global>
 

Memcached 最吸引人的地方主要在于它的分布式,可以实现均衡负载,缓解瞬时访问量大的问题。既然是分布式,那么当然可以使用多个服务器,其中 servers 节点下边就可以添加多个 server 节点,以实现多服务器的配置。

如果在设置 Memcached 之前在后台启用过缓存,那么有可能在开启 Memcached 后访问站点会出现错误,这是默认的缓存格式跟 Memcached 不一样导致的。一般来说只需要把 var/cache 目录下的文件清空就可以解决这个问题。

虽然 Memcached 可以一定程度实现提高运行速度(因为它把缓存暂存到内存中),但它的主要功能还是分布式负载均衡。如果站点瞬时访问量不大,而且使用固态硬盘的话就没有必要使用 memcached 了。

今天我们一起来看一篇关于Magento新建组件控制器不生效或 404问题的解决办法,希望碰到此类问题的同学可以和小编一起来看看吧,具体的操作细节如下所示。

检查链接是否有错误

链接错误通常有两个可能,一个是拼写错误;另一个是后台开启了将 store view code 加在链接里,但测试的时候没有写到地址栏 – -

检查组件是否已打开

有的时候因为某些原因组件没有被开启,这样相关的控制器自然不可用了。可以到后台 System / Configuration > ADVANCED / Advanced 查找组件是否存在于列表中。

如果组件确实没有打开,一般都是配置文件或者程序的拼写问题导致的。特别是那种本地可用但放到服务器上出问题的,百分之七十都是因为大小写不正确 – -

检查组件的 config.xml 配置文件

以原生产品组件为例,前台控制器的配置方式如下:

<config>
    ...
    <frontend>
        <routers>
            <catalog>
                <use>standard</use>
                <args>
                    <module>Mage_Catalog</module>
                    <frontName>catalog</frontName>
                </args>
            </catalog>
        </routers>
    </frontend>
    ...
</config>

如果需要重写这个控制器,可以这样配置:

<config>
    ...
    <frontend>
        <routers>
            <catalog>
                <args>
                    <modules>
                        <Infinity_Catalog before="Mage_Catalog">Infinity_Catalog</Infinity_Catalog>
                    </modules>
                </args>
            </catalog>
        </routers>
    </frontend>
    ...
</config>
 

检查组件及控制器的文件名、类名、方法名

Magento 的组件目录有两个控制器相关的文件夹,一个是 Controller,另一个是 controllers。前者一般是用来定义路由方法的,似乎比较少用到;后者才是控制器安放的地方。与其他常用部件(Block、Helper、Model)不同,控制器文件夹的首字母是小写,且末尾有个 s(很想吐槽做架构那位是暗恋小s么,好吧我知道你 “小” 是因为重写方法跟 “大” 的不一样,“s” 是用来跟 Controller 作区分)。

控制器的文件名是


[控制器名(首字母大写)]Controller.php

比如原生产品前台控制器文件名为 ProductController.php。也是跟其他常用部件(Block、Helper、Model)不一样,后边带了个 Controller。

控制器的类名是


[命名空间(首字母大写)]_[组件名(首字母大写)]_[控制器名(首字母大写)]Controller
比如原生产品前台控制器类名为 Mage_Catalog_ProductController。还是跟其他常用部件(Block、Helper、Model)不一样,把 “Controller” 这个特征名词放到了类名末尾,而不是 [组件名] 之后。

行为的方法名是


[行为(首字母小写)]Action

且该方法必须是 public 的,一般不带参。比如原生前台产品详细页方法名这样定义的:public function viewAction()。


通过插入代码检查

一般来说通过以上几步就可以解决问题了,如果还是不行的话就要到以下两个方法中插入 log 代码,检查相关的模块、控制器、行为是否出了什么问题。

Mage_Core_Controller_Varien_Router_Standard::match
Mage_Core_Controller_Varien_Front::dispatch

标签:[!--infotagslink--]

您可能感兴趣的文章: