天之禁单机版充值脚本

天之禁单机版充值脚本

RT:最近在玩天之禁单机版,但是发现有些活动需要充值,又没找到代金券,所以自己写了个充值脚本

<?php
// 设置时区
date_default_timezone_set('Asia/Shanghai');

// 获取POST数据
$postData = file_get_contents('php://input');

parse_str($postData, $params);


$logData .= "POST数据:\n";
$logData .= $postData . "\n";
$logData .= str_repeat("-", 50) . "\n\n";

// 保存到文件
$result = file_put_contents('1.txt', $logData, FILE_APPEND | LOCK_EX);

$order_no = "order_".date("Ymd")."_".time().rand(1,100);
$callback_url = 'http://127.0.0.1:8190/'; // 游戏服务器回调地址
$private_key = 'miyao'; // 需要与游戏服务器一致
$params1 = [
    'order_no' => $order_no,           // 充值订单号
    'role_id' => $params['role_id'],             // 角色ID
    'goods_id' => $params['goods_id'],           // 商品ID
    'goods_type' => 1,       // 商品类型
    'goods_ext' => "",         // 商品扩展数据
    'total_fee' => $params['total_fee'],         // 订单金额(单位:分)
    'item_id' => 0,             // 待发放道具ID
    'game_money' =>$params['total_fee'],       // 待发放游戏货币数
    'ext_param' => "internal",         // 透传扩展参数
    'goods_code' => $params['goods_code'],       // 商品扩展Code
    'goods_name' => $params['goods_name'],       // 商品名称
    'money_type' => $params['fee_type'],       // 货币类型
    'notify_time' => date('Y-m-d H:i:s'),            // 异步通知时间
    'notify_id' => 'NOTIFY_' . time() . rand(1000, 9999), // 异步通知ID
    'trade_no' => $order_no,           // 第三方支付订单号
    'trade_status' => 1,                             // 支付状态: 1=成功
];

// 发送回调
$result = send_callback($callback_url, $params1, $private_key);
// 返回响应
if ($result !== false) {
    header('Content-Type: application/json; charset=utf-8');
    echo json_encode([
        'state' => 1,
        'data'=>[
            "order_no"=>$order_no,
            "role_id"=>$params['role_id'],
            "goods_id"=>$params['goods_id'],
            ],
        'msg' => '下单成功',
        'code' => 200
    ]);
} else {
    header('Content-Type: application/json; charset=utf-8');
    http_response_code(500);
    echo json_encode([
        'state' => -1,
        'msg' => '下单失败',
        'code' => 0
    ]);
}
function send_callback($callback_url, $params, $private_key) {
    // 添加签名参数
    $params['sign_type'] = 'md5';
    $params['sign'] = generate_sign($params, $private_key);
    
    log_message("发送参数: " . json_encode($params, JSON_UNESCAPED_UNICODE));
    
    // 构建GET请求URL
    $query_string = http_build_query($params);
    $request_url = $callback_url . '?' . $query_string;
    
    log_message("请求URL: " . $request_url);
    
    // 发送GET请求
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, $request_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'User-Agent: PlatformServer/1.0'
    ]);
    
    // 如果是HTTPS,添加SSL选项
    if (strpos($callback_url, 'https://') === 0) {
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    }
    
    // 执行请求
    $response = curl_exec($ch);
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $error = curl_error($ch);
    
    curl_close($ch);
    
    // 记录响应
    log_message("HTTP状态码: {$http_code}");
    log_message("响应内容: {$response}");
    
    if ($error) {
        log_message("cURL错误: {$error}", 'ERROR');
    }
    
    return [
        'success' => ($http_code == 200 && trim($response) == 'SUCCESS'),
        'http_code' => $http_code,
        'response' => $response,
        'error' => $error
    ];
}
function generate_sign($params, $private_key) {
    // 移除sign和sign_type字段
    unset($params['sign']);
    unset($params['sign_type']);
    
    // 移除空值
    $filtered_params = array();
    foreach ($params as $key => $value) {
        if ($value !== '' && $value !== null) {
            $filtered_params[$key] = $value;
        }
    }
    
    // 按键名排序
    ksort($filtered_params);
    
    // 拼接字符串
    $sign_str = '';
    $i = 0;
    $count = count($filtered_params);
    foreach ($filtered_params as $key => $value) {
        $sign_str .= $key . '=' . $value;
        if (++$i < $count) {
            $sign_str .= '&';
        }
    }
    
    // 加上私钥
    $sign_str .= $private_key;
    
    log_message("签名字符串: {$sign_str}", 'DEBUG');
    
    // 生成MD5签名
    return md5($sign_str);
}
function log_message($message, $type = 'INFO') {
    $log_file = 'notify_' . date('Y-m-d') . '.log';
    $log_msg = date('Y-m-d H:i:s') . " [{$type}] " . $message . PHP_EOL;
    file_put_contents($log_file, $log_msg, FILE_APPEND);
    echo $log_msg;
}
?>

 

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容