/** * check login * 检查登录合法性及返回sdk返回的用户id或部分用户信息 */ public function check() { //http请求中所有请求参数数组 $params = $_REQUEST; // 往请求参数增加private_key,这一步要在发起http请求之前 $params['private_key'] = 'XXX_ANYSDK_PRIVATE_KEY_XXX'; //检测必要参数 if (!$this->parametersIsset($params)) { echo 'parameter not complete'; exit; } //模拟http请求 include_once './classes/HttpHelper.php'; $http = new HttpHelper(); //请求前,对参数进行 urlencode 操作 $params = $http->urlencode($params); //这里建议使用post方式提交请求,避免客户端提交的参数再次被urlencode导致部分渠道token带有特殊符号验证失败 $result = $http->post($this->_loginCheckUrl, $params); //@todo在这里处理游戏逻辑,在服务器注册用户信息等 $json_array = json_decode($result, true); $json_array['ext']['accountID'] = $json_array['common']['uid']; echo json_encode($json_array); //$result如: {"status":"ok","data":{--渠道服务器返回的信息--},"common":{"channel":"渠道标识","uid":"用户标识"}} //输出anysdk统一登录返回 if (self::DEBUG_MODE) { $logFile = '/tmp/game.server.login.check.log'; file_put_contents($logFile, "#" . date('Y-m-d H:i:s') . "\n", FILE_APPEND); file_put_contents($logFile, "#URL:\n" . print_r($http->getUrl(), TRUE) . "\n", FILE_APPEND); file_put_contents($logFile, "#RESULT:\n" . print_r($result, TRUE) . "\n", FILE_APPEND); file_put_contents($logFile, "#DECODE:\n" . print_r(json_decode($result, true), TRUE) . "\n", FILE_APPEND); } }