IdentifyController.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /**
  3. * IdentifyController.php UTF-8
  4. * 实名认证
  5. *
  6. * @date : 2018/4/27 16:38
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace api\float\controller;
  13. use api\common\controller\V2ApiBaseController;
  14. use huo\controller\member\Bind;
  15. use huo\controller\member\Member;
  16. use huo\controller\member\MemCache;
  17. use huo\model\member\MemberModel;
  18. use huoIdentify\controller\Identify;
  19. use huoIdentify\controller\Online;
  20. use huoIdentify\controller\UnderageLimitMsg;
  21. use huolib\constant\CommonConst;
  22. use huolib\constant\GameConst;
  23. use huolib\constant\IdentifyConst;
  24. use huolib\sms\SmsType;
  25. use huolib\status\CommonStatus;
  26. use huolib\status\MemberStatus;
  27. class IdentifyController extends V2ApiBaseController {
  28. public function _initialize() {
  29. parent::_initialize();
  30. }
  31. /**
  32. * WAP-实名认证页
  33. * http://doc.1tsdk.com/138?page_id=3112
  34. * 【域名】/wap/identify/index
  35. */
  36. public function index() {
  37. $this->checkLogin();
  38. $_device_id = get_val($this->rq_data, 'device_id', '');
  39. $_mem_data = (new MemCache())->getInfoById($this->mem_id);
  40. $_app_id = $this->request->param('app_id', CommonConst::CONST_ZERO);
  41. $_rdata['username'] = $_mem_data['username'];
  42. $_id_types = IdentifyConst::getTypes();
  43. $_list = [];
  44. foreach ($_id_types as $_k => $_v) {
  45. $_list[] = [
  46. 'type_id' => $_k,
  47. 'type_name' => $_v,
  48. ];
  49. }
  50. $_type_arr['count'] = count($_id_types);
  51. $_type_arr['list'] = $_list;
  52. $_rdata['type'] = $_type_arr;
  53. $_rdata['game_auth'] = (new \huoIdentify\controller\Identify())->getGameAuthByAppId($_app_id);
  54. $this->assign($_rdata);
  55. $this->assign('app_id', $_app_id);
  56. $this->assign('device_id', $_device_id);
  57. return $this->fetch('identify/index');
  58. }
  59. /**
  60. * API-实名认证-设置
  61. * http://doc.1tsdk.com/138?page_id=3117
  62. * 【域名】/wap/identify/set
  63. */
  64. public function save() {
  65. $this->checkLogin();
  66. $_type = $this->request->param('type/d', IdentifyConst::ITYPE_MAINLAND);
  67. $_idcard = $this->request->param('idcard/s', '');
  68. $_idcard = $this->request->param('id_card/s', $_idcard); //兼容旧字段
  69. $_realname = $this->request->param('realname/s', '');
  70. $_realname = $this->request->param('real_name/s', $_realname); //兼容旧字段
  71. if (empty($_idcard) || empty($_realname)) {
  72. $_code = CommonStatus::INVALID_PARAMS;
  73. $this->error(CommonStatus::getMsg($_code), [], $_code);
  74. }
  75. $_rdata = (new Identify())->updateIdentify($this->mem_id, $_type, $_realname, $_idcard);
  76. $this->returnData($_rdata);
  77. }
  78. /**
  79. * WAP-实名认证提示信息页
  80. * http://doc.huosdk.com/web/#/138?page_id=10976
  81. * 【域名】/wap/identify/msg
  82. */
  83. public function getMsg() {
  84. $_type = $this->request->param('type', CommonConst::CONST_ZERO);
  85. $_rdata = UnderageLimitMsg::getMsg($_type);
  86. $this->assign('msg', $_rdata['msg']);
  87. $this->assign('close_type', $_rdata['close_type']);
  88. return $this->fetch('identify/msg');
  89. }
  90. /**
  91. * 绑定手机页面
  92. * http://doc.huosdk.com/web/#/138?page_id=10989
  93. * 【域名】/wap/identify/bind/mobile
  94. */
  95. public function bindMobile() {
  96. $_app_id = get_val($this->rq_data, 'app_id', CommonConst::CONST_ZERO);
  97. $_device_id = get_val($this->rq_data, 'device_id', '');
  98. $this->assign('app_id', $_app_id);
  99. $this->assign('device_id', $_device_id);
  100. $_game_auth = GameConst::GAME_IDENTIFY_IS_YES; // 类型 1 实名认证:不需认证 2 实名认证:强制认证 3 实名认证:需认证
  101. $_mem_id = $this->mem_id;
  102. $_online_class = (new Online($_app_id, $_mem_id, $_device_id));
  103. $_time_left = $_online_class->getTimeLeft();
  104. if (empty($_time_left['time_left']) && !empty($_time_left['bind_url'])) {
  105. // $_game_auth = (new \huoIdentify\controller\Identify())->getGameAuthByAppId($_app_id);
  106. $_game_auth = GameConst::GAME_IDENTIFY_IS_MUST; // 类型 1 实名认证:不需认证 2 实名认证:强制认证 3 实名认证:需认证
  107. }
  108. $_identify_url = $_online_class->getIdentifyUrl();
  109. $this->assign('identify_url', $_identify_url);
  110. $this->assign('game_auth', $_game_auth);
  111. return $this->fetch('identify/bind_mobile');
  112. }
  113. /**
  114. * 发送短信
  115. * http://doc.huosdk.com/web/#/138?page_id=10990
  116. * 【域名】/wap/identify/sms/send
  117. */
  118. public function smsSend() {
  119. $_param = $this->rq_data;
  120. $_sms_data = get_val($_param, 'sms', []);
  121. $_mobile = get_val($_sms_data, 'mobile', '');
  122. if (empty($_mobile)) {
  123. $_mem_id = $this->mem_id;
  124. $_rdata = (new Bind())->getBindInfo($_mem_id);
  125. if (CommonStatus::NO_ERROR != $_rdata['code']) {
  126. return $this->returnData($_rdata);
  127. }
  128. $_mobile = get_val($_rdata['data'], 'real_mobile', '');
  129. }
  130. $_type = get_val($_sms_data, 'type', SmsType::SMS_ID_VERIFY);
  131. $_bind_class = new Bind();
  132. $_rdata = $_bind_class->smsSend($_mobile, $_type);
  133. return $this->returnData($_rdata);
  134. }
  135. /**
  136. * 绑定手机
  137. * http://doc.huosdk.com/web/#/138?page_id=10991
  138. * 【域名】/wap/identify/bind/post
  139. */
  140. public function bindPost() {
  141. $_sms_data = get_val($this->rq_data, 'sms', []);
  142. $_mobile = get_val($_sms_data, 'mobile', '');
  143. $_type = get_val($_sms_data, 'type', SmsType::SMS_ID_VERIFY);
  144. $_code = get_val($_sms_data, 'code', '');
  145. $_app_id = get_val($this->rq_data, 'app_id', CommonConst::CONST_ZERO);
  146. $_device_id = get_val($this->rq_data, 'device_id', '');
  147. $_password = get_val($this->rq_data, 'password', '');
  148. if (empty($_password)) {
  149. $_code = MemberStatus::PASSWORD_EMPTY;
  150. $this->error(MemberStatus::getMsg($_code));
  151. }
  152. if (empty($_app_id) || empty($_device_id)) {
  153. $_code = CommonStatus::INVALID_PARAMS;
  154. $this->error(CommonStatus::getMsg($_code));
  155. }
  156. $_member_count = (new MemberModel()) ->getMemNumber($_mobile);
  157. if ($_member_count > 8){
  158. $_code = MemberStatus::PHONE_BIND_TOOMUCH;
  159. $this->error(MemberStatus::getMsg($_code));
  160. }
  161. $_mem_rq = $this->setMemData();
  162. $_bind_class = new Bind();
  163. $_rdata = $_bind_class->bindPost($this->mem_id, $_mobile, $_code, $_type, $_mem_rq->getPassword());
  164. if (CommonStatus::NO_ERROR != $_rdata['code']) {
  165. return $this->returnData($_rdata);
  166. }
  167. $_auth_info = (new Identify())->getMemIdentifyInfo($_app_id, $this->mem_id, $_device_id);
  168. $_rdata['data']['url'] = get_val($_auth_info, 'url', '');
  169. $_rdata['data']['auth_info'] = get_val($_auth_info, 'auth_info', []);
  170. $_rs = (new Member())->updatePassword($this->mem_id, $_password);
  171. if (CommonStatus::NO_ERROR != $_rs['code']) {
  172. return $this->returnData($_rs);
  173. }
  174. //Log::error(['绑定手机号', $this->rq_data, $_rdata]);
  175. return $this->returnData($_rdata);
  176. }
  177. }