123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- /**
- * CpIdentifyController.php UTF-8
- * CP获取实名认证信息
- *
- * @date : 2020/7/28 10:14
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : chenbingling <cbl@huosdk.com>
- * @version : HuoSdk 9.0
- */
- namespace api\sdk\controller;
- use huo\controller\game\Game;
- use huo\model\member\MemGameModel;
- use huolib\status\GameStatus;
- use huolib\status\MemberStatus;
- use huolib\utils\IdentifyUtils;
- use think\Controller;
- use think\exception\HttpResponseException;
- use think\Response;
- class CpIdentifyController extends Controller {
- private $mg_mem_id;
- private $app_id;
- private $sign;
- private $time;
- private $mem_id;
- private $app_key;
- private function cpReturn($code = '200', $msg = '成功', $data = []) {
- /*增加uid返回*/
- $_rdata = [
- 'state' => 1 == $code ? 1 : 0,
- 'msg' => $msg,
- 'data' => $data,
- ];
- $_response = Response::create($_rdata, 'json');
- throw new HttpResponseException($_response);
- }
- /**
- * CP获取实名认证信息
- * https://doc.huosdk.com/web/#/232?page_id=13801
- * 【域名】/cp/mem/certify
- */
- public function certify() {
- /* 1 查询是否具有访问权限 */
- $this->checkAuth();
- $this->app_id = $this->request->param('appid/d', 0);
- $this->mg_mem_id = $this->request->param('uid/d', 0);
- $this->time = $this->request->param('time/d', 0);
- $this->sign = $this->request->param('sign/s', '');
- /* 检查参数 */
- $this->checkParam();
- /* 校验玩家 */
- $this->checkUser();
- /* 校验APPID */
- $this->checkAppid();
- /* 校验签名 */
- $this->verifySign();
- /* 返回信息 */
- $this->returnData();
- }
- /**
- * 返回信息
- */
- private function returnData() {
- $_data = (new \huoIdentify\controller\Identify())->getIdentifyByMemId($this->mem_id, false, $this->app_id);
- $_id_card = get_val($_data, 'id_card', '');
- $_rdata = [
- 'age' => get_val($_data, 'age', 0),
- 'oversea' => false,
- 'id_type' => 0,
- 'Id' => empty($_id_card) ? '' : md5($_id_card),
- 'id_card' => $_id_card,
- 'real_name' => get_val($_data, 'real_name', ''),
- 'pi' => get_val($_data, 'pi', ''),
- 'verify_status' => get_val($_data, 'is_auth', 1),
- 'birthday' => IdentifyUtils::getBirthday($_id_card, ''),
- 'temporary' => 0
- ];
- $this->cpReturn('1', '验证成功', $_rdata);
- }
- /**
- * 校验签名
- */
- private function verifySign() {
- $_sign_str = $this->app_id."|".$this->mg_mem_id."|".$this->time."|".$this->app_key;
- $_verify_sign = md5($_sign_str);
- if ($this->sign != $_verify_sign) {
- $_result = ['签名校验不通过', $_sign_str, $_verify_sign, $this->sign];
- $_param = $this->request->param();
- \think\Log::write(
- "func=".__FUNCTION__."&class=".__CLASS__."¶m=".json_encode($_param)."&result=".json_encode(
- $_result
- ), 'error'
- );
- $_code = GameStatus::SIGN_ERROR;
- $this->cpReturn($_code, GameStatus::getMsg($_code));
- }
- return true;
- }
- /**
- * 校验游戏
- */
- private function checkAppId() {
- $_app_id = (new MemGameModel())->getAppIdById($this->mg_mem_id);
- if ($_app_id != $this->app_id) {
- $_code = GameStatus::INVALID_PARAMS;
- $this->cpReturn($_code, GameStatus::getMsg($_code).':appid');
- }
- $_app_key = (new Game())->getAppKey($this->app_id);
- if (empty($_app_key)) {
- $_code = GameStatus::GAME_INFO_NOT_EXIST;
- $this->cpReturn($_code, GameStatus::getMsg($_code));
- }
- $this->app_key = $_app_key;
- return true;
- }
- /**
- * 校验玩家
- */
- private function checkUser() {
- $_mem_id = (new MemGameModel())->getMemIdById($this->mg_mem_id);
- if (empty($_mem_id)) {
- $_code = MemberStatus::UID_NOT_EXISTS;
- $this->cpReturn($_code, MemberStatus::getMsg($_code));
- }
- $this->mem_id = $_mem_id;
- return true;
- }
- /**
- * 校验参数
- */
- private function checkParam() {
- if (empty($this->app_id) || $this->app_id < 0) {
- $_code = GameStatus::GAME_NOT_EXISTS;
- $this->cpReturn($_code, GameStatus::getMsg($_code));
- }
- if (empty($this->sign)) {
- $_code = GameStatus::SIGN_ERROR;
- $this->cpReturn($_code, GameStatus::getMsg($_code));
- }
- if (empty($this->mg_mem_id) || $this->app_id < 0) {
- $_code = MemberStatus::UID_NOT_EXISTS;
- $this->cpReturn($_code, MemberStatus::getMsg($_code));
- }
- return true;
- }
- /**
- * 校验权限
- *
- * @return bool
- */
- private function checkAuth() {
- return true;
- }
- }
|