服务地址:
https://market.aliyun.com/products/57000002/cmapi029454.html?spm%3D5176.10695662.1194487.1.fa096c19PeVIb4#sku=yuncode2345400002
购买
请求示例:没有别的sdk
开始弄参数
首先就是主账号Id
登录上阿里云后 访问下面的地址 红框内就是
customerID 可以随便写 不是必须参数 略过
identifyNum 和 userName 是请求接口的时候必须的,来源于用户所填的内容
verifyKey 这个是填写你要调用的网站 才能生成的 也就是说你必须要有网站域名,
如果你有域名备案通过,并且在有效期,那很简单
访问下面地址
然后新增verifyKey
完成后,会跳转
还有appcode
如果你已经购买了 这个服务接口 打开下面地址
这样接口所需参数都已经完成了!
那然后是不是直接可以请求了,
然鹅,看产品说明,感觉事情并没有那么简单
我自己试了试
发现请求完第一个接口以后,返回了一个URL地址 ,
还需要请求第二个接口授权后才会返回结果
返回结果
再去请求其中返回的地址 结果
点击同意授权后,页面空白,没有任何输出
不行,还得找客服 注意找身份认证一的客服
再去请求接口
发现这次直接返回验证结果了 这也就是自己授权
填正确的 返回结果
{"code":200,"value":{"verifyUrl":"","bizCode":0,"message":"success"},"message":"success"}
200 表示验证通过
填错误的返回结果
{"code":404,"message":"check.param.error:参数非法"}
这次没问题了
也就是 verifyKey需要客服确认,如果更换了,还需要客服确认!就这一点比较麻烦!
调试告一段落,我把请求示例自己改了一下 ,需要的拿走,不用谢!
<?php
/**
* 阿里 云盾身份认证(二要素)
* Class AliIdentityAuth
* @package App\Extend
*/
class AliIdentityAuth
{
protected $userId = 'xxxxxx';//购买服务的主账号ID
protected $customerID = 12;//客户自己的userid,只做透传
protected $verifyKey = 'xxxxxx';//新增使用域名生成的verifyKey(重新生成后需与客服确认)
protected $appCode = 'xxxxxxxx';//购买接口生成的code
protected $host = "https://safrvcert.market.alicloudapi.com";//请求阿里云接口域名
protected $path = "/safrv_2meta_id_name/";//请求接口路径
/**
* 执行实名验证
* @param $name:真实姓名
* @param $id_card:身份证号
* @return bool
*/
public function conductAuth($name, $id_card)
{
if (empty($name) || empty($id_card)) return false;
$host = $this->host;
$appCode = $this->appCode;
$querys = "__userId=" . $this->userId . "&customerID=" . $this->customerID . "&identifyNum=" . $id_card . "&userName=" . $name . "&verifyKey=" . $this->verifyKey;
$url = $host . $this->path . "?" . $querys;
$json = $this->curlRequest($host, $url, $appCode, "GET");
$return = json_decode($json, true);
if($return['code'] != 200) {
return false;
}
return true;
}
/**
* curl请求接口
* @param $host
* @param $url
* @param $appCode
* @param $method
* @return bool|string
*/
public function curlRequest($host, $url, $appCode, $method)
{
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appCode);
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
if (1 == strpos("$" . $host, "https://")) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
return curl_exec($curl);
}
}