Salta al contenuto
  • CATEGORIES
  • La Community Connect.gt
  • Presentati alla Community
  • News Ufficiali da Connect.gt
  • Internet News
  • A Scuola Di
  • Digital Marketing
  • Intelligenza Artificiale
  • SEO & GEO
  • Web Marketing e Content
  • Google Analytics e Web Analytics
  • Google Ads & Advertising
  • YouTube
  • TikTok, Instagram e altri Social
  • Google Adsense, Affiliazioni e Guadagno
  • E-Commerce
  • Coding e Sistemistica
  • Help Center: consigli per il tuo progetto
  • Hosting e Cloud
  • Coding
  • CMS & Piattaforme Self-Hosted
  • Annunci e Collaborazioni
  • Annunci Vendita e Acquisto: Pubblicità, Domini, Link e altro
  • Collaborazioni WEB e Lavoro: offro e cerco
  • Impresa, Fisco e Leggi
  • Consulenza Legale e Professioni Web
  • Consulenza Fiscale, Imprese, Startup e P.Iva
  • Gli Off Topic
  • PC, Smartphone e altri Hardware
  • Tutti i Software
  • GT Fetish Cafè
  • Discussioni
  • 0 Non letti 0
  • Recenti
  • Hashtag
  • Popolare
  • Utenti
  • Privacy
  • Termini e condizioni
  • © 2026 Search On Media Group S.r.l.
Collassa
Connect.gt
Il network Search On
Connect.gt WMF AI Festival Accademia Advanced SEO Tool AgentCy Social Media Strategies Search Tech
Registrati Accedi
Connect.gt
Stream Interest Categorie Hashtag
  1. La community italiana di SEO, marketing digitale e AI
  2. Categorie
  3. Coding e Sistemistica
  4. Coding
  5. Problema importazione dati da remoto via API

Problema importazione dati da remoto via API

Pianificato Fissato Bloccato Spostato Coding
1 Post 1 Autori 595 Visualizzazioni 1 Seguito
  • Da Vecchi a Nuovi
  • Da Nuovi a Vecchi
  • Più Voti
Rispondi
  • Risposta alla discussione
