我想在PHP中集成Aadhaar卡身份验证。我可以试试这段代码,但没有得到回应。 在我错的地方,如何使用此代码获得响应?我可以找到Aadhaar card api的更多细节,但没有得到回复。
<?php
$URL = "http://auth.uidai.gov.in/1.6/public/9/9/MH4hSkrev2h_Feu0lBRC8NI-iqzT299_qPSSstOFbNFTwWrie29ThDo";
$xml_data = '<?xml version="1.0"?>
<Auth xmlns="http://www.uidai.gov.in/authentication/uid-auth-request/1.0"
ver="1.5" tid="public" ac="public" sa="public"
lk="MKg8njN6O+QRUmYF+TrbBUCqlrCnbN/Ns6hYbnnaOk99e5UGNhhE/xQ=" uid="999999990019"
txn="GEO.11051880">
<Skey ci="20131003">Nc6DrZKFk1oQXxfgnFUl0mmtYYIPl0RGaFd2oINkpChU1++xdddMx6Dlbz6mEYs3
IyzChGjRXN5/al9r0runFX8LspTfMchwpxaaDIOyIUguBoYmPUqJDqTQcwey6Ntc
TJWFSgOvBg+omUkdbK/9GOQ5KWWrN+E0A9JN0IPU4IJqJZmsA6ETZlVoZteYtoMI
Ucv53qmxNPOEmJ3s4BC3ppHRRWRFMUp/eW7DFJ33W+uInZB6yekKE0dz8fYeo03w
2JUT1wlafL7aseb04nv5tNEbllHWafmbMpbv2pXKr+WPgytjrygt1LagGqF4a5Mr
/UTNwsy4m/YwlkWN0QcYVw==
</Skey>
<Uses otp="n" pin="n" bio="n" pa="n" pfa="n" pi="y" />
<Data>YOn05vg5qMwElULpEmdiH0j6rM1XWcbQN0n+CFNQeazouCgjyPBH/a2SwbFgq/fF
CYUm+the8gQyYC36VO49NLcNcD7WdMhweoiDYgJoCX/t87Kbq/ABoAetfX7OLAck
/mHrTmw8tsfJgo4xGSzKZKr+pVn1O8dDHJjwgptySr7vp2Ntj6ogu6B905rsyTWw
73iMgoILDHf5soM3Pvde+/XW5rJD9AIPQGhHnKirwkiAgNIhtWU6ttYg4t6gHHbZ
0gVBwgjRzM3sDWKzK0EnmA==
</Data>
<Hmac>xy+JPoVN9dsWVm4YPZFwhVBKcUzzCTVvAxikT6BT5EcPgzX2JkLFDls+kLoNMpWe
</Hmac>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference>
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<DigestValue>Idd9hQtO+YAR4bjfQpNxXQ/EvXc=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>SyFAqzqtJ/VTWcR5cdxoIcsa7GMmgJo7X2Rtr+CVYZLaL2myg3HgaasaT7tPOa95
xYJwnwA/pl+S7ki+W/4Kq1nraV/wxArgE5hFTUFG8G/MOcuMy9Ajd1VPvuqMGvHA
gzGfV+qTcU+1lhQscYnwJqqFmoViZO7NRVwPcfgadXs=</SignatureValue>
<KeyInfo>
<X509Data>
<X509Certificate>MIICfzCCAeigAwIBAgIGAbAh09VkMA0GCSqGSIb3DQEBBQUAMHoxCzAJBgNVBAYT
AklOMQswCQYDVQQIEwJLQTESMBAGA1UEBxMJQmFuZ2Fsb3JlMQ4wDAYDVQQKEwVV
SURBSTEeMBwGA1UECxMVQXV0aGVudGljYXRpb24gU2VydmVyMRowGAYDVQQDExFV
SURBSSBBdXRoIFNlcnZlcjAeFw0xMTA2MjgwNDQwNDRaFw0xMjA2MjgwNDQwNDRa
MGkxCzAJBgNVBAYTAklOMQswCQYDVQQIEwJLQTESMBAGA1UEBxMJQmFuZ2Fsb3Jl
MRMwEQYDVQQKEwpQdWJsaWMgQVVBMQ8wDQYDVQQLEwZQdWJsaWMxEzARBgNVBAMT
ClB1YmxpYyBBVUEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAJBEgKhZZNmH
ejKTFaSg0Z/KN6kP98/FKpPkGTlkovJxa7KX0x74I++JhObM8SkRgCGR3DBK/YZB
o0ZCbvs9czTEoDA8CBMDSFLEP5z+Zi65hdNT9XQiaeN0sSY7N4cafsS/KH/LESbM
6I5OLvSGj10aQB8KDgwItvp/7xK6/Vu3AgMBAAGjITAfMB0GA1UdDgQWBBSd3qZJ
j5lPp+1zkJJCqyZoTLLWAzANBgkqhkiG9w0BAQUFAAOBgQBiGVbCITrygzpC+09u
R/l8w0hCInLusQMZeXgHcnxBGDSk1AQxKk5UfQmCwHNcRJMB5Zkj8+9n6T+/wx6D
tKDelktgIoo7w0EJ6MdVJ9Qzr5PJcYzX+ERgJEd/NNNVoPjFc2Al2odjToZdFN8+
/upJnBH02TRb1Wq63OtcuyBIFA==</X509Certificate>
<X509SubjectName>CN=Public AUA,OU=Public,O=Public
AUA,L=Bangalore,ST=KA,C=IN</X509SubjectName>
</X509Data>
</KeyInfo>
</Signature>
</Auth>';
//setting the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
if (curl_errno($ch)) {
// moving to display page to display curl errors
echo curl_errno($ch);
echo curl_error($ch);
} else {
//getting response from server
$response = curl_exec($ch);
print_r($response);
curl_close($ch);
}
?>
答案 0 :(得分:2)
在上面的代码中,您发送的是1.6版本的请求,而在您提到的1.5版本的XML数据中,您缺少正在发送的xml数据中的一些参数,这些参数是必需的。请求部分中缺少一些密钥。
我根据uidai指南解决了这个问题。但由于您没有提供某些密钥并且您提供的某些密钥无效,因此无法获得成功的响应。
<?php
/**
* Read the documentation here
* https://uidai.gov.in/images/FrontPageUpdates/aadhaar_authentication_api_1_6.pdf
*/
$adhar_card_no = "";
function buildUrl($adhar_card_no)
{
$host = "http://auth.uidai.gov.in";
$version = 1.6;
$aua = "";
$asalk = "";
$uid = str_split($adhar_card_no);
$url = $host."/".$version."/".$aua."/".$uid[0]."/".$uid[1]."/".$asalk;
return $url;
}
function requestDataBuilder($uid)
{
$encrypted_encoded_session_key = "";
$encrypted_pid_block = "";
$sha256_pid_bloc_encrypted_encoded= "";
$digital_aua_signatrure= "";
/**
* Authentication data to send request --Mandatory
*/
$auth_data = [
"uid" => $uid, //Adhaar Card No.
"tid" => "", //Terminal Id for registered device else public
"ac" => "", //10 char unique code, public for testing
"sa" => "", //max length 10, same as ac possible
"ver" => 1.6, //Current version
"txn" => "", //AUA transaction identifier. max length 50, not U*
"lk" => "", //Valid License Key, max length 64
];
/**
* Uses data comprises of options as yes (y) or no (n) -- Mandatory
*/
$uses_data = [
"pi" => "n",
"pa" => "n",
"pfa" => "n",
"bio" => "n",
"bt" => "n",
"pin" => "n",
"otp" => "n"
];
/**
* Token data -- optional
*/
$tkn_data = [
"type" => "001", //only this option available for now which is mobile no.
"value" => "" //Mobile no. 10 digit only no prefix
];
/**
* Meta Data Mandatory
*/
$meta_data = [
"udc" => $udc, //[vendorcode][date of deployment][serial number] max length 20
"fdc" => "NA", //Fingerprint device code. use NA or NC or given code
"idc" => "NA", //Iris device code, us na or NC
"pip" => "NA", //Public IP address of the device, or NA
"lot" => "P", //G -lat long format. p for pincode format
"lov" => "110025" // value as per G and P- my pin change it
];
/**
* Skey data -- Mandatory
*/
$skey_data = [
"ci" => "", //Public key certificate Identifier --mandatory
"ki" => "" //This is for advanced use only, --optional
];
$format = '<Auth uid=”'.$auth_data['uid'].'” tid =”'.$auth_data['tid'].'” ac=”'.$auth_data['ac'].'” sa=”'.$auth_data['sa'].'” ver=”'.$auth_data['ver'].'” txn=”'.$auth_data['txn'].'” lk=”'.$auth_data['lk'].'”>';
$format.= '<Uses pi=”'.$uses_data['pi'].'” pa=”'.$uses_data['pa'].'” pfa=”'.$uses_data['pfa'].'” bio=”'.$uses_data['bio'].'” bt=”'.$uses_data['bt'].'” pin=”'.$uses_data['pin'].'” otp=”'.$uses_data['otp'].'”/>';
$format.= '<Tkn type=”'.$tkn_data['type'].'” value=”'.$tkn_data['value'].'”/>';
$format.= '<Meta udc=”'.$meta_data['udc'].'” fdc=”'.$meta_data['fdc'].'” idc=”'.$meta_data['idc'].'” pip=”'.$meta_data['pip'].'” lot=”'.$meta_data['lot'].'” lov=”'.$meta_data['lov'].'”/>';
$format.= '<Skey ci=”'.$skey_data['ci'].'” ki=”'.$skey_data['ci'].'”>'.$encrypted_encoded_session_key.'</Skey>';
$format.= '<Data type=”X”>'.$encrypted_pid_block.'</Data>';
$format.= '<Hmac>'.$sha256_pid_bloc_encrypted_encoded.'</Hmac>';
$format.= '<Signature>'.$digital_aua_signatrure.'</Signature></Auth>';
return $format;
}
$request_url = buildUrl($adhar_card_no);
$data_to_send = requestDataBuilder($adhar_card_no);
//setting the curl parameters.
$ch = curl_init();
$curl_options = [
CURLOPT_URL => $request_url,
CURLOPT_VERBOSE => 1,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_POST => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => array('Content-Type: application/xnl'),
CURLOPT_POSTFIELDS => $data_to_send
];
curl_setopt_array($ch, $curl_options);
if (curl_errno($ch)) {
// moving to display page to display curl errors
echo curl_errno($ch) ;
echo curl_error($ch);
} else {
//getting response from server
$response = curl_exec($ch);
print_r($response);
curl_close($ch);
}
答案 1 :(得分:1)
得到此回复
<?xml version="1.0" encoding="UTF-8"?>
<AuthRes code="NA" err="569" info="02{49951232b1f45f281c7d4f70f3cbbc57c2afd9c0d6bb5f44578bf1304d4868d4,0000000000000000000000000000000000000000000000000000000000000000,0100000000000000,NA,NA,NA,NA,NA,1.6,20ef0f0c8d0eea98772412cea9b3b92612e3e53cb5e59152b5703165f56e8a53,efa1f375d76194fa51a3556a97e641e61685f914d446979da50a551a4333ffd7,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,efa1f375d76194fa51a3556a97e641e61685f914d446979da50a551a4333ffd7}" ret="n" ts="2017-01-17T16:07:07.664+05:30" txn="AuthDemoClient:public:20160615010712053">
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<Reference URI="">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>PTE1p00N0sHAHhrcgK3CwOPA43+3LOY9VRpd6EefPNk=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>Rax6Fii6UcgdQB5HyaxhjltUHwfQERLCxdB+7+in29jVo+YKJrK3kwJ3Tk3nJ/+dSTQTitaSg/gY
e+mn8E+Txepqy4SMhw9jU+DLCchYnjDUu+8MpUJ6DxlmciwFuWF0oX0KosgJhMwh5+LnkmD81O+G
gnZupgwV/eh5NRIJ9+sSdJRYlgjcOs3pT+OcATO6TQR7QOEE0b4hSps6t5cGQX8aCFdBD5ZXe9r8
ufYFqoD2o2DRBXeRzWkQGTODdD2Sa0hjWDA4jueZfci9Ybt8R84CnDYGflWO/88nKQClOAJX2f9F
/ShVyjoRqStaFrmxsKIEOJ55mONmqn67wkuUWg==</SignatureValue>
</Signature>
</AuthRes>