分享

!免费修复小猪pigcms微信自定义菜单操作失败,35:错误号:35,未知错误补丁

 看见就非常 2015-10-21

小猪pigcmg微信自定义菜单操作失败,35:错误号:35,未知错误补丁,西瓜君个人博客亲测完美解决小猪微信平台自定义菜单35:错误号问题。查了一下度娘,都是tmd的收费的补丁,小编感觉至于吗?这也要收费,西瓜君果断免费共享小猪pigcmg微信自定义菜单错误解决方法
  
  说明:此补丁针对,小猪微信pigcms公众平台最新加盟版7.1.X-8.1版本平台等自定义菜单发布时提示:操作失败,35:错误号:35,未知错误

使用方法:找到程序根目录 PigCms\Lib\Action\User ,将下面的补丁文件代码覆盖DiymenAction.class.php 即可。

注意:覆盖前请先备份原始文件(虽然西瓜君提供的补丁亲测好用,但是一定要养成良好的开发备份习惯^-^

特别鸣谢:如果好用,请给予留言支持,让更多需要此补丁的童鞋放心免费使用,避免花冤枉钱。-------------西瓜君博客敬上

<?php
/**
 * des      :小猪pigcmg微信菜单操作失败,35:错误号:35,未知错误修复补丁
 * author   :西瓜君个人博客
 * website  :blog.xiguajun.com
 * time     :2015-03-12 15:02:06
 */
class DiymenAction extends UserAction {
    public $thisWxUser;
    public function _initialize() {
        parent::_initialize();
        $where = array('token' => $this->token);
        $this->thisWxUser = M('Wxuser')->where($where)->find();
        if (!$this->thisWxUser['appid'] || !$this->thisWxUser['appsecret']) {
            $diyApiConfig = M('Diymen_set')->where($where)->find();
            if (!$diyApiConfig['appid'] || !$diyApiConfig['appsecret']) {
                $this->error('请先设置AppID和AppSecret再使用本功能,谢谢', '?g=User&m=Index&a=edit&id=' . $this->thisWxUser['id']);
            } else {
                $this->thisWxUser['appid'] = $diyApiConfig['appid'];
                $this->thisWxUser['appsecret'] = $diyApiConfig['appsecret'];
            }
        }
    }
    //自定义菜单配置
    public function index() {
        $data = M('Diymen_set')->where(array('token' => $_SESSION['token']))->find();
        $this->assign('diymen', $data);
        if (IS_POST) {
            $_POST['token'] = $_SESSION['token'];
            if ($data == false) {
                $this->all_insert('Diymen_set');
            } else {
                $_POST['id'] = $data['id'];
                $this->all_save('Diymen_set');
            }
            M('Wxuser')->where(array('token' => $this->token))->save(array('appid' => trim($this->_post('appid')), 'appsecret' => trim($this->_post('appsecret'))));
        } else {
            $class = M('Diymen_class')->where(array('token' => session('token'), 'pid' => 0))->order('sort desc')->select(); //dump($class);
            foreach ($class as $key => $vo) {
                $c = M('Diymen_class')->where(array('token' => session('token'), 'pid' => $vo['id']))->order('sort desc')->select();
                $class[$key]['class'] = $c;
            }
            $this->assign('class', $class);
            $this->display();
        }
    }
    public function class_add() {
        if (IS_POST) {
            $_POST['url'] = $this->checkUrl($_POST['url']);
            $this->all_insert('Diymen_class', '/index');
        } else {
            $class = M('Diymen_class')->where(array('token' => session('token'), 'pid' => 0))->order('sort desc')->select();
            $this->assign('class', $class);
            $this->assign('wxsys', $this->_get_sys());
            $this->display();
        }
    }
    public function class_del() {
        $class = M('Diymen_class')->where(array('token' => session('token'), 'pid' => $this->_get('id')))->order('sort desc')->find();
        //echo M('Diymen_class')->getLastSql();exit;
        if ($class == false) {
            $back = M('Diymen_class')->where(array('token' => session('token'), 'id' => $this->_get('id')))->delete();
            if ($back == true) {
                $this->success('删除成功');
            } else {
                $this->error('删除失败');
            }
        } else {
            $this->error('请删除该分类下的子分类');
        }
    }
    public function class_edit() {
        $this->assign('wxsys', $this->_get_sys());
        if (IS_POST) {
            $_POST['id'] = $this->_get('id');
            $_POST['url'] = $this->checkUrl($_POST['url']);
            $this->all_save('Diymen_class', '/index?id=' . $this->_get('id'));
        } else {
            $data = M('Diymen_class')->where(array('token' => session('token'), 'id' => $this->_get('id')))->find();
            if ($data == false) {
                $this->error('您所操作的数据对象不存在!');
            } else {
                $class = M('Diymen_class')->where(array('token' => session('token'), 'pid' => 0))->order('sort desc')->select(); //dump($class);
                $this->assign('class', $class);
                $this->assign('show', $data);
            }
            $this->display();
        }
    }
    function _get_sys($type = '', $key = '') {
        $wxsys = array(
            '扫码带提示',
            '扫码推事件',
            '系统拍照发图',
            '拍照或者相册发图',
            '微信相册发图',
            '发送位置',
        );
        if ($type == 'send') {
            $wxsys = array(
                '扫码带提示' => 'scancode_waitmsg',
                '扫码推事件' => 'scancode_push',
                '系统拍照发图' => 'pic_sysphoto',
                '拍照或者相册发图' => 'pic_photo_or_album',
                '微信相册发图' => 'pic_weixin',
                '发送位置' => 'location_select',
            );
            return $wxsys[$key];
            exit;
        }
        return $wxsys;
    }
    private function unicode2utf8_2($str) { // 关于unicode编码转化的第二个函数,用于显示emoji表情
        $str = '{"result_str":"' . $str . '"}'; // 组合成json格式
        $strarray = json_decode($str, true); // json转换为数组,利用 JSON 对 \uXXXX 的支持来把转义符恢复为 Unicode 字符(by 梁海)
        return $strarray['result_str'];
    }
    public function class_send() {
        if (IS_GET) {
            //dump($api);
            $url_get = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $this->thisWxUser['appid'] . '&secret=' . $this->thisWxUser['appsecret'];
            $json = json_decode($this->curlGet($url_get));
            if (!$json->errmsg) {
                //return array('rt'=>true,'errorno'=>0);
            } else {
                $this->error('获取access_token发生错误:错误代码' . $json->errcode . ',微信返回错误信息:' . $json->errmsg);
            }
            $data = '{"button":[';
            $class = M('Diymen_class')->where(array('token' => session('token'), 'pid' => 0, 'is_show' => 1))->limit(3)->order('sort desc')->select(); //dump($class);
            $kcount = M('Diymen_class')->where(array('token' => session('token'), 'pid' => 0, 'is_show' => 1))->limit(3)->order('sort desc')->count();
            $k = 1;
            foreach ($class as $key => $vo) {
                //主菜单
                if ($vo['emoji_code'] != '') {
                    $vo['title'] = $this->unicode2utf8_2('\u' . $vo['emoji_code']) . $vo['title'];
                }
                $data.='{"name":"' . $vo['title'] . '",';
                $c = M('Diymen_class')->where(array('token' => session('token'), 'pid' => $vo['id'], 'is_show' => 1))->limit(5)->order('sort desc')->select();
                $count = M('Diymen_class')->where(array('token' => session('token'), 'pid' => $vo['id'], 'is_show' => 1))->limit(5)->order('sort desc')->count();
                //子菜单
                $vo['url'] = str_replace(array('{siteUrl}', '&', '&wecha_id={wechat_id}'), array($this->siteUrl, '&', '&diymenu=1'), $vo['url']);
                if ($c != false) {
                    $data.='"sub_button":[';
                } else {
                    if ($vo['keyword']) {
                        $data.='"type":"click","key":"' . $vo['keyword'] . '"';
                    } else if ($vo['url']) {
                        $data.='"type":"view","url":"' . $vo['url'] . '"';
                    } else if ($vo['wxsys']) {
                        $data.='"type":"' . $this->_get_sys('send', $vo['wxsys']) . '","key":"' . $vo['wxsys'] . '"';
                    }
                }
                $i = 1;
                foreach ($c as $voo) {
                    if ($voo['emoji_code'] != '') {
                        $voo['title'] = $this->unicode2utf8_2('\u' . $voo['emoji_code']) . $voo['title'];
                    }
                    $voo['url'] = str_replace(array('{siteUrl}', '&', '&wecha_id={wechat_id}'), array($this->siteUrl, '&', '&diymenu=1'), $voo['url']);
                    if ($i == $count) {
                        if ($voo['keyword']) {
                            $data.='{"type":"click","name":"' . $voo['title'] . '","key":"' . $voo['keyword'] . '"}';
                        } else if ($voo['url']) {
                            $data.='{"type":"view","name":"' . $voo['title'] . '","url":"' . $voo['url'] . '"}';
                        } else if ($voo['wxsys']) {
                            $data.='{"type":"' . $this->_get_sys('send', $voo['wxsys']) . '","name":"' . $voo['title'] . '","key":"' . $voo['wxsys'] . '"}';
                        }
                    } else {
                        if ($voo['keyword']) {
                            $data.='{"type":"click","name":"' . $voo['title'] . '","key":"' . $voo['keyword'] . '"},';
                        } else if ($voo['url']) {
                            $data.='{"type":"view","name":"' . $voo['title'] . '","url":"' . $voo['url'] . '"},';
                        } else if ($voo['wxsys']) {
                            $data.='{"type":"' . $this->_get_sys('send', $voo['wxsys']) . '","name":"' . $voo['title'] . '","key":"' . $voo['wxsys'] . '"},';
                        }
                    }
                    $i++;
                }
                if ($c != false) {
                    $data.=']';
                }
                if ($k == $kcount) {
                    $data.='}';
                } else {
                    $data.='},';
                }
                $k++;
            }
            $data.=']}';
            file_get_contents('https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=' . $json->access_token);
            $url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=' . $json->access_token;
            $rt = $this->api_notice_increment($url, $data);
            if ($rt['rt'] == false) {
                $errmsg = GetErrorMsg::wx_error_msg($rt['errorno']);
                $this->error('操作失败,' . $rt['errorno'] . ':' . $errmsg);
            } else {
                $this->success('操作成功');
            }
            exit;
        } else {
            $this->error('非法操作');
        }
    }
    function api_notice_increment($url, $data) {
        $ch = curl_init();
        $header = "Accept-Charset: utf-8";
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $tmpInfo = curl_exec($ch);
        $errorno = curl_errno($ch);
        if ($errorno) {
            return array('rt' => false, 'errorno' => $errorno);
        } else {
            $js = json_decode($tmpInfo, 1);
            if ($js['errcode'] == '0') {
                return array('rt' => true, 'errorno' => 0);
            } else {
                $errmsg = GetErrorMsg::wx_error_msg($js['errcode']);
                $this->error('发生错误:错误代码' . $js['errcode'] . ',微信返回错误信息:' . $errmsg);
            }
        }
    }
    function curlGet($url) {
        $ch = curl_init();
        $header = "Accept-Charset: utf-8";
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $temp = curl_exec($ch);
        return $temp;
    }
    protected function checkUrl($url) {
        if (strpos($url, "wecha_id") !== false) {
            if (strpos($url, "{wechat_id}") === false) {
                $this->error('链接中设置的wecha_id ,不合法请从功能库选择链接');
            }
        }
        return $url;
    }
}
?>

如有疑问请联系西瓜君或者留言,我会第一时间进行处理。您的留言支持,是西瓜君最大的分享动力,

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多