IsIdentity.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\Api;
  4. use app\common\logic\Member;
  5. use app\common\model\MembersTwo;
  6. use app\common\model\Setting;
  7. use app\common\model\Subaccount;
  8. use think\Db;
  9. class IsIdentity extends Api
  10. {
  11. public function _initialize()
  12. {
  13. parent::_initialize();
  14. }
  15. /**
  16. * 是否已经实名认证
  17. *
  18. */
  19. public function isVerified()
  20. {
  21. $userid = $this->input('userid'); //用户名
  22. $gameId = $this->appInfo['gameid']; //游戏ID
  23. $membersTwoInfo = Db::table('cy_memberstwo')->where(['userid' => $userid])->field('realname,idcard')->find();
  24. $gameInfo = Db::table('cy_game')->alias('cg')
  25. ->join('cy_gameinfo cgi', 'cg.id=cgi.game_id', 'left')
  26. ->where(['cg.id' => $gameId])->field('cg.game_auth_type, cg.game_bizid, cgi.belonging_status')->find();
  27. $subaccountModel = new Subaccount();
  28. if ($gameInfo['game_auth_type'] == 1 || $gameInfo['game_auth_type'] == 2) { // 中宣部实名认证
  29. $gameAccountInfo = $subaccountModel->where(['game_id' => $gameId, 'member_id' => $userid])->find();
  30. if ($gameAccountInfo) {
  31. if ($gameAccountInfo['auth_status'] == 3) {
  32. $membersTwoInfo['realname'] = trim($gameAccountInfo['real_name']);
  33. $membersTwoInfo['idcard'] = trim($gameAccountInfo['idcard_num']);
  34. } else if ($gameAccountInfo['auth_status'] == 1) {
  35. vendor('authSdk.Authentication', '.class.php');
  36. $auth = new \Authentication();
  37. $ai = $gameId.'-'.$gameAccountInfo['member_id'] . '-' . $gameAccountInfo['id'];
  38. $result = $auth->check(trim($gameInfo['game_bizid']), $ai, $membersTwoInfo['realname'], $membersTwoInfo['idcard']);
  39. if ($result['errcode'] == 0) {
  40. $resultData = $result['data']['result'];
  41. // 未认证
  42. if ($resultData['status'] == 0 && isset($resultData['pi']) && trim($resultData['pi']) <> '') {
  43. $updAccountData = array();
  44. $updAccountData['auth_type'] = 1;
  45. $updAccountData['auth_status'] = 3;
  46. $updAccountData['auth_pi'] = $resultData['pi'];
  47. $updAccountData['last_query_time'] = time();
  48. $updResult = model('Subaccount')->where(['id' => $gameAccountInfo['id']])->update($updAccountData);
  49. if ($updResult) {
  50. $membersTwoInfo['realname'] = trim($gameAccountInfo['real_name']);
  51. $membersTwoInfo['idcard'] = trim($gameAccountInfo['idcard_num']);
  52. } else {
  53. $membersTwoInfo['realname'] = '';
  54. $membersTwoInfo['idcard'] = '';
  55. }
  56. } // 认证中
  57. else if ($resultData['status'] == 1) {
  58. $updAccountData = array();
  59. $updAccountData['auth_type'] = 1;
  60. $updAccountData['last_query_time'] = time();
  61. $updResult = model('Subaccount')->where(['id' => $gameAccountInfo['id']])->update($updAccountData);
  62. $membersTwoInfo['realname'] = '';
  63. $membersTwoInfo['idcard'] = '';
  64. }
  65. // 认证不通过
  66. else if($resultData['status']==2){
  67. $updAccountData = array();
  68. $updAccountData['auth_type'] = 1;
  69. $updAccountData['auth_status'] = 2;
  70. $updAccountData['last_query_time'] = time();
  71. $updResult = model('Subaccount')->where(['id' => $gameAccountInfo['id']])->update($updAccountData);
  72. $membersTwoInfo['realname'] = '';
  73. $membersTwoInfo['idcard'] = '';
  74. }
  75. }
  76. }
  77. else{
  78. $membersTwoInfo['realname'] = '';
  79. $membersTwoInfo['idcard'] = '';
  80. }
  81. }
  82. else{
  83. $membersTwoInfo['realname'] = '';
  84. $membersTwoInfo['idcard'] = '';
  85. }
  86. }
  87. // $isVerified = 是否实名:0=未实名认证, 1=已经实名认证成功
  88. if (empty($membersTwoInfo) || empty($membersTwoInfo['realname']) || empty($membersTwoInfo['idcard'])) {
  89. $isVerified = 0;
  90. } else if ((-1 == $membersTwoInfo['realname']) && (-1 == $membersTwoInfo['idcard'])) {
  91. $isVerified = 0;
  92. } else {
  93. $isVerified = 1;
  94. }
  95. // ## 自动实名
  96. if($isVerified === 0){
  97. $result = (new Member())->realNameSync($userid, $gameId);
  98. // if($result['code'] != 200){
  99. // $this->jsonResult(['isVerified' => 0], 1, $result['msg'] );
  100. // }
  101. if($result['code'] == 200){
  102. $isVerified = 1;
  103. }
  104. }
  105. if ($isVerified) {
  106. $this->jsonResult(['isVerified' => $isVerified], 1, '已经实名认证成功');
  107. } else {
  108. $this->jsonResult(['isVerified' => $isVerified], 1, '未实名认证');
  109. }
  110. }
  111. /**
  112. * 登录后,是否实名认证登录弹窗
  113. * SDK登录完成后,是否弹出实名认证:1=可设置关闭、2=开启、3=强制开启。
  114. */
  115. public function isLoginPopup()
  116. {
  117. $restrictInfo = model('GameRestrict')->where(['game_id'=>$this->appInfo['gameid'],'restrict_type'=>'realname'])->find();
  118. if($restrictInfo){
  119. $isPopup = intval($restrictInfo['restrict_status']);
  120. }
  121. else{
  122. $settingModel = new Setting;
  123. $isPopup = intval($settingModel::getSetting('SDK_LOGIN_POPUP'));
  124. }
  125. $this->jsonResult(['isLoginPopup' => $isPopup], 1);
  126. }
  127. /**
  128. * 用户支付时,是否实名认证登录弹窗
  129. */
  130. public function isPayPopup()
  131. {
  132. $restrictInfo = model('GameRestrict')->where(['game_id'=>$this->appInfo['gameid'],'restrict_type'=>'realname'])->find();
  133. if($restrictInfo){
  134. $isPopup = intval($restrictInfo['restrict_status']);
  135. }
  136. else{
  137. $settingModel = new Setting;
  138. $isPopup = intval($settingModel::getSetting('SDK_PAY_POPUP'));
  139. }
  140. $this->jsonResult(['isPayPopup' => $isPopup], 1);
  141. }
  142. /**
  143. * 返回实名认证详细信息
  144. *
  145. */
  146. public function verifyInfo()
  147. {
  148. $membersTwoModel = new MembersTwo();
  149. //玩家扩展表
  150. $membersTwoInfo = $membersTwoModel->field('realname,idcard,sex')->where(['userid' => $this->input('userid')])->find();
  151. $gameInfo = model('Game')->where(['id' => $this->appInfo['gameid']])->find();
  152. if($gameInfo['game_auth_type'] == 1 || $gameInfo['game_auth_type'] == 2){ //中宣部实名认证
  153. $gameAccountInfo = model('Subaccount')->where(['game_id'=>$this->appInfo['gameid'],'member_id'=>$this->input('userid')])->find();
  154. if($gameAccountInfo){
  155. if($gameAccountInfo['auth_status']==3){
  156. $membersTwoInfo['realname'] = trim($gameAccountInfo['real_name']);
  157. $membersTwoInfo['idcard'] = trim($gameAccountInfo['idcard_num']);
  158. }
  159. else if($gameAccountInfo['auth_status']==1){
  160. $membersTwoInfo['realname'] = '';
  161. $membersTwoInfo['idcard'] = '';
  162. }
  163. else{
  164. $membersTwoInfo['realname'] = '';
  165. $membersTwoInfo['idcard'] = '';
  166. }
  167. }
  168. else{
  169. $membersTwoInfo['realname'] = '';
  170. $membersTwoInfo['idcard'] = '';
  171. }
  172. }
  173. $is_verified= false;
  174. $birthday = '';
  175. $age = '';
  176. if (empty($membersTwoInfo) || empty($membersTwoInfo['realname']) || empty($membersTwoInfo['idcard'])) {
  177. $is_verified = false;
  178. } else if ((-1 == $membersTwoInfo['realname']) && (-1 == $membersTwoInfo['idcard'])) {
  179. $is_verified = false;
  180. } else {
  181. $is_verified= true;
  182. $birthday = strlen($membersTwoInfo['idcard'])==15 ? ('19' . substr($membersTwoInfo['idcard'], 6, 6)) : substr($membersTwoInfo['idcard'], 6, 8);
  183. if (strlen($membersTwoInfo['idcard']) <= 15) {
  184. $idcard = convertIDCard15to18($membersTwoInfo['idcard']);
  185. }
  186. else{
  187. $idcard = $membersTwoInfo['idcard'];
  188. }
  189. $age = date('Y') - substr($idcard, 6, 4);
  190. $monthDay = date('md') - substr($idcard, 10, 4);
  191. if ($monthDay < 0) { //不满周岁,年龄变小一岁
  192. $age = $age - 1;
  193. if ($age < 0) $age = 0;
  194. }
  195. }
  196. $returnData['is_verified'] = $is_verified; //是否实名认证
  197. $returnData['birthday'] = $birthday; //出生年月
  198. $returnData['age'] = $age; //年龄(周岁)
  199. $returnData['realname'] = $membersTwoInfo['realname']; //[预留参数]真实姓名
  200. $returnData['idcard'] = $membersTwoInfo['idcard']; //[预留参数]身份证号
  201. $returnData['sex'] = $membersTwoInfo['sex']; //[预留参数]性别
  202. $this->jsonResult($returnData, 1);
  203. }
  204. }