<?php


namespace Api\PhpServices\Certification;
use Api\PhpUtils\Http\Request;

class ThreeElementsCertification
{
    private const app_key                  = '7a4d233b0fb7bdf1da5c1374dc1f4516';
    //运营商三要素检测接口
    private const test_mobile3_ele_Sim_url = 'https://111.202.245.110:8180/credit/Mobile3EleSim';

    //加密需要的相关参数
    private const salt = 'A99BC8325635E303';
    private const iterations = 2;
    private const segments = 1;

    /**
     * 运营商三要素检测
     * @param $mobile_num
     * @param $id_num
     * @param $name
     * @return array
     */
    public function mobile3EleSimCheck($mobile_num,$id_num,$name)
    {
        $encry_data = sprintf('idCard=%s&name=%s&mobile=%s',$id_num,$name,$mobile_num);
        $crypt = PbeWithMd5AndDes::encrypt(
            $encry_data, self::app_key,
            self::salt, self::iterations, self::segments
        );

        $query = [
            'rettype' => 'json',
            'encryptParam' => $crypt
        ];

        $result = (new Request())->get(self::test_mobile3_ele_Sim_url.'/'.self::app_key,$query,4000,[],1);
        if (isset($result['code']) && $result['code'] === 0) {
            return $result['response'];
        }
        return ['code'=>-1];
    }

}