/** * 登录 */ public function index() { if (IS_POST) { $account = trim($_POST['account']); $pwd = $_POST['pwd']; if (empty($account) || empty($pwd)) { $this->error('请输入账号密码'); exit; } if ($account && $pwd) { if (is_numeric($account)) { $s_where['mobile'] = $account; } else { $s_where['email'] = $account; } $m_info = $this->model->where($s_where)->find(); if (is_array($m_info) && !empty($m_info)) { if ($m_info['pwd'] != re_md5($pwd)) { $this->error("登录密码错误!"); exit; } if ($m_info['member_status'] == 0) { $this->error('账户被冻结,请联系管理员.'); die; } session('member_id', $m_info['member_id']); $login_referer_url = session('login_referer'); session('login_referer', null); $domain = get_host_domain($login_referer_url); if ($domain == $_SERVER['SERVER_NAME']) { $this->success("登录成功!", $login_referer_url); } else { $this->success("登录成功!", U('Member/index')); } exit; } else { $this->error("不存在此用户!"); exit; } } } elseif (IS_GET) { $this->check_login(); session('login_referer', $_SERVER['HTTP_REFERER']); $this->display(); } }
/** * 获取淘宝或者天猫商品信息 * @param string $url 商品地址 * @return Ambigous <unknown, string> */ function get_taobao_info($url) { header("Content-Type: text/html; charset=utf-8"); $domain = get_host_domain($url); $text = file_get_contents($url); if ($domain == 'taobao.com') { //商品id preg_match('/itemId[\\s]:[\\s]\'(.*)\',/', $text, $itemId); $info['itemId'] = $itemId[1]; //商品名称(主标题) preg_match('/<h3[^>]class="tb-main-title"[^>]data-title=\\"([^<>]*)\\">/', $text, $maintitle); $info['title'] = iconv('GBK', 'UTF-8', $maintitle[1]); //商品备注(子标题) preg_match('/<p[^>]*class="tb-subtitle">([^<>]*)<\\/p>/', $text, $subtitle); $info['subtitle'] = iconv('GBK', 'UTF-8', $subtitle[1]); //主图 preg_match('/<img[^>]*id="J_ImgBooth"[^r]*rc=\\"([^"]*)\\"[^>]*>/', $text, $img); $info['img'] = $img[1]; //小图 preg_match_all('/<img[^>]data-src=\\"([^"]*)\\"[^>]*>/', $text, $small_img, PREG_SET_ORDER); $pic_suffix = array('jpg', 'png', 'jpeg'); foreach ($small_img as $key => $val) { //整理图片像素 foreach ($pic_suffix as $suffix => $v) { if (strpos($val[1], '.' . $v . '_')) { $info['small_img'][$key] = substr($val[1], 0, strpos($val[1], '.' . $v . '_')) . '.' . $v; if (strlen($info['small_img'][$key]) <= 10) { $info['small_img'][$key] = $val[1]; } } } } //店铺名 preg_match('/<div[^>]*class="tb-shop-name">[^<]*<dl>[^<]*<dd>[^<]*<strong>[^<]*<a[^>]*href="[^>]*"[^>]*title=\\"([^<>"]*)\\"/', $text, $shop_name); $info['shop_name'] = iconv('GBK', 'UTF-8', $shop_name[1]); //卖家掌柜 preg_match('/sellerNick :[\\s]\'(.*)\',/', $text, $sellerNick); $info['seller'] = iconv('GBK', 'UTF-8', $sellerNick[1]); //价格 preg_match('/<em class="tb-rmb-num">([^<>]*)<\\/em>/', $text, $price); $info['price'] = $price[1]; //聚划算 if (empty($info['title'])) { //商品id preg_match('/<input[^>]*type="hidden"[^>]*id="itemId"[^>]*value=\\"([^"]*)\\"\\/>/', $text, $itemId); $info['itemId'] = $itemId[1]; //商品名称(主标题) preg_match('/<h2[^>]*class="title">([^<>]*)<\\/h2>/', $text, $maintitle); $info['title'] = trim(iconv('GBK', 'UTF-8', $maintitle[1])); //商品备注(子标题) preg_match_all('/<li>([^<>]*)<\\/li>/', $text, $subtitle, PREG_SET_ORDER); $info['subtitle'] = iconv('GBK', 'UTF-8', $subtitle[1]); //主图 preg_match('/<img[^>]*src="[^"]*"[^"]*data-ks-imagezoom=\\"([^"]*)\\"[^>]*class="J_zoom "\\/>/', $text, $img); $info['img'] = $img[1]; //小图 preg_match_all('/<span[^>]*class="triangle"><\\/span>[^<]*<img[^>]src="[^"]*"[^>]data-normal="[^"]*"[^>]data-big=\\"([^"]*)\\"[^>]*\\/>/', $text, $small_img, PREG_SET_ORDER); $pic_suffix = array('jpg', 'png', 'jpeg'); foreach ($small_img as $key => $val) { //整理图片像素 foreach ($pic_suffix as $suffix => $v) { if (strpos($val[1], '.' . $v . '_')) { $info['small_img'][$key] = substr($val[1], 0, strpos($val[1], '.' . $v . '_')) . '.' . $v; if (strlen($info['small_img'][$key]) <= 10) { $info['small_img'][$key] = $val[1]; } } } } //卖家掌柜 preg_match('/<a[^>]*class="sellername"[^>]*href="[^"]*"[^>]*target="_blank">([^<>]*)<\\/a>/', $text, $sellerNick); $info['shop_name'] = iconv('GBK', 'UTF-8', $sellerNick[1]); //价格 preg_match('/<\\/small>([^<>]*)<\\/div>/', $text, $price); $info['price'] = trim($price[1]); } } elseif ($domain == 'tmall.com') { //商品名称(主标题) //preg_match('/<h1[^>]*data-spm="1000983">([^<>]*)<\/h1>/', $text, $maintitle); preg_match('/<input[^>]*type="hidden"[^>]*name="title"[^>]*value=\\"([^"]*)\\"[^>]*>/', $text, $maintitle); $info['title'] = trim(iconv('GBK', 'UTF-8', $maintitle[1])); //商品备注(子标题) preg_match('/<p>([^<>]*)<\\/p>/', $text, $subtitle); $info['subtitle'] = trim(iconv('GBK', 'UTF-8', $subtitle[1])); //主图 preg_match('/<img[^>]*id="J_ImgBooth"[^r]*rc=\\"([^"]*)\\"[^>]*>/', $text, $img); $info['img'] = $img[1]; //小图 preg_match_all('/<a href="#"><img[^>]src=\\"([^"]*)\\"[^>]*>/', $text, $small_img, PREG_SET_ORDER); $pic_suffix = array('jpg', 'png', 'jpeg'); foreach ($small_img as $key => $val) { //整理图片像素 foreach ($pic_suffix as $suffix => $v) { if (strpos($val[1], '.' . $v . '_')) { $info['small_img'][$key] = substr($val[1], 0, strpos($val[1], '.' . $v . '_')) . '.' . $v; if (strlen($info['small_img'][$key]) <= 10) { $info['small_img'][$key] = $val[1]; } } } } //店铺名 preg_match('/<a[^>]*class="slogo-shopname"[^>]*>[^<]*<strong>([^<>"]*)<\\/strong>/', $text, $shop_name); $info['shop_name'] = iconv('GBK', 'UTF-8', $shop_name[1]); } return $info; }