| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 | <?php/** * AgentIdentify.php UTF-8 * 渠道实名认证 * * @date    : 2020/6/20 11:53 * * @license 这不是一个自由软件,未经授权不许任何使用和传播。 * @author  : chenbingling <cbl@huosdk.com> * @version : HUOUNION 8.5 */namespace huoIdentify\controller;use huo\controller\common\Base;use huo\model\user\UserModel;use huoIdentify\model\IdentifyAgentModel;use huolib\constant\CommonConst;use huolib\constant\IdentifyConst;use huolib\status\AgentStatus;use huolib\status\CommonStatus;use huolib\status\IdentifyStatus;use huolib\status\MemberStatus;use huolib\tool\StrUtils;use huolib\utils\IdentifyUtils;use think\Config;use think\Exception;class AgentIdentify extends Base {    /**     * 获取渠道认证信息     *     * @param int  $agent_id 玩家id     * @param bool $encrypt  是否加密     *     * @return mixed : array     */    public function getIdentifyByAgentId($agent_id, $encrypt = false) {        $_agent_data = (new IdentifyAgentModel())->getInfoByAgentId($agent_id);        $_data['id_card'] = get_val($_agent_data, 'id_card');        $_data['real_name'] = get_val($_agent_data, 'real_name');        $_data['birthday'] = IdentifyUtils::getBirthday($_data['id_card']);        $_data['age'] = IdentifyUtils::getAge($_data['birthday']);        $_data['is_auth'] = IdentifyConst::IS_AUTH_NO;        if (!empty($_data['id_card'])) {            $_data['is_auth'] = IdentifyConst::IS_AUTH_YES;        }        if (true == $encrypt) {            if (!empty($_data['real_name'])) {                $_data['real_name'] = StrUtils::encryptName($_data['real_name']);            }            if (!empty($_data['id_card'])) {                $_data['id_card'] = StrUtils::encryptName($_data['id_card']);            }        }        return $_data;    }    /**     * 更新实名认证信息     *     * @param      $agent_id     * @param int  $type     * @param      $real_name     * @param      $id_card     * @param bool $remote_check 远程校验     *     * @return mixed     */    public function updateIdentify($agent_id, $type, $real_name, $id_card, $remote_check = true) {        $_agent_data = (new UserModel())->getInfoById($agent_id);        if (empty($_agent_data)) {            $_code = AgentStatus::DATA_NOT_FOUND_EXCEPTION;            return $this->huoSuccess($_code, MemberStatus::getMsg($_code));        }        $_chk_rs = IdentifyUtils::checkIdentify($type, $real_name, $id_card);        if (IdentifyStatus::NO_ERROR != $_chk_rs) {            return $this->huoError($_chk_rs, IdentifyStatus::getMsg($_chk_rs));        }        if (!$remote_check) {            $_code = IdentifyStatus::NO_ERROR;            return $this->huoSuccess($_code, IdentifyStatus::getMsg($_code));        }        $_im_model = new IdentifyAgentModel();        $_is_other_api_check = (new IdentifyConf())->getIsOtherApiCheck();        if (CommonConst::STATUS_YES == $_is_other_api_check) {            /* 当前开启了第三方api校验才需要验证 */            $_identify_from = Config::get('identify_conf.default');  //实名认证api            try {                $_identify_class = \huoIdentify\identifyDriver\Identify::ins()->get($_identify_from);                $_identify_class->setRealName($real_name);                $_identify_class->setIdCard($id_card);                $_identify_class->setIdentifyFrom($_identify_from);                $_identify_rs = $_identify_class->identify();                if (CommonStatus::NO_ERROR != $_identify_rs['code']) {                    $_identify_rs['msg'] = '认证失败,请确认身份信息是否正确';                    return $this->huoReturn($_identify_rs);                }            } catch (exception $e) {                return $this->huoError($e->getCode(), $e->getMessage());            };        }        $_old_id_data = $_im_model->getInfoByAgentId($agent_id);        $_data = [            'identify_from' => '',            'agent_id'      => $agent_id,            'real_name'     => $real_name,            'id_card'       => $id_card,            'identify_type' => $type,        ];        if (empty($_old_id_data)) {            $_rs = $_im_model->addData($_data);        } else {            $_rs = $_im_model->updateData($_data, $_old_id_data['id']);        }        if (false === $_rs) {            $_code = AgentStatus::INNER_ERROR;            return $this->huoError($_code, AgentStatus::getMsg($_code));        }        return $this->retSucMsg(IdentifyStatus::NO_ERROR);    }}
 |