Effettua l'accesso per rispondere
Questa discussione è stata eliminata. Solo gli utenti con diritti di gestione possono vederla.
  • D
    D
    digitalwarrior
    scritto su ultima modifica di
    User 0
    #1
    Problema importazione dati da remoto via API

    Ciao a tutti.
    Sto utilizzando il famoso pannello sentora che utilizza moduli nativi per zpanel.
    Il pannello e i moduli funzionano tutti alla perfezione ma ho un piccolo problema con una funzione e sono sicuro che i più esperti sapranno guidarmi per trovare la soluzione.
    Cercherò di essere più chiaro possibile.

    Omettendo tutto il resto degli script focalizzo l'attenzione unicamente sulle funzioni incriminate cercando di descrivere tutto al meglio.

    1. La funzione "voucherInfo" richiama da remoto la funzione "CheckVoucher".
    function voucherInfo($username, $code){
        global $cfg;
        if($username){
            $xmws = new xmwsclient();
            
            $xmws->InitRequest($cfg['panel_url'], 'xbilling', 'CheckVoucher', $cfg['api_key']);
            $xmws->SetRequestData('<zpx_user>' .$username. '</zpx_user>');
    
            $res = $xmws->XMLDataToArray($xmws->Request($xmws->BuildRequest()));
    
            if ($res['xmws']['response'] != '1101') {
                die("API Error: " . $res['xmws']['content']);
            }
           return $res['xmws']['content']['voucher'];
    //    var_dump($res);
        }
    }
    
    1. La funzione "CheckVoucher" richiama in locale la funzione "getVoucher" che va ad estrapolare i dati dal db.
        public function CheckVoucher(){
        
            $zpx_user = '';
            $request_data = ws_generic::XMLToArray($this->wsdata);
            if(isset($request_data['xmws']['content']['zpx_uid']) && isset($request_data['xmws']['content']['voucher'])){
                $zpx_user = $request_data['xmws']['content']['zpx_uid'];
                $code = $request_data['xmws']['content']['voucher'];
            }
            
            //die(var_dump($request_data));
            
    
            if($zpx_user && $code){
                $response_xml = "\n";
                $voucher_info = module_controller::getVoucher($zpx_user, $code);
                
                //die(var_dump($voucher_exists));
                
                if ($voucher_info){
                        $discount_type = 'Once-Off';
                if($voucher_info['discount_type'] == 2){
                    $discount_type = 'Recurring';
                }
                    $voucher_check['voucher_exists'] = $voucher_exists;
                     $voucher = array('id' => $voucher_info['voucher_id'], 'code' => $voucher_info['voucher_code'], 'discount' => $voucher_info['discount'], 'type' => $discount_type);
                     $response_xml = $response_xml . ws_xmws::NewXMLContentSection('result', $voucher);
                }
    
                $dataobject = new runtime_dataobject();
                $dataobject->addItemValue('response', '');
                $dataobject->addItemValue('content', $response_xml);
    
                return $dataobject->getDataObject();
            }
        }
    
        public function GetPackageName(){
            $pkg_name = '';
            $pkg_id = 0;
            $request_data = ws_generic::XMLToArray($this->wsdata);
            if(isset($request_data['xmws']['content']['package_id'])){
                //$zpx_uid = $request_data['xmws']['content']['zpx_uid'];
                $pkg_id = $request_data['xmws']['content']['package_id'];
            }
            
    
            if($pkg_id){
                $response_xml = "\n";
                $pkg_name = module_controller::GetPackageName($pkg_id);
                
                if (!fs_director::CheckForEmptyValue($pkg_name)) {
                    $package['name'] = $pkg_name;
                     $response_xml = $response_xml . ws_xmws::NewXMLContentSection('package', $package);
                }
    
                $dataobject = new runtime_dataobject();
                $dataobject->addItemValue('response', '');
                $dataobject->addItemValue('content', $response_xml);
    
                return $dataobject->getDataObject();
            }   
        }
    
    1. Qui lo script eseguito dalla funzione "CheckVoucher".
        static function getVouchers(){
            global $zdbh;
            $currentuser = ctrl_users::GetUserDetail();
            $vouchers = $zdbh->prepare("SELECT * FROM ".self::$module_db.".x_vouchers 
                                            WHERE reseller_ac_id_fk=:user_id 
                                            AND voucher_deleted_ts IS NULL;");
            $vouchers->bindParam(':user_id', $currentuser['userid']);
            $vouchers->execute();
            $res = array();
            if (!fs_director::CheckForEmptyValue($vouchers)) {
                while ($row = $vouchers->fetch()) {
                   $active_text = '<span class="label label-danger">No</span>';
                   if($row['active_yn'] == 1){
                       $active_text = '<span class="label label-success">Yes</span>';
                   }
    
                   $usage_type = 'N/A';
                   if($row['usage_type'] == 1){
                       $usage_type = 'Once';
                   } elseif($row['usage_type'] == 2){
                       $usage_type = 'Multiple';
                   }
    
                   $discount_type = 'N/A';
                   if($row['discount_type'] == 1){
                       $discount_type = 'Once-Off';
                   } elseif($row['discount_type'] == 2){
                       $discount_type = 'Recurring';
                   }
                   
    /*               //usages
                   $total_usages = 0;
                $sql = "SELECT COUNT(*) AS total_usages FROM ".self::$module_db.".x_invoices 
                            WHERE invoice_voucher_id=:id AND invoice_deleted_ts IS NULL";
                $numrows = $zdbh->prepare($sql);
                $numrows->bindParam(':id', $row['voucher_id']);
                if ($numrows->execute()) {
                    $voucher_usages = $numrows->fetch();
                    $total_usages = $voucher_usages['total_usages'];
                }
    */               
                   
                   array_push($res, array('code' => $row['voucher_code'],
                                          'discount' => $row['discount'],
                                          'type' => $row['voucher_code'],
                                          'active_text' => $active_text,
                                          'usage_type_text' => $usage_type,
                                          'discount_type_text' => $discount_type,
                                          'total_usages' => self::getVoucherUsages($row['voucher_id']),
                                          'id' => $row['voucher_id']));  
                }
                return $res;
            } else {
                return false;
            }            
        }
    

    Dando per scontato che le funzioni di cui ai punti 2 e 3 funzionino a dovere poiché preesistenti, il mio problema è che non riesco ad ottenere i dati utilizzando lo script fatto da me al punto 1.

    Spero che qualcuno riesca a darmi una mano.
    Saluti

    1 Risposta Ultima Risposta
    Miglior risposta 0
    0

    Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.

    Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.

    Con il tuo contributo, questo post potrebbe essere ancora migliore 💗

    Registrati Accedi
    Rispondi
    • Risposta alla discussione
    Effettua l'accesso per rispondere
    • Da Vecchi a Nuovi
    • Da Nuovi a Vecchi
    • Più Voti


    • Accedi

    • Non hai un account? Registrati

    • Accedi o registrati per effettuare la ricerca.
    • Primo post
      Ultimo post
    Home Accedi Registrati
    Menu
    • CATEGORIES
    • La Community Connect.gt
    • Presentati alla Community
    • News Ufficiali da Connect.gt
    • Internet News
    • A Scuola Di
    • Digital Marketing
    • Intelligenza Artificiale
    • SEO & GEO
    • Web Marketing e Content
    • Google Analytics e Web Analytics
    • Google Ads & Advertising
    • YouTube
    • TikTok, Instagram e altri Social
    • Google Adsense, Affiliazioni e Guadagno
    • E-Commerce
    • Coding e Sistemistica
    • Help Center: consigli per il tuo progetto
    • Hosting e Cloud
    • Coding
    • CMS & Piattaforme Self-Hosted
    • Annunci e Collaborazioni
    • Annunci Vendita e Acquisto: Pubblicità, Domini, Link e altro
    • Collaborazioni WEB e Lavoro: offro e cerco
    • Impresa, Fisco e Leggi
    • Consulenza Legale e Professioni Web
    • Consulenza Fiscale, Imprese, Startup e P.Iva
    • Gli Off Topic
    • PC, Smartphone e altri Hardware
    • Tutti i Software
    • GT Fetish Cafè
    • Discussioni
    • Non letti 0
    • Recenti
    • Hashtag
    • Popolare
    • Utenti
    • Privacy
    • Termini e condizioni
    • © 2026 Search On Media Group S.r.l.