CpIdentifyController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /**
  3. * CpIdentifyController.php UTF-8
  4. * CP获取实名认证信息
  5. *
  6. * @date : 2020/7/28 10:14
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : HuoSdk 9.0
  11. */
  12. namespace api\sdk\controller;
  13. use huo\controller\game\Game;
  14. use huo\model\member\MemGameModel;
  15. use huolib\status\GameStatus;
  16. use huolib\status\MemberStatus;
  17. use huolib\utils\IdentifyUtils;
  18. use think\Controller;
  19. use think\exception\HttpResponseException;
  20. use think\Response;
  21. class CpIdentifyController extends Controller {
  22. private $mg_mem_id;
  23. private $app_id;
  24. private $sign;
  25. private $time;
  26. private $mem_id;
  27. private $app_key;
  28. private function cpReturn($code = '200', $msg = '成功', $data = []) {
  29. /*增加uid返回*/
  30. $_rdata = [
  31. 'state' => 1 == $code ? 1 : 0,
  32. 'msg' => $msg,
  33. 'data' => $data,
  34. ];
  35. $_response = Response::create($_rdata, 'json');
  36. throw new HttpResponseException($_response);
  37. }
  38. /**
  39. * CP获取实名认证信息
  40. * https://doc.huosdk.com/web/#/232?page_id=13801
  41. * 【域名】/cp/mem/certify
  42. */
  43. public function certify() {
  44. /* 1 查询是否具有访问权限 */
  45. $this->checkAuth();
  46. $this->app_id = $this->request->param('appid/d', 0);
  47. $this->mg_mem_id = $this->request->param('uid/d', 0);
  48. $this->time = $this->request->param('time/d', 0);
  49. $this->sign = $this->request->param('sign/s', '');
  50. /* 检查参数 */
  51. $this->checkParam();
  52. /* 校验玩家 */
  53. $this->checkUser();
  54. /* 校验APPID */
  55. $this->checkAppid();
  56. /* 校验签名 */
  57. $this->verifySign();
  58. /* 返回信息 */
  59. $this->returnData();
  60. }
  61. /**
  62. * 返回信息
  63. */
  64. private function returnData() {
  65. $_data = (new \huoIdentify\controller\Identify())->getIdentifyByMemId($this->mem_id, false, $this->app_id);
  66. $_id_card = get_val($_data, 'id_card', '');
  67. $_rdata = [
  68. 'age' => get_val($_data, 'age', 0),
  69. 'oversea' => false,
  70. 'id_type' => 0,
  71. 'Id' => empty($_id_card) ? '' : md5($_id_card),
  72. 'id_card' => $_id_card,
  73. 'real_name' => get_val($_data, 'real_name', ''),
  74. 'pi' => get_val($_data, 'pi', ''),
  75. 'verify_status' => get_val($_data, 'is_auth', 1),
  76. 'birthday' => IdentifyUtils::getBirthday($_id_card, ''),
  77. 'temporary' => 0
  78. ];
  79. $this->cpReturn('1', '验证成功', $_rdata);
  80. }
  81. /**
  82. * 校验签名
  83. */
  84. private function verifySign() {
  85. $_sign_str = $this->app_id."|".$this->mg_mem_id."|".$this->time."|".$this->app_key;
  86. $_verify_sign = md5($_sign_str);
  87. if ($this->sign != $_verify_sign) {
  88. $_result = ['签名校验不通过', $_sign_str, $_verify_sign, $this->sign];
  89. $_param = $this->request->param();
  90. \think\Log::write(
  91. "func=".__FUNCTION__."&class=".__CLASS__."&param=".json_encode($_param)."&result=".json_encode(
  92. $_result
  93. ), 'error'
  94. );
  95. $_code = GameStatus::SIGN_ERROR;
  96. $this->cpReturn($_code, GameStatus::getMsg($_code));
  97. }
  98. return true;
  99. }
  100. /**
  101. * 校验游戏
  102. */
  103. private function checkAppId() {
  104. $_app_id = (new MemGameModel())->getAppIdById($this->mg_mem_id);
  105. if ($_app_id != $this->app_id) {
  106. $_code = GameStatus::INVALID_PARAMS;
  107. $this->cpReturn($_code, GameStatus::getMsg($_code).':appid');
  108. }
  109. $_app_key = (new Game())->getAppKey($this->app_id);
  110. if (empty($_app_key)) {
  111. $_code = GameStatus::GAME_INFO_NOT_EXIST;
  112. $this->cpReturn($_code, GameStatus::getMsg($_code));
  113. }
  114. $this->app_key = $_app_key;
  115. return true;
  116. }
  117. /**
  118. * 校验玩家
  119. */
  120. private function checkUser() {
  121. $_mem_id = (new MemGameModel())->getMemIdById($this->mg_mem_id);
  122. if (empty($_mem_id)) {
  123. $_code = MemberStatus::UID_NOT_EXISTS;
  124. $this->cpReturn($_code, MemberStatus::getMsg($_code));
  125. }
  126. $this->mem_id = $_mem_id;
  127. return true;
  128. }
  129. /**
  130. * 校验参数
  131. */
  132. private function checkParam() {
  133. if (empty($this->app_id) || $this->app_id < 0) {
  134. $_code = GameStatus::GAME_NOT_EXISTS;
  135. $this->cpReturn($_code, GameStatus::getMsg($_code));
  136. }
  137. if (empty($this->sign)) {
  138. $_code = GameStatus::SIGN_ERROR;
  139. $this->cpReturn($_code, GameStatus::getMsg($_code));
  140. }
  141. if (empty($this->mg_mem_id) || $this->app_id < 0) {
  142. $_code = MemberStatus::UID_NOT_EXISTS;
  143. $this->cpReturn($_code, MemberStatus::getMsg($_code));
  144. }
  145. return true;
  146. }
  147. /**
  148. * 校验权限
  149. *
  150. * @return bool
  151. */
  152. private function checkAuth() {
  153. return true;
  154. }
  155. }