| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <?php
- namespace app\api\controller\v1;
- use app\api\controller\Api;
- use app\common\logic\Member;
- use app\common\model\MembersTwo;
- use app\common\model\Setting;
- use app\common\model\Subaccount;
- use think\Db;
- class IsIdentity extends Api
- {
- public function _initialize()
- {
- parent::_initialize();
- }
- /**
- * 是否已经实名认证
- *
- */
- public function isVerified()
- {
- $userid = $this->input('userid'); //用户名
- $gameId = $this->appInfo['gameid']; //游戏ID
- $membersTwoInfo = Db::table('cy_memberstwo')->where(['userid' => $userid])->field('realname,idcard')->find();
- $gameInfo = Db::table('cy_game')->alias('cg')
- ->join('cy_gameinfo cgi', 'cg.id=cgi.game_id', 'left')
- ->where(['cg.id' => $gameId])->field('cg.game_auth_type, cg.game_bizid, cgi.belonging_status')->find();
- $subaccountModel = new Subaccount();
- if ($gameInfo['game_auth_type'] == 1 || $gameInfo['game_auth_type'] == 2) { // 中宣部实名认证
- $gameAccountInfo = $subaccountModel->where(['game_id' => $gameId, 'member_id' => $userid])->find();
- if ($gameAccountInfo) {
- if ($gameAccountInfo['auth_status'] == 3) {
- $membersTwoInfo['realname'] = trim($gameAccountInfo['real_name']);
- $membersTwoInfo['idcard'] = trim($gameAccountInfo['idcard_num']);
- } else if ($gameAccountInfo['auth_status'] == 1) {
- vendor('authSdk.Authentication', '.class.php');
- $auth = new \Authentication();
- $ai = $gameId.'-'.$gameAccountInfo['member_id'] . '-' . $gameAccountInfo['id'];
- $result = $auth->check(trim($gameInfo['game_bizid']), $ai, $membersTwoInfo['realname'], $membersTwoInfo['idcard']);
- if ($result['errcode'] == 0) {
- $resultData = $result['data']['result'];
- // 未认证
- if ($resultData['status'] == 0 && isset($resultData['pi']) && trim($resultData['pi']) <> '') {
- $updAccountData = array();
- $updAccountData['auth_type'] = 1;
- $updAccountData['auth_status'] = 3;
- $updAccountData['auth_pi'] = $resultData['pi'];
- $updAccountData['last_query_time'] = time();
- $updResult = model('Subaccount')->where(['id' => $gameAccountInfo['id']])->update($updAccountData);
- if ($updResult) {
- $membersTwoInfo['realname'] = trim($gameAccountInfo['real_name']);
- $membersTwoInfo['idcard'] = trim($gameAccountInfo['idcard_num']);
- } else {
- $membersTwoInfo['realname'] = '';
- $membersTwoInfo['idcard'] = '';
- }
- } // 认证中
- else if ($resultData['status'] == 1) {
- $updAccountData = array();
- $updAccountData['auth_type'] = 1;
- $updAccountData['last_query_time'] = time();
- $updResult = model('Subaccount')->where(['id' => $gameAccountInfo['id']])->update($updAccountData);
- $membersTwoInfo['realname'] = '';
- $membersTwoInfo['idcard'] = '';
- }
- // 认证不通过
- else if($resultData['status']==2){
- $updAccountData = array();
- $updAccountData['auth_type'] = 1;
- $updAccountData['auth_status'] = 2;
- $updAccountData['last_query_time'] = time();
- $updResult = model('Subaccount')->where(['id' => $gameAccountInfo['id']])->update($updAccountData);
- $membersTwoInfo['realname'] = '';
- $membersTwoInfo['idcard'] = '';
- }
- }
- }
- else{
- $membersTwoInfo['realname'] = '';
- $membersTwoInfo['idcard'] = '';
- }
- }
- else{
- $membersTwoInfo['realname'] = '';
- $membersTwoInfo['idcard'] = '';
- }
- }
- // $isVerified = 是否实名:0=未实名认证, 1=已经实名认证成功
- if (empty($membersTwoInfo) || empty($membersTwoInfo['realname']) || empty($membersTwoInfo['idcard'])) {
- $isVerified = 0;
- } else if ((-1 == $membersTwoInfo['realname']) && (-1 == $membersTwoInfo['idcard'])) {
- $isVerified = 0;
- } else {
- $isVerified = 1;
- }
- // ## 自动实名
- if($isVerified === 0){
- $result = (new Member())->realNameSync($userid, $gameId);
- // if($result['code'] != 200){
- // $this->jsonResult(['isVerified' => 0], 1, $result['msg'] );
- // }
- if($result['code'] == 200){
- $isVerified = 1;
- }
- }
- if ($isVerified) {
- $this->jsonResult(['isVerified' => $isVerified], 1, '已经实名认证成功');
- } else {
- $this->jsonResult(['isVerified' => $isVerified], 1, '未实名认证');
- }
- }
-
- /**
- * 登录后,是否实名认证登录弹窗
- * SDK登录完成后,是否弹出实名认证:1=可设置关闭、2=开启、3=强制开启。
- */
- public function isLoginPopup()
- {
-
- $restrictInfo = model('GameRestrict')->where(['game_id'=>$this->appInfo['gameid'],'restrict_type'=>'realname'])->find();
- if($restrictInfo){
- $isPopup = intval($restrictInfo['restrict_status']);
- }
- else{
- $settingModel = new Setting;
- $isPopup = intval($settingModel::getSetting('SDK_LOGIN_POPUP'));
- }
- $this->jsonResult(['isLoginPopup' => $isPopup], 1);
- }
-
-
- /**
- * 用户支付时,是否实名认证登录弹窗
- */
- public function isPayPopup()
- {
- $restrictInfo = model('GameRestrict')->where(['game_id'=>$this->appInfo['gameid'],'restrict_type'=>'realname'])->find();
- if($restrictInfo){
- $isPopup = intval($restrictInfo['restrict_status']);
- }
- else{
- $settingModel = new Setting;
- $isPopup = intval($settingModel::getSetting('SDK_PAY_POPUP'));
- }
- $this->jsonResult(['isPayPopup' => $isPopup], 1);
- }
-
- /**
- * 返回实名认证详细信息
- *
- */
- public function verifyInfo()
- {
- $membersTwoModel = new MembersTwo();
-
- //玩家扩展表
- $membersTwoInfo = $membersTwoModel->field('realname,idcard,sex')->where(['userid' => $this->input('userid')])->find();
-
- $gameInfo = model('Game')->where(['id' => $this->appInfo['gameid']])->find();
- if($gameInfo['game_auth_type'] == 1 || $gameInfo['game_auth_type'] == 2){ //中宣部实名认证
- $gameAccountInfo = model('Subaccount')->where(['game_id'=>$this->appInfo['gameid'],'member_id'=>$this->input('userid')])->find();
- if($gameAccountInfo){
- if($gameAccountInfo['auth_status']==3){
- $membersTwoInfo['realname'] = trim($gameAccountInfo['real_name']);
- $membersTwoInfo['idcard'] = trim($gameAccountInfo['idcard_num']);
- }
- else if($gameAccountInfo['auth_status']==1){
- $membersTwoInfo['realname'] = '';
- $membersTwoInfo['idcard'] = '';
- }
- else{
- $membersTwoInfo['realname'] = '';
- $membersTwoInfo['idcard'] = '';
- }
- }
- else{
- $membersTwoInfo['realname'] = '';
- $membersTwoInfo['idcard'] = '';
- }
- }
- $is_verified= false;
- $birthday = '';
- $age = '';
-
- if (empty($membersTwoInfo) || empty($membersTwoInfo['realname']) || empty($membersTwoInfo['idcard'])) {
- $is_verified = false;
- } else if ((-1 == $membersTwoInfo['realname']) && (-1 == $membersTwoInfo['idcard'])) {
- $is_verified = false;
- } else {
- $is_verified= true;
- $birthday = strlen($membersTwoInfo['idcard'])==15 ? ('19' . substr($membersTwoInfo['idcard'], 6, 6)) : substr($membersTwoInfo['idcard'], 6, 8);
- if (strlen($membersTwoInfo['idcard']) <= 15) {
- $idcard = convertIDCard15to18($membersTwoInfo['idcard']);
- }
- else{
- $idcard = $membersTwoInfo['idcard'];
- }
- $age = date('Y') - substr($idcard, 6, 4);
- $monthDay = date('md') - substr($idcard, 10, 4);
- if ($monthDay < 0) { //不满周岁,年龄变小一岁
- $age = $age - 1;
- if ($age < 0) $age = 0;
- }
- }
- $returnData['is_verified'] = $is_verified; //是否实名认证
- $returnData['birthday'] = $birthday; //出生年月
- $returnData['age'] = $age; //年龄(周岁)
- $returnData['realname'] = $membersTwoInfo['realname']; //[预留参数]真实姓名
- $returnData['idcard'] = $membersTwoInfo['idcard']; //[预留参数]身份证号
- $returnData['sex'] = $membersTwoInfo['sex']; //[预留参数]性别
- $this->jsonResult($returnData, 1);
- }
- }
|