* @version : HuoSdk 9.0 */ namespace api\sdk\controller; use huo\controller\game\Game; use huo\model\member\MemGameModel; use huolib\status\GameStatus; use huolib\status\MemberStatus; use huolib\utils\IdentifyUtils; use think\Controller; use think\exception\HttpResponseException; use think\Response; class CpIdentifyController extends Controller { private $mg_mem_id; private $app_id; private $sign; private $time; private $mem_id; private $app_key; private function cpReturn($code = '200', $msg = '成功', $data = []) { /*增加uid返回*/ $_rdata = [ 'state' => 1 == $code ? 1 : 0, 'msg' => $msg, 'data' => $data, ]; $_response = Response::create($_rdata, 'json'); throw new HttpResponseException($_response); } /** * CP获取实名认证信息 * https://doc.huosdk.com/web/#/232?page_id=13801 * 【域名】/cp/mem/certify */ public function certify() { /* 1 查询是否具有访问权限 */ $this->checkAuth(); $this->app_id = $this->request->param('appid/d', 0); $this->mg_mem_id = $this->request->param('uid/d', 0); $this->time = $this->request->param('time/d', 0); $this->sign = $this->request->param('sign/s', ''); /* 检查参数 */ $this->checkParam(); /* 校验玩家 */ $this->checkUser(); /* 校验APPID */ $this->checkAppid(); /* 校验签名 */ $this->verifySign(); /* 返回信息 */ $this->returnData(); } /** * 返回信息 */ private function returnData() { $_data = (new \huoIdentify\controller\Identify())->getIdentifyByMemId($this->mem_id, false, $this->app_id); $_id_card = get_val($_data, 'id_card', ''); $_rdata = [ 'age' => get_val($_data, 'age', 0), 'oversea' => false, 'id_type' => 0, 'Id' => empty($_id_card) ? '' : md5($_id_card), 'id_card' => $_id_card, 'real_name' => get_val($_data, 'real_name', ''), 'pi' => get_val($_data, 'pi', ''), 'verify_status' => get_val($_data, 'is_auth', 1), 'birthday' => IdentifyUtils::getBirthday($_id_card, ''), 'temporary' => 0 ]; $this->cpReturn('1', '验证成功', $_rdata); } /** * 校验签名 */ private function verifySign() { $_sign_str = $this->app_id."|".$this->mg_mem_id."|".$this->time."|".$this->app_key; $_verify_sign = md5($_sign_str); if ($this->sign != $_verify_sign) { $_result = ['签名校验不通过', $_sign_str, $_verify_sign, $this->sign]; $_param = $this->request->param(); \think\Log::write( "func=".__FUNCTION__."&class=".__CLASS__."¶m=".json_encode($_param)."&result=".json_encode( $_result ), 'error' ); $_code = GameStatus::SIGN_ERROR; $this->cpReturn($_code, GameStatus::getMsg($_code)); } return true; } /** * 校验游戏 */ private function checkAppId() { $_app_id = (new MemGameModel())->getAppIdById($this->mg_mem_id); if ($_app_id != $this->app_id) { $_code = GameStatus::INVALID_PARAMS; $this->cpReturn($_code, GameStatus::getMsg($_code).':appid'); } $_app_key = (new Game())->getAppKey($this->app_id); if (empty($_app_key)) { $_code = GameStatus::GAME_INFO_NOT_EXIST; $this->cpReturn($_code, GameStatus::getMsg($_code)); } $this->app_key = $_app_key; return true; } /** * 校验玩家 */ private function checkUser() { $_mem_id = (new MemGameModel())->getMemIdById($this->mg_mem_id); if (empty($_mem_id)) { $_code = MemberStatus::UID_NOT_EXISTS; $this->cpReturn($_code, MemberStatus::getMsg($_code)); } $this->mem_id = $_mem_id; return true; } /** * 校验参数 */ private function checkParam() { if (empty($this->app_id) || $this->app_id < 0) { $_code = GameStatus::GAME_NOT_EXISTS; $this->cpReturn($_code, GameStatus::getMsg($_code)); } if (empty($this->sign)) { $_code = GameStatus::SIGN_ERROR; $this->cpReturn($_code, GameStatus::getMsg($_code)); } if (empty($this->mg_mem_id) || $this->app_id < 0) { $_code = MemberStatus::UID_NOT_EXISTS; $this->cpReturn($_code, MemberStatus::getMsg($_code)); } return true; } /** * 校验权限 * * @return bool */ private function checkAuth() { return true; } }