活体检测H5-V2.1
<p>[TOC]</p>
<h3>简介</h3>
<ul>
<li>活体检测H5是通过引入H5页面实现人像活体检测的RESTful Web Service接口</li>
<li>本接口支持静默、动作、闪光</li>
<li>检测成功之后提取一张人像照片</li>
</ul>
<p>演示(请在手机端打开):<a href="https://api-h5.jumdata.com/lifecheck/v2-1/demo">https://api-h5.jumdata.com/lifecheck/v2-1/demo</a></p>
<h3>接入流程</h3>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=4f31f02100af6432d170ef488b776370&amp;file=file.png" alt="" /></p>
<ol>
<li>接入者服务端通过调用聚美智数活体检测初始化接口获取token和检测页面的url,并返回给接入者页面; </li>
<li>接入者页面转至初始化接口返回的检测页面进行活体检测;检测结束后,检测H5页面会自动跳转至初始化时指定的地址returnUrl,并返回token;</li>
<li>接入者服务端通过调用聚美智数获取检测结果接口获取结果;</li>
</ol>
<h3>接口调用说明</h3>
<h4>请求方式</h4>
<p>如接口没有单独说明,所有接口均为:<strong>POST</strong></p>
<h4>请求格式</h4>
<p>如接口没有单独说明,所有接口均为:<strong>application/x-www-form-urlencoded</strong></p>
<h4>请求参数</h4>
<p>请求参数均包括公共参数和业务参数(业务参数见具体接口说明)
如接口没有单独说明,所有接口调用时,均需要把<strong>公共参数</strong>和<strong>业务参数</strong>一并放在<strong>请求参数</strong>中提交</p>
<p><a name="公共请求参数"></a></p>
<h5>公共请求参数</h5>
<table>
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>必须</th>
<th><div style="width:440px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>appId</td>
<td>String</td>
<td>是</td>
<td>服务商分配的唯一标识</td>
</tr>
<tr>
<td>timestamp</td>
<td>Long</td>
<td>是</td>
<td>当前时间戳(毫秒)</td>
</tr>
<tr>
<td>sign</td>
<td>String</td>
<td>是</td>
<td>签名,详见签名算法说明</td>
</tr>
</tbody>
</table>
<h5>签名算法说明</h5>
<pre><code>sign = sha256(appId + appSecret + timestamp)</code></pre>
<p>用服务商分配的 <strong>appId</strong>、服务商分配的 <strong>appSecret</strong>,当前时间戳(毫秒) <strong>timestamp</strong>,按上述顺序拼接成字符串,再进行 <strong>sha256</strong> 哈希得到。如下:</p>
<pre><code class="language-java">String appId = &quot;xyzxy2121zxyz&quot;;
String timestamp = &quot;1555378976238&quot;;
String appSecret = &quot;efcefcef1121cefcefc1212121&quot;;
String str = appId + appSecret + timestamp;
String sign = sha256(str);</code></pre>
<h4>返回说明</h4>
<h5>公共返回字段说明</h5>
<p>所有接口均返回以下公共字段:</p>
<table>
<thead>
<tr>
<th>字段名</th>
<th><div style="width:440px">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>code</td>
<td>返回码,详见:code返回码说明</td>
</tr>
<tr>
<td>msg</td>
<td>code对应的描述</td>
</tr>
<tr>
<td>charge</td>
<td>计费标志 true为计费,false为不计费</td>
</tr>
<tr>
<td>taskNo</td>
<td>本次请求号</td>
</tr>
<tr>
<td>data</td>
<td>返回具体结果,object类型,详见data返回字段描述</td>
</tr>
</tbody>
</table>
<p><a name="公共code返回码说明"></a></p>
<h5>公共code返回码说明</h5>
<p>所有接口公共返回码如下:</p>
<table>
<thead>
<tr>
<th>code</th>
<th><div style="width:440px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>200</td>
<td>成功</td>
</tr>
<tr>
<td>400</td>
<td>参数错误</td>
</tr>
<tr>
<td>404</td>
<td>接口地址不正确</td>
</tr>
<tr>
<td>500</td>
<td>系统维护,请稍候再试</td>
</tr>
<tr>
<td>601</td>
<td>接口未开通</td>
</tr>
<tr>
<td>602</td>
<td>账号停用</td>
</tr>
<tr>
<td>604</td>
<td>接口停用</td>
</tr>
<tr>
<td>606</td>
<td>调用超限,请稍候再试</td>
</tr>
<tr>
<td>607</td>
<td>ip不在白名单</td>
</tr>
<tr>
<td>609</td>
<td>请求过于频繁,请稍候再试</td>
</tr>
<tr>
<td>610</td>
<td>请求超时</td>
</tr>
<tr>
<td>999</td>
<td>其他,以实际返回为准</td>
</tr>
</tbody>
</table>
<hr />
<h3>活体检测初始化</h3>
<h4>请求地址</h4>
<p><code>https://api.jumdata.com/lifecheck/h5/v2-1/init</code></p>
<h4>业务参数</h4>
<table>
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>必须</th>
<th><div style="width:440px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>returnUrl</td>
<td>String</td>
<td>是</td>
<td>检测完成后页面自动跳转地址,长度不超过256个字符。接入者可以在该地址的页面中去获取检测结果。<br>不用的使用场景,returnUrl的前缀要求不同,详见returnUrl前缀说</td>
</tr>
<tr>
<td>actionStyle</td>
<td>int</td>
<td>否</td>
<td>动作选项,默认:1。详见actionStyle参数说明</td>
</tr>
<tr>
<td>actions</td>
<td>String</td>
<td>否</td>
<td>动作序列,当actionStyle为3时,必须传入。详见actions参数说明</td>
</tr>
<tr>
<td>actionMutex</td>
<td>int</td>
<td>否</td>
<td>是否检查动作互斥,也就是动作不匹配立刻停止采集。<br>1 - 检查,0 - 不检查。默认:1</td>
</tr>
<tr>
<td>antiCameraHack</td>
<td>int</td>
<td>否</td>
<td>是否开启闪光防摄像头劫持检测,对光线环境会有一定要求。<br>1 - 开启,0 - 不开启。默认:1</td>
</tr>
<tr>
<td>title</td>
<td>String</td>
<td>否</td>
<td>采集页面的标题文本,最长32个字符</td>
</tr>
</tbody>
</table>
<h4>returnUrl前缀说明</h4>
<table>
<thead>
<tr>
<th>前缀</th>
<th><div style="width:500px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>无</td>
<td>自适应跳转,<code>http://</code>或<code>https://开头</code> 如<code>http://www.aaa.com</code> 用于普通H5页面跳转</td>
</tr>
<tr>
<td>replace:</td>
<td>指定使用window.location.replace进行跳转, 如<code>replace: http://xxx</code></td>
</tr>
<tr>
<td>wx.redirect</td>
<td>微信小程序跳转,指定使用wx.miniProgram.redirectTo跳转,如<code>wx.redirect:/pages/result</code></td>
</tr>
<tr>
<td>wx.history</td>
<td>微信小程序跳转,指定使用wx.miniProgram.navigateBack跳回原页面</td>
</tr>
<tr>
<td>app:functionName</td>
<td>嵌入app的混合开发模式,functionName必填,如<code>app:notifyResult</code>,采集完成后通过JavaScript Bridge方式通知用户。自定义的方法(如notifyResult),传参为String型(token),用户自主跳转。注:安卓端接收数据时需定义注册的js名是handleLive(webView.addJavascriptInterface(this, “handleLive”))</td>
</tr>
<tr>
<td>scheme:</td>
<td>浏览器打开的采集页面跳到小程序或者app指定页面,如<code>scheme:weixin://…</code></td>
</tr>
</tbody>
</table>
<h4>actionStyle参数说明</h4>
<table>
<thead>
<tr>
<th>值</th>
<th><div style="width:550px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>随机从摇头、点头、左转头、右转头4个头部动作中选取一个动作,再随机从眨眼和张嘴2个局部动作中选取一个动作,然后随机组合这两个动作的顺序</td>
</tr>
<tr>
<td>2</td>
<td>随机从眨眼和张嘴2个局部动作中选取一个动作</td>
</tr>
<tr>
<td>3</td>
<td>自定义</td>
</tr>
<tr>
<td>-1</td>
<td>无动作(静默)</td>
</tr>
</tbody>
</table>
<h4>actions参数说明</h4>
<table>
<thead>
<tr>
<th>值</th>
<th><div style="width:550px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>LookLeft</td>
<td>向左转头,要求动作不要很快,幅度适宜(30度左右)</td>
</tr>
<tr>
<td>LookRight</td>
<td>向右转头,要求动作不要很快,幅度适宜(30度左右)</td>
</tr>
<tr>
<td>OpenMouth</td>
<td>张嘴,从闭嘴变为张开嘴巴,动作不要很快,幅度适宜(嘴唇距离双指以上)</td>
</tr>
<tr>
<td>BlinkEye</td>
<td>眨眼,由睁眼到闭眼,动作不要很快,眼睛睁开到紧闭</td>
</tr>
<tr>
<td>ShakeHead</td>
<td>摇头,向左右转头,动作不要很快,幅度适宜(30度左右)</td>
</tr>
<tr>
<td>NodHead</td>
<td>点头,上下转头,动作不要很快,幅度适宜(30度左右)</td>
</tr>
</tbody>
</table>
<p>公共请求参数请参阅:<a href="#公共请求参数">公共请求参数</a></p>
<h4>成功返回样例</h4>
<pre><code class="language-json">{
&quot;code&quot;: 200,
&quot;msg&quot;: &quot;成功&quot;,
&quot;taskNo&quot;: &quot;043439882226367117195632&quot;,
&quot;charge&quot;: true,
&quot;data&quot;: {
&quot;token&quot;: &quot;xxx&quot;, // 本次检测的token,有效期为2小时,用于后续获取结果
&quot;checkUrl&quot;: &quot;https://api-h5.jumdata.com/lifecheck/v2-1/check/capture.html?token=e146524ee4b8415e8bebc9f739ee67da&quot; // 检测页面的地址
}
}</code></pre>
<h4>code返回码说明</h4>
<p>本接口没有特殊返回码,请参阅:<a href="#公共code返回码说明">公共code返回码说明</a></p>
<hr />
<h3>获取活体检测结果</h3>
<h4>请求地址</h4>
<p><code>https://api.jumdata.com/lifecheck/h5/v2-1/result</code></p>
<table>
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>必须</th>
<th><div style="width:440px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>token</td>
<td>String</td>
<td>是</td>
<td>初始化接口返回的token</td>
</tr>
</tbody>
</table>
<p>公共请求参数请参阅:<a href="#公共请求参数">公共请求参数</a></p>
<h4>检测通过返回样例</h4>
<pre><code class="language-json">{
&quot;code&quot;: 200,
&quot;msg&quot;: &quot;活体检测通过&quot;,
&quot;taskNo&quot;: &quot;043439882226367117195632&quot;,
&quot;data&quot;: {
&quot;faceImageUrl&quot;: &quot;xxx&quot; // 检测通过时返回人像照片地址【注意:链接有效期一天】
&quot;faceImageBase64&quot;: &quot;xxx&quot; // 检测通过时返回人像照片base64
}
}</code></pre>
<h4>检测不通过返回样例</h4>
<pre><code class="language-json">{
&quot;code&quot;: 202,
&quot;msg&quot;: &quot;活体检测未通过&quot;,
&quot;taskNo&quot;: &quot;043439882226367117195632&quot;,
}</code></pre>
<h4>未查询到检测结果返回样例</h4>
<pre><code class="language-json">{
&quot;code&quot;: 201,
&quot;msg&quot;: &quot;未查询到检测结果&quot;,
&quot;taskNo&quot;: &quot;043439882226367117195632&quot;,
}</code></pre>
<h4>检测失败样例</h4>
<pre><code class="language-json">{
&quot;code&quot;: 203,
&quot;msg&quot;: &quot;检测失败&quot;,
&quot;taskNo&quot;: &quot;043439882226367117195632&quot;,
}</code></pre>
<h4>code返回码说明</h4>
<table>
<thead>
<tr>
<th>code</th>
<th><div style="width:120px;">说明</div></th>
<th><div style="width:420px;">原因说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>200</td>
<td>活体检测通过</td>
<td></td>
</tr>
<tr>
<td>202</td>
<td>活体检测未通过</td>
<td>1.用户做出不匹配指令的错误动作<br>2.用户未在等待时间内做出正确动作<br>3.未能采集到质量合格的活体人脸照片<br>4.未通过活体检测算法</td>
</tr>
<tr>
<td>201</td>
<td>未查询到检测结果</td>
<td></td>
</tr>
<tr>
<td>203</td>
<td>活体检测失败</td>
<td>1.浏览器环境不支持活体检测<br>2.用户拒绝打开摄像头<br>3.未能检测到人脸或持续出现多人脸 <br>4.人脸移出视线或出现多人脸<br>5.检测到有可能摄像头被劫持</td>
</tr>
<tr>
<td>301</td>
<td>token已过期</td>
<td>指初始化之后未在两小时内获取结果</td>
</tr>
</tbody>
</table>
<p>公共返回码请参阅:<a href="#公共code返回码说明">公共code返回码说明</a></p>
<h3>前端(VUE)接入参考</h3>
<h4>开始检测页面</h4>
<pre><code class="language-javascript"> // 接入者服务端先提供获取token接口,详见获取初始化接口
// 然后此处调用该接口获取活体检测token
// myLifecheckService 指接入者自行封装的活体检测服务端
myLifecheckService.getToken().then(response=&gt; {
let token = response.token
// 获取token之后跳转至初始化接口返回的活体检测H5页面
location.href = ${初始化接口返回的活体检测H5页面}
})</code></pre>
<h4>returnUrl页面</h4>
<pre><code class="language-javascript"> let query = this.$route.query
let token = query.token
// 在接入者服务端封装获取结果接口,详见获取活体检测结果
myLifecheckService.getResult(token).then(response=&gt; {
if(200===response.code) {
// 检测通过
} else {
// 检测未通过、未查询到检测结果、活体检测失败、token已过期
}
})</code></pre>
<h3>计费说明</h3>
<ul>
<li>调用初始化接口时预扣费用,当检测通过(查询结果接口返回200)或不通过(查询结果接口返回202)时实扣费用,其余情况系统会自动退回费用</li>
<li>查询结果接口不计费</li>
</ul>