AgentIdentify.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * AgentIdentify.php UTF-8
  4. * 渠道实名认证
  5. *
  6. * @date : 2020/6/20 11:53
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : HUOUNION 8.5
  11. */
  12. namespace huoIdentify\controller;
  13. use huo\controller\common\Base;
  14. use huo\model\user\UserModel;
  15. use huoIdentify\model\IdentifyAgentModel;
  16. use huolib\constant\CommonConst;
  17. use huolib\constant\IdentifyConst;
  18. use huolib\status\AgentStatus;
  19. use huolib\status\CommonStatus;
  20. use huolib\status\IdentifyStatus;
  21. use huolib\status\MemberStatus;
  22. use huolib\tool\StrUtils;
  23. use huolib\utils\IdentifyUtils;
  24. use think\Config;
  25. use think\Exception;
  26. class AgentIdentify extends Base {
  27. /**
  28. * 获取渠道认证信息
  29. *
  30. * @param int $agent_id 玩家id
  31. * @param bool $encrypt 是否加密
  32. *
  33. * @return mixed : array
  34. */
  35. public function getIdentifyByAgentId($agent_id, $encrypt = false) {
  36. $_agent_data = (new IdentifyAgentModel())->getInfoByAgentId($agent_id);
  37. $_data['id_card'] = get_val($_agent_data, 'id_card');
  38. $_data['real_name'] = get_val($_agent_data, 'real_name');
  39. $_data['birthday'] = IdentifyUtils::getBirthday($_data['id_card']);
  40. $_data['age'] = IdentifyUtils::getAge($_data['birthday']);
  41. $_data['is_auth'] = IdentifyConst::IS_AUTH_NO;
  42. if (!empty($_data['id_card'])) {
  43. $_data['is_auth'] = IdentifyConst::IS_AUTH_YES;
  44. }
  45. if (true == $encrypt) {
  46. if (!empty($_data['real_name'])) {
  47. $_data['real_name'] = StrUtils::encryptName($_data['real_name']);
  48. }
  49. if (!empty($_data['id_card'])) {
  50. $_data['id_card'] = StrUtils::encryptName($_data['id_card']);
  51. }
  52. }
  53. return $_data;
  54. }
  55. /**
  56. * 更新实名认证信息
  57. *
  58. * @param $agent_id
  59. * @param int $type
  60. * @param $real_name
  61. * @param $id_card
  62. * @param bool $remote_check 远程校验
  63. *
  64. * @return mixed
  65. */
  66. public function updateIdentify($agent_id, $type, $real_name, $id_card, $remote_check = true) {
  67. $_agent_data = (new UserModel())->getInfoById($agent_id);
  68. if (empty($_agent_data)) {
  69. $_code = AgentStatus::DATA_NOT_FOUND_EXCEPTION;
  70. return $this->huoSuccess($_code, MemberStatus::getMsg($_code));
  71. }
  72. $_chk_rs = IdentifyUtils::checkIdentify($type, $real_name, $id_card);
  73. if (IdentifyStatus::NO_ERROR != $_chk_rs) {
  74. return $this->huoError($_chk_rs, IdentifyStatus::getMsg($_chk_rs));
  75. }
  76. if (!$remote_check) {
  77. $_code = IdentifyStatus::NO_ERROR;
  78. return $this->huoSuccess($_code, IdentifyStatus::getMsg($_code));
  79. }
  80. $_im_model = new IdentifyAgentModel();
  81. $_is_other_api_check = (new IdentifyConf())->getIsOtherApiCheck();
  82. if (CommonConst::STATUS_YES == $_is_other_api_check) {
  83. /* 当前开启了第三方api校验才需要验证 */
  84. $_identify_from = Config::get('identify_conf.default'); //实名认证api
  85. try {
  86. $_identify_class = \huoIdentify\identifyDriver\Identify::ins()->get($_identify_from);
  87. $_identify_class->setRealName($real_name);
  88. $_identify_class->setIdCard($id_card);
  89. $_identify_class->setIdentifyFrom($_identify_from);
  90. $_identify_rs = $_identify_class->identify();
  91. if (CommonStatus::NO_ERROR != $_identify_rs['code']) {
  92. $_identify_rs['msg'] = '认证失败,请确认身份信息是否正确';
  93. return $this->huoReturn($_identify_rs);
  94. }
  95. } catch (exception $e) {
  96. return $this->huoError($e->getCode(), $e->getMessage());
  97. };
  98. }
  99. $_old_id_data = $_im_model->getInfoByAgentId($agent_id);
  100. $_data = [
  101. 'identify_from' => '',
  102. 'agent_id' => $agent_id,
  103. 'real_name' => $real_name,
  104. 'id_card' => $id_card,
  105. 'identify_type' => $type,
  106. ];
  107. if (empty($_old_id_data)) {
  108. $_rs = $_im_model->addData($_data);
  109. } else {
  110. $_rs = $_im_model->updateData($_data, $_old_id_data['id']);
  111. }
  112. if (false === $_rs) {
  113. $_code = AgentStatus::INNER_ERROR;
  114. return $this->huoError($_code, AgentStatus::getMsg($_code));
  115. }
  116. return $this->retSucMsg(IdentifyStatus::NO_ERROR);
  117. }
  118. }