YhIdentity.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /**
  3. * 获取实名认证信息接口(SDK和聚合全都使用同一个接口)
  4. */
  5. namespace app\api\controller\v1;
  6. use think\Cache;
  7. use app\common\model\Channel;
  8. use app\common\model\MembersTwo;
  9. use app\common\model\ComplexMembers;
  10. use app\api\controller\Api;
  11. use think\Env;
  12. class YhIdentity extends Api
  13. {
  14. protected $_channelMd5Key = '1eraqbEsvS7WzYTbnabsa1babIpidAke'; // 下级渠道通信秘钥
  15. public function _initialize()
  16. {
  17. }
  18. /**
  19. * 获取实名认证信息接口
  20. */
  21. public function getVerifyInfo()
  22. {
  23. if (request()->isPost()) {
  24. $token = input('post.Sdkuid');
  25. // $token = 'DJ+zECuv7CORH3h+ZrQLRW9/FIVZF/O58HKIWzxXNu0nu8aKeih5MtP48BGirSOEsN53bAjeJZLVu3Mq/w/oMhs69umlRcFMXmB096hAtInEdMP0';
  26. $result = $this->validate(
  27. [
  28. 'token' => $token,
  29. ],
  30. [
  31. ['token', 'require', 'Sdkuid不能为空'],
  32. ]);
  33. if (true !== $result) {
  34. $this->result('', 0, $result, 'json');
  35. }
  36. $r = Cache::store('default')->get($token);
  37. if ( !$r ) {
  38. $this->result('',0,'无效Sdkuid','json');
  39. }
  40. //聚合渠道时,$sub_username对应的值是mg_username
  41. list($userid2, $username2, $gameid2,$sub_username,$token_random,$type) = explode('|', auth_code($token,"DECODE", Env::get('auth_key')));
  42. // echo $userid2."---userid2---".$sub_username."----sub_username-----".$type."----type-----<br>";
  43. /*
  44. $userid2 = 29414986;
  45. $sub_username = '13850194392';
  46. $type = 'cm';
  47. */
  48. //默认值
  49. $is_verified = 1;
  50. $birthday = '';
  51. $idcard = '';
  52. $age = 0;
  53. $id_type = 0;
  54. $oversea = false;
  55. $realname = '';
  56. if($type=='sdk'){ //sdk用户
  57. $membersTwoModel = new MembersTwo();
  58. //玩家扩展表
  59. $membersTwoInfo = $membersTwoModel->field('realname,idcard')->where(['userid' => $userid2])->find();
  60. if (empty($membersTwoInfo) || empty($membersTwoInfo['realname']) || empty($membersTwoInfo['idcard'])) {
  61. $is_verified = 1;
  62. } else if ((-1 == $membersTwoInfo['realname']) && (-1 == $membersTwoInfo['idcard'])) {
  63. $is_verified = 1;
  64. } else {
  65. $is_verified= 2;
  66. $realname = $membersTwoInfo['realname'];
  67. $idcard = $membersTwoInfo['idcard'];
  68. $birthday = strlen($idcard)==15 ? ('19' . substr($idcard, 6, 6)) : substr($idcard, 6, 8);
  69. if (strlen($idcard) <= 15) {
  70. $idcard = convertIDCard15to18($idcard);
  71. }
  72. $age = date('Y') - substr($idcard, 6, 4);
  73. $monthDay = date('md') - substr($idcard, 10, 4);
  74. // 验证最小年龄
  75. if ($age < 18 || $age == 18 && $monthDay < 0) {
  76. $is_verified = 3;
  77. }
  78. $idcard = md5($idcard);
  79. }
  80. $returnData['verify_status'] = $is_verified; //1:未验证 2:验证通过 3:验证失败
  81. $returnData['birthday'] = $birthday; //出生年月
  82. $returnData['id_type'] = $id_type;
  83. $returnData['oversea'] = $oversea;
  84. $returnData['Id'] = $idcard; //渠道可以通过特定算法脱敏后,返回唯一身份证值
  85. $returnData['age'] = $age;
  86. $returnData['realname'] = $realname;
  87. $this->result($returnData,1,'获取成功','json');
  88. }
  89. else if($type=='cm'){ //聚合用户
  90. $complexMembersModel = new ComplexMembers;
  91. $userinfo = $complexMembersModel->where(['id'=>$userid2])->find();
  92. if (empty($userinfo) || empty($userinfo['mg_username']) || empty($userinfo['complex_username']) || !intval($userinfo['channel_id'])) {
  93. $this->result('',0,'账号错误','json');
  94. } else {
  95. $channelId = intval($userinfo['channel_id']);
  96. $channelModel = new Channel;
  97. $channelInfo = $channelModel->where(['id'=>$channelId,'flag'=>4])->find();
  98. if(empty($channelInfo) && $channelInfo['status'] <> 1){
  99. $this->result('',0,'渠道不存在或已无效','json');
  100. }
  101. else{
  102. $mark = $channelInfo['mark'];
  103. $complexUsername = $userinfo['complex_username'];
  104. $sign = md5(urlencode($complexUsername).urlencode($this->_channelMd5Key));
  105. $param = [
  106. 'uuid' => urlencode($complexUsername),
  107. 'sign' => $sign,
  108. ];
  109. if($mark=='dt'){ //调用相关渠道接口
  110. $url = '';
  111. }
  112. else{
  113. $this->result('',0,'该渠道暂未提供接口','json');
  114. }
  115. $response = get_http_response($url, http_build_query($param));
  116. // $response = '{"code":1,"msg":"获取成功","time":"1574067041","data":{"verify_status":2,"birthday":"1988-08-28","id_type":0,"oversea":false,"Id":"350101198808285521","realname":"黄韩寒","age":30}}';
  117. if ( ! empty($response) ) {
  118. $response = json_decode($response, true);
  119. }
  120. if(empty($response)){
  121. $this->result('',0,'调用该渠道接口返回错误','json');
  122. }
  123. else if($response['code'] <> 1){
  124. $this->result('',0,'调用该渠道接口返回信息不成功','json');
  125. }
  126. else{
  127. $retData = $response['data'];
  128. // var_dump($retData);
  129. $is_verified = isset($retData['verify_status'])?$retData['verify_status']:$is_verified;
  130. $birthday = isset($retData['birthday'])?$retData['birthday']:$birthday;
  131. $idcard = isset($retData['Id'])?$retData['Id']:$idcard;
  132. $age = isset($retData['age'])?$retData['age']:$age;
  133. $id_type = isset($retData['id_type'])?$retData['id_type']:$id_type;
  134. $oversea = isset($retData['oversea'])?$retData['oversea']:$oversea;
  135. $realname = isset($retData['realname'])?$retData['realname']:$realname;
  136. $returnData['verify_status'] = $is_verified; //1:未验证 2:验证通过 3:验证失败
  137. $returnData['birthday'] = $birthday; //出生年月
  138. $returnData['id_type'] = $id_type;
  139. $returnData['oversea'] = $oversea;
  140. $returnData['Id'] = $idcard; //渠道可以通过特定算法脱敏后,返回唯一身份证值
  141. $returnData['age'] = $age;
  142. $returnData['realname'] = $realname;
  143. $this->result($returnData,1,'获取成功','json');
  144. }
  145. }
  146. }
  147. }
  148. else{
  149. $this->result('',0,'非法或无效token','json');
  150. }
  151. }
  152. else{
  153. $this->result('',0,'请认真查看文档,使用正确的请求方式','json');
  154. }
  155. }
  156. }