| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <?php
- /**
- * 聚合渠道 玩家实名认证管理
- */
- namespace app\api\controller\v2;
- use app\api\controller\Api;
- use app\common\library\RsaSign;
- use app\common\model\ComplexLoginlog;
- use app\common\model\ComplexChannelModel;
- use app\common\model\ComplexMembers;
- use app\common\logic\Complex;
- use Authentication;
- use think\Db;
- use think\Cache;
- use think\Exception;
- use think\Config;
- use app\common\model\PolychannelGame;
- use think\Env;
- use think\exception\HttpResponseException;
- use think\Request;
- use think\Validate;
- use app\common\controller\Base;
- class ComplexAuthentication extends Api
- {
- public function _initialize()
- {
- // parent::_initialize();
- }
- private function initCheck()
- {
- }
- // 实名认证
- public function check()
- {
- $validate = new Validate([
- 'uid' => 'require', // CP渠道用户ID
- 'game_id' => 'require', // 游戏ID
- 'channel_mark' => 'require', // 渠道标识
- 'real_name' => 'require|chsAlpha', // 真实姓名
- 'id_card' => 'require|alphaNum', // 身份证号
- 'sign' => 'require'
- ], [
- 'uid.require' => '缺少参数: uid',
- 'game_id.require' => '缺少参数: game_id',
- 'channel_mark.require' => '缺少参数: channel_mark',
- 'real_name.require' => '缺少参数: real_name',
- 'real_name.chsAlpha' => '真实姓名 格式有误!',
- 'id_card.require' => '缺少参数: id_card',
- 'id_card.alphaNum' => '身份证号 格式有误!',
- 'id_card' => '身份证号 格式有误!',
- 'sign.require' => '缺少参数: sign',
- ]);
- $data = Request::instance()->only(['uid', 'game_id', 'channel_mark', 'real_name', 'id_card', 'sign']);
- if (!$validate->check($data)) {
- return resultJson(-100, $validate->getError());
- }
- $gameInfo = model('Common/Game')->alias('g')
- ->join('cy_app a', 'a.gameid = g.id', 'left')
- ->where('g.id', $data['game_id'])->field('a.appkey,g.game_bizid,g.game_auth_type,g.id')->find();
- if (empty($gameInfo['id'])) return resultJson(-101, '当前游戏不存在!');
- if (empty($gameInfo['appkey'])) return resultJson(-102, '当前游戏缺少实名配置项!(请联系商务)');
- if (empty($gameInfo['game_bizid'])) return resultJson(-103, '当前游戏未配置中宣!(请联系商务)');
- if (empty($gameInfo['game_auth_type'])) return resultJson(-104, '当前游戏未开启中宣认证!(请联系商务)');
- $sign = $this->checkSign($data, $gameInfo['appkey']);
- if ($data['sign'] != $sign) return resultJson([], -120, '签名有误!');
- vendor('authSdk.Authentication', '.class.php');
- $auth = new Authentication();
- $result = $auth->check(trim($gameInfo['game_bizid']), $gameInfo['id'] . '-' . $data['uid'], $data['real_name'], $data['id_card']);
- if ($result['errcode'] <> 0) {
- if ($result['errcode'] > 1000 && $result['errcode'] < 2000) {
- // return resultJson(-130, '中宣 系统错误!:' . $result['errmsg']);
- return resultJson(-130, '中宣 系统错误!');
- }
- switch ($result['errcode']) {
- case 2001:
- $msg = '身份证号格式校验失败!';
- break;
- case 2002:
- $msg = '实名认证条目已达上限!';
- break;
- case 2003:
- $msg = '无该编码提交的实名认证记录!';
- break;
- case 2004:
- // $msg = '编码已经被占用!';
- $msg = '调用频繁,请稍后重试!';
- break;
- case 2005:
- $msg = '姓名合法性校验错误!';
- break;
- case 2006:
- $msg = 'PlayerId生成错误!';
- }
- return resultJson(-131, $msg ?? $result['errmsg']);
- }
- $resultData = $result['data']['result'];
- $authData = [
- 'complex_id' => $data['uid'],
- 'real_name' => trim($data['real_name']),
- 'idcard_num' => trim($data['id_card']),
- 'last_auth_time' => time(),
- 'update_time' => time(),
- ];
- $complexAuthModel = model('Common/ComplexMembersAuthentication');
- $caId = $complexAuthModel->where(['auth_pi' => $resultData['pi']])->value('id');
- if ($resultData['status'] == 0) {
- $authData['auth_status'] = 3; // 认证状态: 0=未认证, 1=认证中, 2=认证不通过, 3=认证通过
- } else if ($resultData['status'] == 1) {
- $authData['auth_status'] = 1;
- } else {
- $authData['auth_status'] = 2;
- }
- if($caId){
- $updResult = $complexAuthModel->where(['id' => $caId])->update($authData);
- }else{
- $authData['auth_type'] = 1;
- $authData['auth_pi'] = $resultData['pi'];
- $authData['createtime'] = time();
- $updResult = $complexAuthModel->insert($authData);
- }
- return resultJson(200, 'success', ['pi' => $resultData['pi'], 'auth_status' => $authData['auth_status']]);
- }
- // 实名认证结果查询
- public function query()
- {
- $validate = new Validate([
- 'uid' => 'require', // 渠道用户ID
- 'channel_mark' => 'require', // 渠道标识
- 'sign' => 'require'
- ], [
- 'uid.require' => '缺少参数: uid',
- 'channel_mark.require' => '缺少参数: channel_mark',
- 'sign.require' => '缺少参数: sign',
- ]);
- $data = Request::instance()->only(['uid', 'channel_mark', 'sign']);
- if (!$validate->check($data)) {
- $this->result([], -110, $validate->getError(), 'json');
- }
- $info = model('Common/ComplexMembers')->alias('cc')
- ->join('cy_app a', 'cc.gameid = a.gameid', 'left')
- ->join('cy_game g', 'cc.gameid = g.id', 'left')
- ->where('complex_id', $data['uid'])->field('cc.id,cc.complex_id,cc.gameid,cc.channel_id,a.appkey,g.game_bizid,g.game_auth_type')->find();
- // dump($info->toArray());
- if (!$info) $this->result([], -111, '渠道用户不存在!', 'json');
- if (!isset($info['appkey'])) $this->result([], -112, '当前游戏缺少实名配置项!(请联系商务)', 'json');
- if (!isset($info['game_bizid'])) $this->result([], -113, '当前游戏未配置中宣!(请联系商务)', 'json');
- if (!isset($info['game_auth_type'])) $this->result([], -114, '当前游戏未开启中宣认证!(请联系商务)', 'json');
- $sign = $this->checkSign($data, $info['appkey']);
- if ($data['sign'] != $sign) $this->result([], -120, '签名有误!', 'json');
- $complexModel = model('Common/ComplexMembersAuthentication');
- $info = $complexModel->where(['members_id' => $info['id']])->find();
- if (!empty($info)) $this->result([], -140, '当前用户不存在!', 'json');
- if ($info['auth_status'] === 0) $this->result([], -141, '当前用户未认证!', 'json');
- vendor('authSdk.Authentication', '.class.php');
- $auth = new Authentication();
- $result = $auth->query(trim($info['game_bizid']), $info['id'] . '-' . $data['uid']);
- if ($result['errcode'] <> 0) {
- if ($result['errcode'] == 2004) {
- $this->result([], -130, '调用频繁,请稍后重试!', 'json');
- } else {
- $this->result([], -131, '中宣接口异常:' . $result['errmsg'], 'json');
- }
- }
- $resultData = $result['data']['result'];
- $authData = [
- 'id' => $info['id'],
- 'last_query_time' => time(),
- 'update_time' => time(),
- ];
- if ($resultData['status'] == 0) {
- $authData['auth_status'] = 3;
- $updResult = $complexModel->save($authData);
- if (!$updResult) {
- $this->jsonResult([], -41, '实名认证结果保存异常');
- }
- } else if ($resultData['status'] == 1) {
- $authData['auth_status'] = 1;
- $complexModel->save($authData);
- $this->result([], -42, '当前用户认证中审核中...', 'json');
- } else {
- $authData['auth_status'] = 2;
- $complexModel->save($authData);
- $this->result([], -43, '当前用户认证不通过!', 'json');
- }
- $this->jsonResult([
- 'real_name' => $info['real_name'],
- 'idcard_num' => $info['idcard_num'],
- 'auth_status' => $info['auth_status'],
- ], 200, 'success');
- }
- // 中宣部游戏用户行为数据上报
- public function sync()
- {
- }
- // 签名校验
- private function checkSign($data, $app_key)
- {
- unset($data['sign']); // 去除 sign 参数
- ksort($data); // 按照键名排序
- $url_params = http_build_query($data); // 将数组转换为 URL 参数字符串
- $url_params = urldecode($url_params);
- return md5($url_params . $app_key); // MD5(字符串+app_key)
- }
- }
|