相信大家最近都被防沉迷 接口整的头疼 也有很多坑 下面介绍下对接沉迷的注意事项与接口代码
1、首先在 接口测试 中获取到 APPID、Secret Key、bizId等测试数据 同时配置IP白名单 配置访问ip
2、直接上代码 ,需要用到的方法,自己写的 直接拿过去修改下可以用的
/*
* 请求身份验证接口
* $name 姓名,$card 身份证号,$member_id 平台用户id,$test_code 测试码
*/
function getIdCard($name,$card,$member_id,$test_code='')
{
$secret_key = ''; //正式secret_key
$appId = ''; //正式appId
$bizId = ''; //正式bizId
$timestamps = getMillisecond(); //当前毫秒时间戳
$url = 'https://api.wlc.nppa.gov.cn/idcard/authentication/check';
if($test_code) {
$secret_key = 'a84b4e7eaa4854cc7faf68285c4a61f7'; //测试secret_key
$appId = '2dea4362b36f4b5d9ab19aef5801d72e'; //测试appId
$bizId = '1101999999'; //测试bizId
$url = 'https://wlc.nppa.gov.cn/test/authentication/check/'.$test_code;
}
$head = ['appId'=>$appId,'bizId'=>$bizId,'timestamps'=>$timestamps];
//请求头
$header[] = 'Content-Type:application/json;charset=utf-8';
$header[] = 'appId:'.$appId;
$header[] = 'bizId:'.$bizId;
$header[] ='timestamps:'.$timestamps;
//请求体
$body['ai'] = md5($member_id); //32位 不然也会报错
$body['name'] = $name;
$body['idNum'] = $card