Merge branch 'master' of http://122.114.239.145:7070/r/php/iem_shop
2 files added
4 files modified
New file |
| | |
| | | <?php |
| | | |
| | | |
| | | /** |
| | | * 对外接口工具类 Api |
| | | * 王腾宇 |
| | | */ |
| | | |
| | | // 1000001 微擎 |
| | | // 1000002 商城 |
| | | // 1000003 管理系统 |
| | | static $systemId = array( |
| | | "1000001"=>"3a03c2e6f2f911e8b9245254009bf9ba", |
| | | "1000002"=>"466a50d8f2f911e8b9245254009bf9ba", |
| | | "1000003"=>"53cfae5df2f911e8b9245254009bf9ba", |
| | | ); |
| | | |
| | | |
| | | /** |
| | | * 接口数据校验 |
| | | * e00000 检验成功 |
| | | * e00001 接入平台不存在 |
| | | * e00002 鉴权失败 |
| | | */ |
| | | function checkParam ($param) |
| | | { |
| | | global $systemId; |
| | | $retData = array(); |
| | | $sysKey = $systemId[substr($param["id"],0,7)]; |
| | | if ($sysKey == null){ |
| | | $retData["regMsg"] = "e00001"; |
| | | } else { |
| | | if (checkSign($param,$sysKey)){ |
| | | $retData["regMsg"] = "e00000"; |
| | | $retData["regData"] = json_decode($param["data"],true); |
| | | } else { |
| | | $retData["regMsg"] = "e00002"; |
| | | } |
| | | } |
| | | return $retData; |
| | | } |
| | | |
| | | /** |
| | | * 校验签名 |
| | | */ |
| | | function checkSign($data,$sysKey) |
| | | { |
| | | $str = ""; |
| | | foreach ($data as $key => $value) |
| | | { |
| | | if ($key != "sign") { |
| | | $str = $str.$key."=".str_replace("\\", "", $value)."&"; |
| | | } |
| | | } |
| | | return $data["sign"] == md5($str."key=".$sysKey); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 解析请求接口地址 |
| | | */ |
| | | function getUrl($url) |
| | | { |
| | | $arr = explode('/', $url); |
| | | return substr($arr[count($arr)-1],0,strpos($arr[count($arr)-1], '?')); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 生成对外接口字符串 |
| | | * 例子: id=100000120181128223494512&data=%7B%22code%22%3A%221%22%2C%22id%22%3A%22100000120181128223494512%22%7D&sign=a59336edda9fd6785fac6720d02c7d61 |
| | | */ |
| | | function makeInterfaceParam($param, $appId) |
| | | { |
| | | |
| | | $param["id"]=$appId.date("Ymd").getRandomNumber(9); |
| | | $paramJson = json_encode($param,JSON_UNESCAPED_UNICODE); |
| | | return |
| | | "id=".$param["id"]. |
| | | "&data=".urlencode($paramJson). |
| | | "&sign=".getSign($paramJson,$appId,$param["id"]); |
| | | } |
| | | |
| | | /** |
| | | * 生成签名 |
| | | */ |
| | | function getSign($param,$appId,$id){ |
| | | global $systemId; |
| | | return md5( |
| | | "id=".$id. |
| | | "&data=".$param. |
| | | "&key=".$systemId["$appId"] |
| | | ); |
| | | } |
| | | |
| | | /** |
| | | * 生成随机数字 |
| | | */ |
| | | function getRandomNumber($length){ |
| | | $arr = [0,1,2,3,4,5,6,7,8,9]; |
| | | $str = ''; |
| | | for ($i = 0; $i < $length; $i++) |
| | | { |
| | | $str .= $arr[rand(0, 9)]; |
| | | } |
| | | 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; |
| | | } |
New file |
| | |
| | | <?php |
| | | /** |
| | | * 注册用户 api |
| | | * 2018-11-28 chenlei |
| | | */ |
| | | define('IN_ECS', true); |
| | | include_once ('../includes/init.php'); |
| | | include_once ('./common/interface.func.php'); |
| | | |
| | | $action = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : 'default'; |
| | | |
| | | $affiliate = unserialize($GLOBALS['_CFG']['affiliate']); |
| | | $smarty->assign('affiliate', $affiliate); |
| | | $back_act = ''; |
| | | |
| | | /* 路由 */ |
| | | $function_name = 'action_' . $action; |
| | | // if(function_exists($function_name)) |
| | | // { |
| | | if($_SERVER['REQUEST_METHOD'] != 'POST'){ |
| | | http_response_code(405); |
| | | } else { |
| | | $retData=checkParam($_POST); |
| | | switch ($retData["regMsg"]){ |
| | | case "e00000": |
| | | exit(json_encode(action_register (), JSON_UNESCAPED_UNICODE)); |
| | | case "e00001": |
| | | exit(array( |
| | | "rspCode"=>"e00001", |
| | | "rspMsg"=>"接入平台不存在" |
| | | )); |
| | | case "e00002": |
| | | exit(array( |
| | | "rspCode"=>"e00002", |
| | | "rspMsg"=>"鉴权失败" |
| | | )); |
| | | } |
| | | } |
| | | // } |
| | | /* 路由 */ |
| | | |
| | | /** |
| | | * 注册会员的处理 |
| | | */ |
| | | function action_register () |
| | | { |
| | | // 获取全局变量 |
| | | $_CFG = $GLOBALS['_CFG']; |
| | | $_LANG = $GLOBALS['_LANG']; |
| | | $smarty = $GLOBALS['smarty']; |
| | | $db = $GLOBALS['db']; |
| | | $ecs = $GLOBALS['ecs']; |
| | | |
| | | /* 增加是否关闭注册 */ |
| | | if($_CFG['shop_reg_closed']) |
| | | { |
| | | $rst['rspCode'] = "e20001"; |
| | | $rst['rspMsg'] = "注册系统已关闭"; |
| | | return $rst; |
| | | } else { |
| | | include_once ('../includes/lib_passport.php'); |
| | | |
| | | $data = str_replace("\\", "", $_POST['data']); |
| | | $parameter = json_decode($data, true); |
| | | $username = isset($parameter['username']) ? trim($parameter['username']) : ''; |
| | | |
| | | $password = isset($parameter['password']) ? trim($parameter['password']) : ''; |
| | | $email = isset($parameter['email']) ? trim($parameter['email']) : ''; |
| | | $other['msn'] = isset($parameter['extend_field1']) ? $parameter['extend_field1'] : ''; |
| | | $other['qq'] = isset($parameter['extend_field2']) ? $parameter['extend_field2'] : ''; |
| | | $other['office_phone'] = isset($parameter['extend_field3']) ? $parameter['extend_field3'] : ''; |
| | | $other['home_phone'] = isset($parameter['extend_field4']) ? $parameter['extend_field4'] : ''; |
| | | $other['openid'] = isset($parameter['openid']) ? $parameter['openid'] : ''; |
| | | $other['invitation_code'] = isset($parameter['invitation_code']) ? $parameter['invitation_code'] : ''; |
| | | //$other['mobile_phone'] = isset($pa['extend_field5']) ? $pa['extend_field5'] : ''; |
| | | $sel_question = empty($parameter['sel_question']) ? '' : compile_str($parameter['sel_question']); |
| | | $passwd_answer = isset($parameter['passwd_answer']) ? compile_str(trim($parameter['passwd_answer'])) : ''; |
| | | |
| | | // 注册类型:email、mobile |
| | | $register_type = isset($parameter['register_type']) ? trim($parameter['register_type']) : ''; |
| | | |
| | | $back_act = isset($parameter['back_act']) ? trim($parameter['back_act']) : ''; |
| | | |
| | | if($register_type == "email") |
| | | { |
| | | /* 邮箱验证码检查 */ |
| | | require_once ('../includes/lib_validate_record.php'); |
| | | |
| | | /* 邮箱注册 */ |
| | | $result = register_by_email($username, $password, $email, $other); |
| | | |
| | | if($result) |
| | | { |
| | | /* 删除注册的验证记录 */ |
| | | remove_validate_record($email); |
| | | } |
| | | } else if($register_type == "mobile") { |
| | | |
| | | require_once ('../includes/lib_validate_record.php'); |
| | | |
| | | $mobile_phone = ! empty($parameter['phone']) ? trim($parameter['phone']) : ''; |
| | | |
| | | /* 手机注册 */ |
| | | $result = register_by_mobile($username, $password, $mobile_phone, $other); |
| | | |
| | | if($result) |
| | | { |
| | | /* 删除注册的验证记录 */ |
| | | remove_validate_record($mobile_phone); |
| | | } |
| | | } else { |
| | | $rst['rspCode'] = "e10009"; |
| | | $rst['rspMsg'] = "请求失败"; |
| | | return $rst; |
| | | } |
| | | |
| | | if($result) |
| | | { |
| | | /* 把新注册用户的扩展信息插入数据库 */ |
| | | $sql = 'SELECT id FROM ' . $ecs->table('reg_fields') . ' WHERE type = 0 AND display = 1 ORDER BY dis_order, id'; // 读出所有自定义扩展字段的id |
| | | $fields_arr = $db->getAll($sql); |
| | | |
| | | $extend_field_str = ''; // 生成扩展字段的内容字符串 |
| | | foreach($fields_arr as $val) |
| | | { |
| | | $extend_field_index = 'extend_field' . $val['id']; |
| | | if(! empty($parameter[$extend_field_index])) |
| | | { |
| | | $temp_field_content = strlen($parameter[$extend_field_index]) > 100 ? mb_substr($parameter[$extend_field_index], 0, 99) : $parameter[$extend_field_index]; |
| | | $extend_field_str .= " ('" . $_SESSION['user_id'] . "', '" . $val['id'] . "', '" . compile_str($temp_field_content) . "'),"; |
| | | } |
| | | } |
| | | $extend_field_str = substr($extend_field_str, 0, - 1); |
| | | |
| | | if($extend_field_str) // 插入注册扩展数据 |
| | | { |
| | | $sql = 'INSERT INTO ' . $ecs->table('reg_extend_info') . ' (`user_id`, `reg_field_id`, `content`) VALUES' . $extend_field_str; |
| | | $db->query($sql); |
| | | } |
| | | |
| | | |
| | | /* 写入密码提示问题和答案 */ |
| | | if(! empty($passwd_answer) && ! empty($sel_question)) |
| | | { |
| | | $sql = 'UPDATE ' . $ecs->table('users') . " SET `passwd_question`='$sel_question', `passwd_answer`='$passwd_answer' WHERE `user_id`='" . $_SESSION['user_id'] . "'"; |
| | | $db->query($sql); |
| | | } |
| | | |
| | | $now = gmtime(); |
| | | if($_CFG['bonus_reg_rand']) |
| | | { |
| | | $sql_bonus_ext = " order by rand() limit 0,1"; |
| | | } |
| | | $sql_b = "SELECT type_id FROM " . $ecs->table("bonus_type") . " WHERE send_type='" . SEND_BY_REGISTER . "' AND send_start_date<=" . $now . " AND send_end_date>=" . $now . $sql_bonus_ext; |
| | | $res_bonus = $db->query($sql_b); |
| | | $kkk_bonus = 0; |
| | | while($row_bonus = $db->fetchRow($res_bonus)) |
| | | { |
| | | $sql = "INSERT INTO " . $ecs->table('user_bonus') . "(bonus_type_id, bonus_sn, user_id, used_time, order_id, emailed)" . " VALUES('" . $row_bonus['type_id'] . "', 0, '" . $_SESSION['user_id'] . "', 0, 0, 0)"; |
| | | $db->query($sql); |
| | | $kkk_bonus = $kkk_bonus + 1; |
| | | } |
| | | if($kkk_bonus) |
| | | { |
| | | $_LANG['register_success'] = '用户名 %s 注册成功,并获得官方赠送的红包礼品'; |
| | | } |
| | | |
| | | |
| | | /* 判断是否需要自动发送注册邮件 */ |
| | | if($GLOBALS['_CFG']['member_email_validate'] && $GLOBALS['_CFG']['send_verify_email']) |
| | | { |
| | | send_regiter_hash($_SESSION['user_id']); |
| | | } |
| | | |
| | | $rst['rspCode'] = "e00000"; |
| | | $rst['rspMsg'] = "请求成功"; |
| | | return $rst; |
| | | } else { |
| | | $rst['rspCode'] = "e10009"; |
| | | $rst['rspMsg'] = "请求失败"; |
| | | return $rst; |
| | | } |
| | | } |
| | | } |
| | | ?> |
| | |
| | | return $user; |
| | | } |
| | | /** |
| | | * 根据openId获取用户是否存在 |
| | | * chenlei |
| | | * @param unknown $openId |
| | | * @return unknown |
| | | */ |
| | | function exist_user_info($openId = ""){ |
| | | $sql = 'SELECT u.user_id, u.email,u.user_rank, u.user_name, u.user_money, u.pay_points'. |
| | | ' FROM ' .$GLOBALS['ecs']->table('users'). ' AS u ' . |
| | | " WHERE u.openid = '$openId'"; |
| | | $result = $GLOBALS['db']->getRow($sql); |
| | | if ($result !== false && !empty($result)) |
| | | { |
| | | // 获取全局变量 |
| | | $user = $GLOBALS['user']; |
| | | $user -> set_session($result[user_name]); |
| | | $user -> set_cookie($result[user_name], isset($_POST['remember'])); |
| | | return true; |
| | | } else { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 取得当前位置和页面标题 |
| | | * |
| | | * @access public |
| | |
| | | $other_key_array = array( |
| | | // 改为手机注册时,则不需要此处的手机验证了 |
| | | // 'msn','qq','office_phone','home_phone','mobile_phone' |
| | | 'msn','qq','office_phone','home_phone' |
| | | // 2018-11-28 验证码和openid添加到合法数组中 chenlei start |
| | | 'msn','qq','office_phone','home_phone', 'invitation_code', 'openid' |
| | | // 2018-11-28 验证码和openid添加到合法数组中 chenlei end |
| | | ); |
| | | $update_data['reg_time'] = local_strtotime(local_date('Y-m-d H:i:s')); |
| | | $update_data['froms'] = WEB_FROM; |
| | |
| | | |
| | | require(dirname(__FILE__) . '/includes/init.php'); |
| | | |
| | | // 2018-11-28 根据openid模拟登陆 chenlei start |
| | | $openid = $_REQUEST['openid']; |
| | | if (!empty($openid)) { |
| | | $Loaction = 'index.php'; |
| | | if (exist_user_info($openid)) { |
| | | ecs_header("Location: $Loaction\n"); |
| | | } else { |
| | | // 获取全局变量 |
| | | $user = $GLOBALS['user']; |
| | | |
| | | $user->logout(); |
| | | ecs_header("Location: $Loaction\n"); |
| | | } |
| | | } |
| | | // 2018-11-28 根据openid模拟登陆 chenlei end |
| | | |
| | | if ((DEBUG_MODE & 2) != 2) |
| | | { |
| | | $smarty->caching = true; |
| | |
| | | $smarty->assign('affiliate', $affiliate); |
| | | $back_act = ''; |
| | | |
| | | include_once (ROOT_PATH . 'includes/cls_json.php'); |
| | | |
| | | // 不需要登录的操作或自己验证是否登录(如ajax处理)的act |
| | | $not_login_arr = array( |
| | | 'login', 'act_login', 'act_edit_password', 'get_password', 'send_pwd_email', 'password', 'signin', 'add_tag', 'collect', 're_collect', 'return_to_cart', 'book_goods','add_book_goods', 'logout', 'user_bonus', 'email_list', 'validate_email', 'send_hash_mail', 'order_query', 'is_registered', 'check_email', 'check_mobile_phone', 'clear_history', 'qpassword_name', 'get_passwd_question', 'check_answer', 'check_register', 'oath', 'oath_login', 'other_login', 'ch_email', 'ck_email', 'check_username', 'forget_password', 'getverifycode', 'step_1', |