| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <?php
- /**
- * 获取实名认证信息接口(SDK和聚合全都使用同一个接口)
- */
- namespace app\api\controller\v1;
- use think\Cache;
- use app\common\model\Channel;
- use app\common\model\MembersTwo;
- use app\common\model\ComplexMembers;
- use app\api\controller\Api;
- use think\Env;
- class YhIdentity extends Api
- {
- protected $_channelMd5Key = '1eraqbEsvS7WzYTbnabsa1babIpidAke'; // 下级渠道通信秘钥
- public function _initialize()
- {
- }
- /**
- * 获取实名认证信息接口
- */
- public function getVerifyInfo()
- {
- if (request()->isPost()) {
-
- $token = input('post.Sdkuid');
-
- // $token = 'DJ+zECuv7CORH3h+ZrQLRW9/FIVZF/O58HKIWzxXNu0nu8aKeih5MtP48BGirSOEsN53bAjeJZLVu3Mq/w/oMhs69umlRcFMXmB096hAtInEdMP0';
-
- $result = $this->validate(
- [
- 'token' => $token,
- ],
- [
- ['token', 'require', 'Sdkuid不能为空'],
- ]);
- if (true !== $result) {
- $this->result('', 0, $result, 'json');
- }
- $r = Cache::store('default')->get($token);
- if ( !$r ) {
- $this->result('',0,'无效Sdkuid','json');
- }
- //聚合渠道时,$sub_username对应的值是mg_username
- list($userid2, $username2, $gameid2,$sub_username,$token_random,$type) = explode('|', auth_code($token,"DECODE", Env::get('auth_key')));
- // echo $userid2."---userid2---".$sub_username."----sub_username-----".$type."----type-----<br>";
- /*
- $userid2 = 29414986;
- $sub_username = '13850194392';
- $type = 'cm';
- */
- //默认值
- $is_verified = 1;
- $birthday = '';
- $idcard = '';
- $age = 0;
- $id_type = 0;
- $oversea = false;
- $realname = '';
- if($type=='sdk'){ //sdk用户
- $membersTwoModel = new MembersTwo();
- //玩家扩展表
- $membersTwoInfo = $membersTwoModel->field('realname,idcard')->where(['userid' => $userid2])->find();
-
- if (empty($membersTwoInfo) || empty($membersTwoInfo['realname']) || empty($membersTwoInfo['idcard'])) {
- $is_verified = 1;
- } else if ((-1 == $membersTwoInfo['realname']) && (-1 == $membersTwoInfo['idcard'])) {
- $is_verified = 1;
- } else {
- $is_verified= 2;
- $realname = $membersTwoInfo['realname'];
- $idcard = $membersTwoInfo['idcard'];
- $birthday = strlen($idcard)==15 ? ('19' . substr($idcard, 6, 6)) : substr($idcard, 6, 8);
- if (strlen($idcard) <= 15) {
- $idcard = convertIDCard15to18($idcard);
- }
- $age = date('Y') - substr($idcard, 6, 4);
- $monthDay = date('md') - substr($idcard, 10, 4);
- // 验证最小年龄
- if ($age < 18 || $age == 18 && $monthDay < 0) {
- $is_verified = 3;
- }
- $idcard = md5($idcard);
- }
- $returnData['verify_status'] = $is_verified; //1:未验证 2:验证通过 3:验证失败
- $returnData['birthday'] = $birthday; //出生年月
- $returnData['id_type'] = $id_type;
- $returnData['oversea'] = $oversea;
- $returnData['Id'] = $idcard; //渠道可以通过特定算法脱敏后,返回唯一身份证值
- $returnData['age'] = $age;
- $returnData['realname'] = $realname;
- $this->result($returnData,1,'获取成功','json');
- }
- else if($type=='cm'){ //聚合用户
- $complexMembersModel = new ComplexMembers;
- $userinfo = $complexMembersModel->where(['id'=>$userid2])->find();
-
- if (empty($userinfo) || empty($userinfo['mg_username']) || empty($userinfo['complex_username']) || !intval($userinfo['channel_id'])) {
- $this->result('',0,'账号错误','json');
- } else {
- $channelId = intval($userinfo['channel_id']);
- $channelModel = new Channel;
- $channelInfo = $channelModel->where(['id'=>$channelId,'flag'=>4])->find();
- if(empty($channelInfo) && $channelInfo['status'] <> 1){
- $this->result('',0,'渠道不存在或已无效','json');
- }
- else{
- $mark = $channelInfo['mark'];
- $complexUsername = $userinfo['complex_username'];
- $sign = md5(urlencode($complexUsername).urlencode($this->_channelMd5Key));
- $param = [
- 'uuid' => urlencode($complexUsername),
- 'sign' => $sign,
- ];
- if($mark=='dt'){ //调用相关渠道接口
- $url = '';
- }
- else{
- $this->result('',0,'该渠道暂未提供接口','json');
- }
- $response = get_http_response($url, http_build_query($param));
- // $response = '{"code":1,"msg":"获取成功","time":"1574067041","data":{"verify_status":2,"birthday":"1988-08-28","id_type":0,"oversea":false,"Id":"350101198808285521","realname":"黄韩寒","age":30}}';
- if ( ! empty($response) ) {
- $response = json_decode($response, true);
- }
- if(empty($response)){
- $this->result('',0,'调用该渠道接口返回错误','json');
- }
- else if($response['code'] <> 1){
- $this->result('',0,'调用该渠道接口返回信息不成功','json');
- }
- else{
- $retData = $response['data'];
- // var_dump($retData);
-
- $is_verified = isset($retData['verify_status'])?$retData['verify_status']:$is_verified;
- $birthday = isset($retData['birthday'])?$retData['birthday']:$birthday;
- $idcard = isset($retData['Id'])?$retData['Id']:$idcard;
- $age = isset($retData['age'])?$retData['age']:$age;
- $id_type = isset($retData['id_type'])?$retData['id_type']:$id_type;
- $oversea = isset($retData['oversea'])?$retData['oversea']:$oversea;
- $realname = isset($retData['realname'])?$retData['realname']:$realname;
-
- $returnData['verify_status'] = $is_verified; //1:未验证 2:验证通过 3:验证失败
- $returnData['birthday'] = $birthday; //出生年月
- $returnData['id_type'] = $id_type;
- $returnData['oversea'] = $oversea;
- $returnData['Id'] = $idcard; //渠道可以通过特定算法脱敏后,返回唯一身份证值
- $returnData['age'] = $age;
- $returnData['realname'] = $realname;
- $this->result($returnData,1,'获取成功','json');
- }
- }
- }
- }
- else{
- $this->result('',0,'非法或无效token','json');
- }
- }
- else{
- $this->result('',0,'请认真查看文档,使用正确的请求方式','json');
- }
- }
- }
|