JezK
Edit File: ultrapack_unlock_api.php
<?php /* * _ _ _ _ ____ _ ____ * | | | | | |_ _ __ __ _| _ \ __ _ ___| | ____ _|___ \ * | | | | | __| '__/ _` | |_) / _` |/ __| |/ /\ \ / / __) | * | |_| | | |_| | | (_| | __/ (_| | (__| < \ V / / __/ * \___/|_|\__|_| \__,_|_| \__,_|\___|_|\_\ \_/ |_____| * * Acesse - https://ultrapackv2.com * Desenvolvido por Gustavo - https://t.me/gustta * * Version: 1.2.0 * Plugin version: 3.108.3 */ /* ChangeLog - v1.2.0 - Support to OpenRouter.ai */ if (!defined('ABSPATH')) { exit; } // OpenAI/OpenRoute Route class openaiComplete { public function __construct() { add_action('rest_api_init', array($this, 'register_routes')); } public function register_routes() { register_rest_route('acwap/v1', '/openaiComplete', array( 'methods' => 'POST', 'callback' => array($this, 'generate_openai_content'), 'args' => array( 'prompt' => array('required' => true), 'apiKey' => array('required' => true), 'model' => array('required' => true), 'base' => array('required' => false), 'temperature' => array('required' => false), 'max_tokens' => array('required' => false), ), 'permission_callback' => '__return_true', )); } public function generate_openai_content($request) { $prompt = sanitize_text_field($request['prompt']); $apiKey = sanitize_text_field($request['apiKey']); $model = sanitize_text_field($request['model']); $temperature = sanitize_text_field($request['temperature']) ? (float) sanitize_text_field($request['temperature']) : 0.7; // Randomness of the output $base = sanitize_text_field($request['base']); $max_tokens = sanitize_text_field($request['max_tokens']); if (isset($base) && $base === 'openrouter.ai' ) { $url = 'https://openrouter.ai/api/v1/chat/completions'; } else { $url = 'https://api.openai.com/v1/chat/completions'; } $data = json_encode(array( 'model' => $model, 'messages' => array( array( 'role' => 'user', 'content' => $prompt ) ), 'temperature' => $temperature, )); if ($max_tokens) { $data['max_tokens'] = $max_tokens; } //error_log('Data: ' . print_r($data, true)); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer ' . $apiKey, 'Content-Type: application/json', )); curl_setopt($ch, CURLOPT_TIMEOUT, 120); $response = curl_exec($ch); $curl_error = curl_error($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($curl_error) { //error_log('cURL error: ' . $curl_error); return array('result' => 'Fail to connect to ' . $base . '! Please check your API Key!'); } $data = json_decode($response, true); //error_log('Data: ' . print_r($data, true)); if ($http_code !== 200 || isset($data['error'])) { //error_log('OpenAI API error: ' . print_r($data, true)); return array('result' => 'License is not valid, please check your API Key!'); } if (isset($data['choices'][0]['message']['content'])) { //error_log('OpenAI response: ' . $data['choices'][0]['message']['content']); return array('result' => trim($data['choices'][0]['message']['content'])); } else { //error_log('OpenAI response format unexpected: ' . print_r($data, true)); return array('result' => $base . 'API Key Format is incorrect!'); } } } // DALL-E Route class dalleroute { public function __construct() { add_action('rest_api_init', array($this, 'register_routes')); } public function register_routes() { register_rest_route('acwap/v1', '/dalle', array( 'methods' => 'POST', 'callback' => array($this, 'generate_dalle_image'), 'args' => array( 'prompt' => array('required' => true), 'apiKey' => array('required' => true), 'size' => array('required' => true), ), 'permission_callback' => '__return_true', )); } public function generate_dalle_image($request) { $prompt = sanitize_text_field($request['prompt']); $apiKey = sanitize_text_field($request['apiKey']); $size = sanitize_text_field($request['size']); $url = 'https://api.openai.com/v1/images/generations'; $data = json_encode(array( 'prompt' => $prompt, 'size' => $size, 'n' => 1 // Number of images to generate )); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer ' . $apiKey, 'Content-Type: application/json', )); curl_setopt($ch, CURLOPT_TIMEOUT, 120); $response = curl_exec($ch); $curl_error = curl_error($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($curl_error) { //error_log('cURL error: ' . $curl_error); return array('result' => 'Fail to connect to OpenAI!'); } $data = json_decode($response, true); if ($http_code !== 200 || isset($data['error'])) { //error_log('OpenAI API error: ' . print_r($data, true)); return array('result' => 'License is not valid, please visit the plugin settings page and add your correct purchase code'); } if (isset($data['data'][0]['url'])) { return array('result' => array(array('url' => $data['data'][0]['url']))); } else { //error_log('OpenAI response format unexpected: ' . print_r($data, true)); return array('result' => 'OpenAI Format is incorrect!'); } } } // AliSign Route class aliSignroute { public function __construct() { add_action('rest_api_init', array($this, 'register_routes')); } public function register_routes() { register_rest_route('acwap/v1', '/aliSign', array( 'methods' => 'POST', 'callback' => array($this, 'generate_ali_sign'), 'args' => array( 'token' => array('required' => true), 'time' => array('required' => true), 'appKey' => array('required' => true), 'data' => array('required' => true), ), 'permission_callback' => '__return_true', )); } public function generate_ali_sign($request) { $token = sanitize_text_field($request['token']); $time = sanitize_text_field($request['time']); $appKey = sanitize_text_field($request['appKey']); $data = $request['data']; $decoded_data = json_decode($data, true); if (json_last_error() !== JSON_ERROR_NONE) { //error_log('Failed to decode data payload: ' . json_last_error_msg()); return array('result' => 'Invalid data payload.'); } $normalized_data = json_encode($decoded_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); if ($normalized_data === false) { //error_log('Failed to encode data payload: ' . json_last_error_msg()); return array('result' => 'Data encoding failed.'); } $sign_string = $token . "&" . $time . "&" . $appKey . "&" . $normalized_data; $sign = md5($sign_string); $decoded_data_array = json_decode($data, true); $productId = $decoded_data_array['productId'] ?? null; if (!$productId) { //error_log('Product ID is missing in data payload.'); return array('result' => 'Product ID is missing.'); } $productUrl = "https://www.aliexpress.com/item/{$productId}.html"; $admitad_base_url = get_option('wp_automatic_ali_admitad', ''); if (empty($admitad_base_url)) { //error_log('Admitad base URL is missing. Please configure it in the plugin settings.'); return array('result' => 'Admitad URL not configured.'); } $affiliate_link = $admitad_base_url . '?ulp=' . urlencode($productUrl); return array( 'result' => array( 'sign' => $sign, 'affiliate_link' => $affiliate_link, ), ); } } new openaiComplete(); new dalleroute(); new aliSignroute();