<?php


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

class ThreeElementsCertification
{
    private const app_key                  = '392df35aa98721c597cf20b85d21eebc';
    //运营商三要素检测接口
    public const test_mobile3_ele_Sim_url = 'https://api.goodsdatas.com:8443/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];
    }

}