客户端代码

 

<?php
// 远程服务器地址
$remote_url = 'http://scriptsz.com/api.php';
// 客户端提交的验证数据
$data = array(
    'username' => 'user',
    'password' => '123456',
);
// 构造请求URL
$request_url = $remote_url . '?' . http_build_query($data);
// 发送HTTP GET请求并获取响应
$response = file_get_contents($request_url);
// 解析JSON格式的响应数据
$result = json_decode($response, true);
// 判断验证结果是否为成功
if ($result['success']) {
    // 验证成功,显示授权码
    echo '授权码:' . $result['authcode'];
} else {
    // 验证失败,显示错误信息
    echo '验证失败:' . $result['errmsg'];
}
?>

远程代码

<?php
function auth_check($username, $password) {
    // 假设这里是一个验证函数,返回验证结果
    if ($username === 'user' && $password === '123456') {
        return array(
            'success' => true,
            'errmsg' => '',
            'authcode' => 'xxx-xxx-xxx',
        );
    } else {
        return array(
            'success' => false,
            'errmsg' => '用户名或密码不正确',
            'authcode' => '',
        );
    }
}
// 获取客户端提交的验证数据
$username = $_GET['username'];
$password = $_GET['password'];

// 假设这里是一个验证函数,返回验证结果
$result = auth_check($username, $password);

// 构造JSON格式的响应数据
$response = array(
    'success' => $result['success'],
    'errmsg' => $result['errmsg'],
    'authcode' => $result['authcode'],
);

// 将响应数据以JSON格式返回给客户端
echo json_encode($response);
?>

 

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。