<?php
/** wap
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaogg <xiaogg@sina.cn>
 */

namespace Home\Controller;
class WeixinController extends BaseController {
    public function _initialize() {
		parent::_initialize ();
	}
    public function index(){
        $weixin = new \Common\Vendor\WeixinChat;
        $data=$weixin->request();
        if($data){
           $weixinresponse=new \Common\Vendor\Weixinresponse;
           $backdata=$weixinresponse->reply($data);
           if($backdata['type'] && $backdata['content'])$weixin->response($backdata['content'],$backdata['type']);
        }
    }
    public function jump(){
        $id=I('id');
        $openid=I('openid','','openid_decode');
        if(!empty($openid)){session('openid',$openid);cookie('openid',$openid);}
        $info=M('WxNews')->where('id='.$id)->field(true)->find();
        if(!empty($info['jump_url'])){
            $url=geturl($info['jump_url']);
            redirect($url);
        }else{
            $this->assign($info);
            $this->display('Public/weixin');
        }
    }
}