给大家分享个云脉身份证识别API接口使用教程

[复制链接]
查看11 | 回复0 | 2016-12-6 13:25:00 | 显示全部楼层 |阅读模式
';


$paswd = strtoupper(md5($this->pwd));

$key = $this->getNonceStr();

$dtime = time();

$verify = strtoupper(md5('idcard.scan'.$this->user.$key.$dtime.$paswd));

$picturedata = $this->getUrlImg('http://star409964.oss-cn-beijing.aliyuncs.com/1.JPG');

$data['action'] = 'idcard.scan';

$data['client'] = $this->user;

$data['system'] = 'test card wl';

$data['password'] = $paswd;

$data['key'] = $key;

$data['time'] = $dtime;

$data['verify'] = $verify;

$data['file'] = $picturedata;

$data['ext'] = 'jpg';

$data['header'] = '1';

//数组转换成xml 数据


$xml = $this->ToXml($data);

$rest = $this->postXmlCurl($xml,$this->apiurl);

//xml数据 转换成数组

$arrxml = $this->FromXml($rest);



if($this->saveImg($arrxml['data']['item']['header_pic'])!=FALSE){

echo 'save img success';

}

return $arrxml;
}




/**
* 本地图片转换成二进制数据
* $fileurl-本地地址
* @param string $fileurl
* @return string
*/

function getLoclImg($fileurl){

$PSize = filesize($fileurl);

$picturedata = fread(fopen($fileurl, "r"), $PSize);

return $picturedata;

}



/**
* 远程图片转换成二进制数据
* $url-图片url地址
* @param string $url
* @return string
*/

function getUrlImg($url){

$res = $this->httpGet($url);

return $res;

}

/**
* 将base64字符串保存为图片,失败返回false,成功返回字节数
* @param string $img64
* @param string $filename
* @throws WxPayException
* @return boolen
*/

function saveImg($img64, $filename='./demo.jpg') {

if(empty($img64)){

echo 'img Base64 data cannot be empty';

exit;

}

$img = base64_decode($img64);

$res = file_put_contents($filename, $img);//返回的是字节数

return $res;

}
/**
* 将xml转为array
* @param string $xml
* @throws WxPayException
*/

public function FromXml($xml)

{


if(!$xml){

throw new WxPayException("xml数据异常!");

}
//将XML转为array
//禁止引用外部xml实体
libxml_disable_entity_loader(true);
$values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);


return $values;

}



/**
* 输出xml字符
* @throws WxPayException
**/

public function ToXml($values){

if(!is_array($values) || count($values) ";

foreach ($values as $key=>$val)

{

if (is_numeric($val)){

$xml.="".$val."";

}else{

$xml.="".$val."";

}
}
$xml.="";
return $xml;

}

/**
*
* 产生随机字符串,不长于32位
* @param int $length
* @return 产生的随机字符串
*/

public static function getNonceStr($length = 32)

{

$chars = "abcdefghijklmnopqrstuvwxyz0123456789";

$str ="";

for ( $i = 0; $i shenfenzheng();
复制代码上面代码中的账号和密码,请到www.yunmaiocr.com注册获取就可以直接使用了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行