<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 微信功能
 *
 *
 */
class wechat_wang_model extends MY_Model
{
    /**
     * 初始化微信数据库和缓存使用
     *
     */
    public function __construct()
    {
        parent::__construct(1,1,0);
    }

    /**
     * 系统数据库对象
     *
     */
    public function getSystemObject()
    {
        $this->load->library('My_DB','','dbsystem');

        return $this->dbsystem->get_db_obj('dbsystem');
    }

    /**
     * 获取微信二维码信息
     *
     */
    public function get_wechat_info($conf_city = '')
    {
        $wechatDbObject = $this->getSystemObject();

        $result = array();

        $time = time();

        //超时期限15分钟
        $result['limit_date'] = 6;//6;

        //微信传图记录开始时间
        $result['time'] = $time;

        $parameter = "key=''&limit_date=".$limit_date."&start_date=".$time;

        $addData = array('key' => '','city' => $conf_city,'parameter' => $parameter,'add_date' => $time);

        //记录微信使用日志
        $wechatDbObject->insert('wechat_cache',$addData);

        //缓存关系表ID
        $result['wechat_cache_id'] = $wechatDbObject->insert_id();

        //微信传图缓存key
        //$result['wechat_cache_key'] = 'nuvbvq1472434918_imgUrl_qrscene_'.$result['wechat_cache_id'];
        $result['wechat_cache_key'] = 'nuvbvq1472434918_imgUrl_qrscene_'.$result['wechat_cache_id'];

        $expire = $result['limit_date']*60;

        //微信传图记录结束时间
        $result['last_time'] = $time+$expire;

        //南京微信二维码图片老接口
        //$result['wechat_image']='http://weixin.house365.com/index.php?g=Job&m=Qrcode&a=index&token=fskaqu1435124077&scene_id='. $result['wechat_cache_id'].'&expire='.$expire;

        //南京微信二维码图片接口
        //$result['wechat_image'] =  curl_get_contents('http://wx0024766e48094339.wx.weixinhouse365.com/index.php?g=Job&m=Qrcode&a=index&token=nuvbvq1472434918&scene_id='.$result['wechat_cache_id'].'&expire='.$expire.'&type=1');

        //$result['wechat_image'] = 'http://wx0024766e48094339.wx.weixinhouse365.com/index.php?g=Job&m=Qrcode&a=index&token=nuvbvq1472434918&scene_id='.$result['wechat_cache_id'].'&expire='.$expire;

        //$result['wechat_image'] = curl_get_contents('http://wx621fe7cb73692ef2.wx.weixinhouse365.com/index.php?g=Job&m=Qrcode&a=index&token=nuvbvq1472434918&scene_id='.$result['wechat_cache_id'].'&expire='.$expire.'&type=1');

		//echo 'http://wx0024766e48094339.wx.weixinhouse365.com/index.php?g=Job&m=Qrcode&a=index&token=nuvbvq1472434918&scene_id='.$result['wechat_cache_id'].'&expire='.$expire.'&type=1';die;

		$result['wechat_image'] = curl_get_contents('http://wx0024766e48094339.wx.weixinhouse365.com/index.php?g=Job&m=Qrcode&a=index&token=nuvbvq1472434918&scene_id='.$result['wechat_cache_id'].'&expire='.$expire.'&type=1');

        return $result;
    }
}
?>