3v4l.org

run code in 500+ PHP versions simultaneously
<?php error_reporting(E_ALL); ini_set('display_errors', 1); class TelecomLogin { private $client_type = "#10.4.5#channel50#iPhone 14 Pro#"; // 字符转换函数 private function transNumber($str, $encode = true) { $result = ''; $offset = $encode ? 2 : -2; for ($i = 0; $i < strlen($str); $i++) { $char = $str[$i]; $result .= chr((ord($char) + $offset) & 0xFF); } return $result; } // RSA加密 private function encrypt($str) { $public_key = "-----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDBkLT15ThVgz6/NOl6s8GNPofd WzWbCkWnkaAm7O2LjkM1H7dMvzkiqdxU02jamGRHLX/ZNMCXHnPcW/sDhiFCBN18 qFvy8g6VYb9QtroI09e176s+ZCtiv7hbin2cCTj99iUpnEloZm19lwHyo69u5UMi PMpq0/XKBO8lYhN/gwIDAQAB -----END PUBLIC KEY-----"; if (!openssl_public_encrypt($str, $encrypted, $public_key, OPENSSL_PKCS1_PADDING)) { throw new Exception("加密失败: " . openssl_error_string()); } return base64_encode($encrypted); } // 执行登录请求 public function getToken($phonenum, $password) { try { // 生成随机参数 $uuid = str_pad(mt_rand(0, 9999999999999999), 16, '0', STR_PAD_LEFT); $ts = date('YmdHis'); // 构建加密字符串 $enc_str = "iPhone 14 13.2." . substr($uuid, 0, 12) . $phonenum . $ts . $password . "0$$$0."; // 生成请求体 $body = [ 'content' => [ 'fieldData' => [ 'accountType' => '', 'authentication' => $this->transNumber($password), 'deviceUid' => substr($uuid, 0, 16), 'isChinatelecom' => '0', 'loginAuthCipherAsymmertric' => $this->encrypt($enc_str), 'loginType' => '4', 'phoneNum' => $this->transNumber($phonenum), 'systemVersion' => '13.2.3', ], 'attach' => 'test' ], 'headerInfos' => [ 'code' => 'userLoginNormal', 'clientType' => $this->client_type, 'timestamp' => $ts, 'shopId' => '20002', 'source' => '110003', 'sourcePassword' => 'Sid98s', 'userLoginName' => $phonenum ] ]; // 发送请求 $url = 'https://appgologin.189.cn:9031/login/client/userLoginNormal'; $response = $this->curlPost($url, $body); // 解析响应 $result = json_decode($response, true); if (json_last_error() !== JSON_ERROR_NONE) { throw new Exception("JSON解析失败: " . json_last_error_msg() . "\n响应原始内容:\n" . $response); } if (isset($result['responseData']['data']['loginSuccessResult']['token'])) { return $result['responseData']['data']['loginSuccessResult']['token']; } else { // 获取错误信息的正确路径 $errorData = $result['responseData']['data']['loginFailResult'] ?? []; $msg = $errorData['resultDesc'] ?? ($result['responseData']['resultDesc'] ?? '未知错误'); $code = $errorData['resultCode'] ?? ($result['responseData']['resultCode'] ?? '未知状态码'); throw new Exception("登录失败 ($code): $msg"); } } catch (Exception $e) { return $e->getMessage(); // 返回异常信息而不是终止脚本 } } private function curlPost($url, $data) { $headers = [ "Accept: application/json", "Content-Type: application/json; charset=UTF-8", "user-agent: iPhone 14 Pro/9.7.0" ]; $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode($data), CURLOPT_HTTPHEADER => $headers, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_TIMEOUT => 15, CURLOPT_VERBOSE => true // 开启详细输出 ]); $response = curl_exec($ch); if ($response === false) { throw new Exception("CURL错误: " . curl_error($ch)); } curl_close($ch); return $response; } } $showResult = false; $isSuccess = false; $resultContent = ''; $phonenum = ''; // 初始化变量 if ($_SERVER['REQUEST_METHOD'] === 'POST') { $phonenum = $_POST['phonenum'] ?? ''; $password = $_POST['password'] ?? ''; $login = new TelecomLogin(); $resultContent = $login->getToken($phonenum, $password); $isSuccess = true; // 假设成功,如果getToken返回异常信息,则在下面修改$isSuccess if (strpos($resultContent, '登录失败') !== false) { $isSuccess = false; } $showResult = true; } ?> <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>电信Token获取</title> <style> body, html { height: 100%; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; } .card { padding: 1.5rem; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; width: 100%; max-width: 500px; margin: 2rem auto; } .form-group { margin-bottom: 1.2rem; } input { width: 100%; padding: 0.8rem; border: 1px solid #ddd; border-radius: 6px; } button { background: #007aff; color: white; width: 100%; padding: 1rem; border: none; border-radius: 6px; font-size: 1rem; cursor: pointer; } .result-box { margin-top: 1.5rem; padding: 1rem; border-radius: 6px; } .success, .error { padding: 1rem; border-radius: 6px; } .success { background: #0dffd8; color: #3c763d; border: 1px solid #d6e9c6; } .error { background: #f2dede; color: #a94442; border: 1px solid #ebccd1; } code { display: block; padding: 0.8rem; margin: 0.5rem 0; background: rgba(0,0,0,0.05); border-radius: 4px; word-break: break-all; } /* Centering content */ .container { display: flex; justify-content: center; align-items: center; height: 100%; } </style> </head> <body> <div class="container"> <div class="card"> <h1 style="margin-top:0; text-align:center">电信认证</h1> <form method="post" onsubmit="return validateForm()"> <div class="form-group"> <input type="text" name="phonenum" placeholder="手机号码" required oninput="this.value = this.value.replace(/[^0-9]/g,'')" onkeypress="return isNumber(event)" onpaste="return false" title="请输入11位手机号码" value="<?= htmlspecialchars($phonenum) ?>" maxlength="11"> </div> <div class="form-group"> <input type="password" name="password" placeholder="登录密码" required oninput="this.value = this.value.replace(/[^0-9]/g,'')" onkeypress="return isNumber(event)" onpaste="return false" title="请输入6位密码" maxlength="6"> </div> <button type="submit">获取Token</button> </form> <?php if ($showResult) : ?> <div class="result-box <?= $isSuccess ? 'success' : 'error' ?>"> <strong><?= $isSuccess ? '获取成功:' : '发生异常:' ?></strong> <code><?= htmlspecialchars($resultContent) ?></code> <?php if ($isSuccess) : ?> <small style="display:block; margin-top:0.5rem; opacity:0.8"> Token有效期通常为7天,请妥善保存 </small> <?php endif; ?> </div> <?php endif; ?> <script> function isNumber(evt) { evt = (evt) ? evt : window.event; var charCode = (evt.which) ? evt.which : evt.keyCode; if (charCode > 31 && (charCode < 48 || charCode > 57)) { return false; } return true; } function validateForm() { var phonenum = document.forms[0]["phonenum"].value; var password = document.forms[0]["password"].value; if (phonenum.length !== 11 || !/^\d+$/.test(phonenum)) { alert("手机号码必须为11位数字"); return false; } if (password.length !== 6 || !/^\d+$/.test(password)) { alert("密码必须为6位数字"); return false; } return true; } </script> </div> </div> </body> </html>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.5.30.0360.00616.82
8.5.20.0340.00816.78
8.5.10.0390.00516.81
8.5.00.0350.00617.06
8.4.180.0330.01319.62
8.4.170.0350.01219.83
8.4.160.0300.00919.77
8.4.150.0340.00919.63
8.4.140.0370.00617.86
8.4.130.0360.00817.94
8.4.120.0350.01017.89
8.4.110.0400.00718.00
8.4.100.0350.01017.86
8.4.90.0330.00817.92
8.4.80.0360.00917.96
8.4.70.0430.01017.91
8.4.60.0330.00818.05
8.4.50.0440.00817.84
8.4.40.0370.00717.89
8.4.30.0350.00917.73
8.4.20.0420.00818.00
8.4.10.0330.00918.01
8.3.300.0350.00918.44
8.3.290.0370.00918.36
8.3.280.0320.00918.54
8.3.270.0350.00816.93
8.3.260.0380.00816.93
8.3.250.0390.00616.95
8.3.240.0330.01216.71
8.3.230.0290.01016.77
8.3.220.0380.00716.55
8.3.210.0340.00916.77
8.3.200.0380.00716.85
8.3.190.0370.00616.85
8.3.180.0370.00816.80
8.3.170.0380.01016.74
8.3.160.0400.01116.69
8.3.150.0310.00716.96
8.3.140.0410.00616.75
8.3.130.0340.01016.85
8.3.120.0290.00816.46
8.3.110.0220.00416.81
8.3.100.0190.00416.70
8.3.90.0190.00216.74
8.3.80.0170.00416.77
8.3.70.0210.00116.77
8.3.60.0180.00316.65
8.3.50.0160.00516.91
8.3.40.0230.00318.00
8.3.30.0300.00418.03
8.3.20.0220.00618.09
8.3.10.0300.00718.10
8.3.00.0280.00818.03

preferences:
50.74 ms | 1137 KiB | 5 Q