<?php
header('Content-Type: text/plain; charset=utf-8');
// 记录开始时间
$start_time = microtime(true);

// 验证必需参数
if (!isset($_GET['name']) ||!isset($_GET['phone']) ||!isset($_GET['id'])) {
    die("参数错误，请提供姓名、手机号和身份证号码");
}

$cust_name = $_GET['name'];
$mobile = $_GET['phone'];
$valid_identity = $_GET['id'];

// 构造请求数据
$data = [
    "authType" => "IdCard",
    "isUpdateIdCard" => 1,
    "openId" => "null",
    "roleCode" => "consumer",
    "realName" => $cust_name,
    "cardNo" => $valid_identity,
    "phone" => $mobile,
    "custId" => "CzRagxR3Am",
    "userId" => "CzRagxR3Am"
];

// 设置请求头
$headers = [
    'content-type: application/json',
    'Accept-Encoding: gzip,compress,br,deflate',
    'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 17_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.52(0x18003423) NetType/WIFI Language/zh_CN',
    'Referer: https://servicewechat.com/wxe48112dad392793a/101/page-frame.html'
];

$ch = curl_init();
curl_setopt_array($ch, [
    CURLOPT_URL => 'https://gxhs.wtkj.site/dev-api/gxhs/front/make_auth',
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_POSTFIELDS => json_encode($data),
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_ENCODING => 'gzip,compress,br,deflate'
]);

$response = curl_exec($ch);
if (curl_errno($ch)) {
    die("请求异常: ". curl_error($ch));
}

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

$found_valid = false;
if ($httpCode == 200) {
    $responseData = json_decode($response, true);
    if (json_last_error() === JSON_ERROR_NONE) {
        $original_msg = $responseData['msg']?? '未知状态';
        switch ($original_msg) {
            case '身份证号、姓名、手机号不符':
                break;
            case '操作成功':
            case '您需要登录湖北供销小程序完成实名认证完成回收订单后才能参与优惠券活动':
                $found_valid = true;
                break;
        }
    }
}

// 记录结束时间并计算耗时
$end_time = microtime(true);
$elapsed_time = $end_time - $start_time;

echo "接口由白沐API提供\n白沐yyds\n";
if ($found_valid) {
    echo ">>>> 最终结果:核验一致✅\n";
    echo "姓名: ". $cust_name. "\n";
    echo "身份证: ". $valid_identity. "\n";
    echo "手机号: ". $mobile. "\n";
} else {
    echo ">>>> 最终结果:未找到正确信息❌\n";
}

echo "耗时: ". $elapsed_time. " 秒\n";
