微信web置顶功能

WEB微信扫码登陆后置顶

    // 获取微信登陆2微码图片
    public function wx_web_img()
    {
        // 获取UUID
        $res = srv_weixin_index::I()->urllib_get('https://login.wx2.qq.com/jslogin?appid=wx782c26e4c19acffb&redirect_uri=https%3A%2F%2Fwx2.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage&fun=new&lang=zh_CN&_=1484199765594', $json=false);
        $explode = (explode(';', $res));
        $uuid    = str_replace(' window.QRLogin.uuid = ', '', $explode[1]); $uuid    = str_replace('"', '', $uuid);

        // 根据UUID获取登陆2微码
        $img = sprintf('https://login.weixin.qq.com/qrcode/%s', $uuid);
        $this->_success($echo_exit = true, $msg = '获取成功', $data = array('uuid' => $uuid, 'img' => $img));
    }

    /*
     * 循环获取状态
     * 返回window.code=408;则继续循环
     * 返回window.code=400;则重新获取二维码
     * 返回window.code=201;则表示手机扫描了二维码,等待手机点击“登录”
     * 返回window.code=200;则手机已经按了"登录“
     */
    public function loop_get_status(){
        $uuid=$_GET['uuid'];
        $img_get = sprintf('http://login.wx2.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&uuid=%s&tip=0&r=-600643520&_=%s', $uuid, time());
        $res = srv_weixin_index::I()->urllib_get($img_get, $json=false);
        $search = array(" "," ","\n","\r","\t");
        $replace = array("","","","","");
        $str=str_replace($search, $replace, $res);
        if (preg_match('/window.code=200/',$str) == 1){
            preg_match('/(https:\/\/.*?)\"\;/', $str, $match);
            $res=srv_weixin_index::I()->set_wx_web_login($this->_uid(), $match[1]);
            $this->_success($echo_exit = true, $msg = '可以登陆了', $data = array('url' => $match[1]));
        }
        if (preg_match('/window.code=408/',$str) == 1){
            $this->_failed($msg = '继续循环.', $result = 408, $data = null);
        }
        if (preg_match('/window.code=400/',$str) == 1){
            $this->_failed($msg = '重新获取二维码.', $result = 400, $data = null);
        }
        if (preg_match('/window.code=201/',$str) == 1){
            preg_match('/(data.*?)\';/', $str, $matchs);
            $this->_failed($msg = '手机扫描了二维码,等待手机点击“登录”', $result = 201, $data = array('url' => $matchs[1]));
        }
    }

    // 微信置顶功能
    public function stick(){
        // 获取微信参数
        $param=srv_weixin_index::I()->get_wx_web_login($this->_uid());
        $url_tp='https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxoplog?lang=zh_CN&pass_ticket=%s';
        $url=sprintf($url_tp, $param->pass_ticket);
        $data_tp='{"UserName":"hrloo_com","CmdId":3,"OP":0,"BaseRequest":{"Uin":%s,"Sid":"%s","Skey":"%s","DeviceID":"e040374362029945"}}';
        $data=sprintf($data_tp, $param->wxuin, $param->wxsid, $param->skey);
        $res=srv_weixin_index::I()->urllib_post($url, $data, $header = true);
        print_r($res);
    }