public function getRightToken() { $customer_config = new Model_CustomerConfig(); $sql = "select customer_id,c_value,create_date from customer_config where customer_id='" . $this->customer_id . "' and c_type='token'"; $configinfo = $customer_config->fetchRow($sql); //token 有记录 if ($configinfo) { //token 未过期 if (strtotime($configinfo['create_date']) > time()) { $token = $configinfo['c_value']; //token 已经过期 } else { $token = $this->gettoken($customer_config); if ($token) { $configdata['c_value'] = $token; $configdata['create_date'] = date('Y-m-d H:i:s', time() + 1800); $customer_config->row_update($configdata, "customer_id='{$configinfo[customer_id]}' and c_type='token'"); } } } else { //没有记录 $token = $this->gettoken($customer_config); if ($token) { $configdata['customer_id'] = $this->customer_id; $configdata['c_type'] = "token"; $configdata['c_value'] = $token; $configdata['create_date'] = date('Y-m-d H:i:s', time() + 1800); $customer_config->insert($configdata); } } return $token; }
public function getLocation() { $i = 0; $push_num = 1; $infolbsModel = new Model_InfoLbs(); $filter['where'] = " customer_id='{$this->customer_id}' and state='1' and x_dian!='' "; $sql = $infolbsModel->select($filter); $inforesult = $infolbsModel->fetchAll($sql); $infocount = count($inforesult); for ($i = 0; $i < $infocount; $i++) { $inforesult[$i]['location_desc'] = strip_tags($inforesult[$i]['location_desc']); $short_intro = cut_str(strip_tags($inforesult[$i]['location_intro']), 120, $start = 0, $code = 'UTF-8'); $inforesult[$i]['location_desc'] = $inforesult[$i]['location_desc'] != '' ? $inforesult[$i]['location_desc'] : $short_intro; $inforesult[$i]['faraway'] = $this->get_distance($this->location_x, $this->location_y, $inforesult[$i]['x_dian'], $inforesult[$i]['y_dian']); } $newlocallist = multi_array_sort($inforesult, 'faraway', $sort = SORT_ASC); $customerconfigModel = new Model_CustomerConfig(); $filter['where'] = " customer_id='{$this->customer_id}' and c_type='lbs_push' "; $sql = $customerconfigModel->select($filter); $inforesult = $customerconfigModel->fetchRow($sql); if ($inforesult['c_value']) { $push_num = $inforesult['c_value']; } else { if ($i >= 2) { $push_num = 2; } } $push_num = $push_num <= $i ? $push_num : $i; for ($j = 0; $j < $push_num; $j++) { if ($j >= 10) { $push_num = 10; break; } $sql = "update info_lbs set push_num=push_num+1 where id='" . $newlocallist[$j]['id'] . "' limit 1"; $customerconfigModel->query($sql); $infolbsrecordModel = new Model_InfoLbsRecord(); $row['lbs_id'] = $newlocallist[$j]['id']; $row['customer_id'] = $this->customer_id; $row['fromuser'] = $this->fromuser; $row['fromwhere'] = $this->fromwhere; $row['ip'] = $_WGT['IP']; $row['create_date'] = date("Y-m-d H:i:s"); $infolbsrecordModel->insert($row); $url = 'http://' . $_SERVER['HTTP_HOST'] . "/mobile/info.php?t=location&id=" . $newlocallist[$j]['id']; $itemlist .= "<item>\n\t\t <Title><![CDATA[[" . $newlocallist[$j]['faraway'] . "公里]" . $newlocallist[$j]['location_name'] . "]]></Title>\n\t\t <Description><![CDATA[" . $newlocallist[$j]['location_desc'] . "]]></Description>\n\t\t <PicUrl><![CDATA[http://" . $_SERVER['HTTP_HOST'] . "/data/image_c/" . $newlocallist[$j]['location_pic'] . "]]></PicUrl>\n\t\t <Url><![CDATA[{$url}]]></Url>\n\t\t </item>"; } if ($i > 0) { $Bodystr = "\n\t\t\t <ArticleCount>{$push_num}</ArticleCount>\n\t\t\t <Articles>\n\t\t\t {$itemlist}\n\t\t\t </Articles>"; $data['msgtype'] = 'news'; $data['bodystr'] = $Bodystr; return $data; } }
<?php include_once "../../includes/config.inc.php"; include_once "../../includes/login_check.php"; $customer_id = (int) $_SESSION['customer_id']; $customerconfigModel = new Model_CustomerConfig(); $filter['where'] = " customer_id='{$customer_id}' and c_type='appid' "; $sql = $customerconfigModel->select($filter, 'c_value'); $value_str = $customerconfigModel->fetchRow($sql); $value_array = explode(',', $value_str['c_value']); $smarty->assign('value_array', $value_array); $smarty->setTpl('info/templates/auth.html')->display();
public function getMeminfo($fromuser) { $customer_config = new Model_CustomerConfig(); $sql = "select customer_id,c_value,create_date from customer_config where customer_id='" . $this->customer_id . "' and c_type='token'"; $configinfo = $customer_config->fetchRow($sql); //获取access_token if ($configinfo) { if (strtotime($configinfo['create_date']) > time()) { //token未过期 $token = $configinfo['c_value']; } else { //token已经过期 $token = $this->gettoken($customer_config); if ($token) { $configdata['c_value'] = $token; $configdata['create_date'] = date('Y-m-d H:i:s', time() + 3600); $customer_config->row_update($configdata, "customer_id='{$configinfo[customer_id]}' and c_type='token'"); } } } else { //没有记录 $token = $this->gettoken($customer_config); if ($token) { $configdata['customer_id'] = $this->customer_id; $configdata['c_type'] = "token"; $configdata['c_value'] = $token; $configdata['create_date'] = date('Y-m-d H:i:s', time() + 3600); $customer_config->insert($configdata); } } //获取详细信息 $rowMem2 = array(); if ($token) { $memberjson = file_get_contents("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $token . "&openid=" . $fromuser . "&lang=zh_CN"); $meminfo = json_decode($memberjson); if ($meminfo->nickname) { $rowMem2['nickname'] = $meminfo->nickname; $rowMem2['sex'] = $meminfo->sex; $rowMem2['language'] = $meminfo->language; $rowMem2['city'] = $meminfo->city; $rowMem2['province'] = $meminfo->province; $rowMem2['country'] = $meminfo->country; $rowMem2['headimgurl'] = $meminfo->headimgurl; return $rowMem2; } } return $rowMem2; }