首先,我们需要准备好接口的请求参数。根据接口示例,我们需要提供以下参数:
- key:接口密钥,可以在控制台的密钥管理中找到;
- mobile:待查询的手机号;
- isp:运营商,可选值为移动(yd)、联通(lt)或电信(dx);
- order:随机生成的订单号,长度为8到32位。
接下来,我们将使用PHP的cURL库来发送POST请求并获取接口的响应数据。以下是示例代码:
<?php
// 准备请求参数
$key = "35kj5jnlj53453kl5j43nj5";
$mobile = "18833333333";
$isp = "yd";
$order = "12345678";
// 构造请求数据
$data = array(
'key' => $key,
'mobile' => $mobile,
'isp' => $isp,
'order' => $order
);
// 发送POST请求
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.example.com/api/huafei");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETU