实名认证接口

/*需要得到agent_id,datakey,key这三个值*/  


 $apiUrl = "https://www.heepay.com/API/Merchant/Reality.aspx";
        $version = '1';  //版本号
        $agent_id = '';
        $name = $request->post('name');
        $datakey ="";  //数据加密key
        $key ="";  //签名key
        //提交参数的中文为GB2312编码,参与签名验证的中文为UTF-8编码
        $gb_name = iconv("UTF-8","gb2312//IGNORE",$name);  //商户页面如果不是GB2312,则需要此处转码
        /*3DES加密*/
        $crypt_name = $this->encrypt($gb_name,$datakey);  //姓名进行3DES加密
       // dump($crypt_name);exit;
        $crypt_cert_no = $this->encrypt($cert_no,$datakey);  //身份证号进行3DES加密
       // dump($crypt_name);exit;
        $params = array(
            'key' => $key,
            'version'=>$version,
            'agent_id'=>$agent_id,
            'name'=>$crypt_name,
            'cert_no'=>$crypt_cert_no,
        );
        //ksort($params);
 //       $signStr='';
//        foreach($params as $key=>$val){
//            $signStr .= $key .'=' . $val.'&';
//        }
//       // rtrim($signStr,"&");
//        $signStr = substr($signStr, 0, -1);
        $signStr='';
        $signStr  = $signStr . 'agent_id=' . $agent_id;
        $signStr  = $signStr . '&cert_no=' . $cert_no;
        $signStr = $signStr . '&key=' . $key;
        $signStr  = $signStr . '&name=' . $name;
        $signStr  = $signStr . '&version=' . $version;
        $sign = md5(strtolower($signStr));  //获取sign密钥
        $params['sign'] = $sign;
        $ch = curl_init ();
        curl_setopt ( $ch, CURLOPT_URL, $apiUrl );
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 从证书中检查SSL加密算法是否存在
        curl_setopt ( $ch, CURLOPT_POST, 1 );
        curl_setopt ( $ch, CURLOPT_HEADER, 0 );
        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $params );
        $return = curl_exec ( $ch );
        //不是JSON格式,是一个xml  先将字串由gb2312转成utf8
        $res = iconv("GB2312","UTF-8",$return);
        $xml=simplexml_load_string($res);
        $xml=(array)$xml;
        curl_close ( $ch );
        if($xml['ret_code'] == '0000'){
            $this->success('实名认证成功','/');
        }else{
            $this->error('实名认证失败','/');
        }

你可能感兴趣的:(实名认证接口)