api/common/interface.func.php | ●●●●● patch | view | raw | blame | history | |
api/init_db.php | ●●●●● patch | view | raw | blame | history | |
api/userApi.php | ●●●●● patch | view | raw | blame | history | |
data/config.php | ●●●●● patch | view | raw | blame | history | |
includes/cls_mysql.php | ●●●●● patch | view | raw | blame | history |
api/common/interface.func.php
@@ -28,13 +28,14 @@ $retData = array(); $sysKey = $systemId[substr($param["id"],0,7)]; if ($sysKey == null){ $retData["regMsg"] = "e00001"; $retData["rspCode"] = "e00001"; } else { if (checkSign($param,$sysKey)){ $retData["regMsg"] = "e00000"; $retData["regData"] = json_decode($param["data"],true); $retData["rspCode"] = "e00000"; $retData["repData"] = json_decode($param["data"],true); } else { $retData["regMsg"] = "e00002"; $retData["rspCode"] = "e00002"; } } return $retData; @@ -49,7 +50,7 @@ foreach ($data as $key => $value) { if ($key != "sign") { $str = $str.$key."=".str_replace("\\", "", $value)."&"; $str = $str.$key."=".$value."&"; } } return $data["sign"] == md5($str."key=".$sysKey); @@ -106,67 +107,19 @@ return $str; } /** * 生成openId * @param $appId * @return openId */ function getOpenId($appId) { return $appId.date("Ymd").getRandomNumber(9); } /** *封闭curl的调用接口,get的请求方式。 */ function doCurlGetRequest($url,$data,$timeout = 5){ if($url == "" || $timeout <= 0){ return false; } $url = $url.'?'.http_build_query($data); $con = curl_init((string)$url); curl_setopt($con, CURLOPT_HEADER, false); curl_setopt($con, CURLOPT_RETURNTRANSFER,true); curl_setopt($con, CURLOPT_TIMEOUT, (int)$timeout); return curl_exec($con); } /** ** @desc 封装 curl 的调用接口,post的请求方式 **/ function doCurlPostRequest($url,$requestString,$timeout = 5){ if($url == '' || $requestString == '' || $timeout <=0){ return false; } $con = curl_init((string)$url); curl_setopt($con, CURLOPT_HEADER, false); curl_setopt($con, CURLOPT_POSTFIELDS, $requestString); curl_setopt($con, CURLOPT_POST,true); curl_setopt($con, CURLOPT_RETURNTRANSFER,true); curl_setopt($con, CURLOPT_TIMEOUT,(int)$timeout); $data = curl_exec($con); if (curl_errno($url)) { return curl_error($url); } else { curl_close($url); return $data; } } /** * 指定key删除数组中指定的元素 * @param unknown $data * @param unknown $key * @return unknown */ function array_remove($data, $key){ if(!array_key_exists($key, $data)){ return $data; } $keys = array_keys($data); $index = array_search($key, $keys); if($index !== FALSE){ array_splice($data, $index, 1); } return $data; } function send_post($url, $post_data) { $postdata = http_build_query($post_data); $options = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type:application/x-www-form-urlencoded', 'content' => $postdata, 'timeout' => 15 * 60 ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); return $result; } api/init_db.php
New file @@ -0,0 +1,13 @@ <?php error_reporting(E_ALL); /* 初始化数据库类 */ require('../data/config.php'); require('../includes/cls_mysql.php'); require('../includes/cls_session.php'); $db = new cls_mysql($db_host, $db_user, $db_pass, $db_name); $db_host = $db_user = $db_pass = $db_name = NULL; ?> api/userApi.php
New file @@ -0,0 +1,62 @@ <?php /** * 获取用户数据相关 Api * 王腾宇 */ define('IN_ECS', true); require('./init_db.php'); require('./common/interface.func.php'); if($_SERVER['REQUEST_METHOD'] != 'POST'){ http_response_code(405); } else { $retData=checkParam($_GET); switch ($retData["rspCode"]){ case "e00000": $userApi = new UserApi(); try { switch (getUrl($_SERVER['REQUEST_URI'])) { case "getUserList": $retData["rspData"] = $userApi->getUserList($retData["repData"]); break; case "getUserOrderList": $retData["rspData"] = $userApi->getUserOrderList($retData["repData"]); break; default: http_response_code(404); } } catch (Exception $e){ $retData["rspCode"] = "e99999"; $retData["rspData"] = $e->getMessage(); } break; case "e00001": $retData["rspMsg"]="接入平台不存在"; break; case "e00002": $retData["rspMsg"]="鉴权失败"; break; } exit(json_encode($retData,JSON_UNESCAPED_UNICODE)); } class UserApi { function _initialize() {} public function getUserList($param) { global $db; return $db->getAll("SELECT * from ecs_users where invitation_code="."'".$param["invitationCode"]."'"); } public function getUserOrderList($param) { global $db; return $db->getAll("select *,(select user_name from ecs_users where i.user_id = user_id) as user_name from ecs_order_info i left join ecs_order_goods g on i.order_id = g.order_id where i.user_id in (select ecs_users.user_id from ecs_users where invitation_code="."'".$param["invitationCode"]."')"); } } data/config.php
@@ -1,15 +1,15 @@ <?php // database host $db_host = "localhost:3306"; $db_host = "122.114.239.145:3306"; // database name $db_name = "new-mall"; $db_name = "ec_shop"; // database username $db_user = "root"; $db_user = "jiuding"; // database password $db_pass = "123456"; $db_pass = "jiuding@iemsoft"; // table prefix $prefix = "ecs_"; includes/cls_mysql.php
@@ -150,13 +150,13 @@ } if ($this->platform == 'OTHER' && ($dbhost != '.' && strtolower($dbhost) != 'localhost:3306' && $dbhost != '127.0.0.1:3306') || ($dbhost != '.' && strtolower($dbhost) != '122.114.239.145:3306' && $dbhost != '127.0.0.1:3306') || (PHP_VERSION >= '5.1' && date_default_timezone_get() == 'UTC')) { $result = mysql_query("SELECT UNIX_TIMESTAMP() AS timeline, UNIX_TIMESTAMP('" . date('Y-m-d H:i:s', $this->starttime) . "') AS timezone", $this->link_id); $row = mysql_fetch_assoc($result); if ($dbhost != '.' && strtolower($dbhost) != 'localhost:3306' && $dbhost != '127.0.0.1:3306') if ($dbhost != '.' && strtolower($dbhost) != '122.114.239.145:3306' && $dbhost != '127.0.0.1:3306') { $this->timeline = $this->starttime - $row['timeline']; }