IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Dupliquer correctement des informations


Sujet :

Langage PHP

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Intégrateur Web
    Inscrit en
    Mai 2018
    Messages
    57
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Intégrateur Web
    Secteur : Services de proximité

    Informations forums :
    Inscription : Mai 2018
    Messages : 57
    Points : 28
    Points
    28
    Par défaut Dupliquer correctement des informations
    Bonjour,

    Après avoir tout essayé, je ne vois pas comment réussir à dupliquer correctement la balise <skybillValue>
    Le but étant d'obtenir cela :

    <skybillValue>
    ....................
    </skybillValue>
    <skybillValue>
    ...................
    </skybillValue>
    Cela a pour but de créer 2 fichiers en pdf mais il ne me crée toujours qu'un seul fichier.
    J'ai créé 2 fichiers comme ci-dessous :

    informations.php
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    $shipping->skybillValue->productCode = $_POST['choix'];            
    $shipping->skybillValue->shipDate = date('c');        
    $shipping->skybillValue->shipHour = date('G');
    $shipping->skybillValue->weight = $_POST['poids'];
    $shipping->skybillValue->service = '0';              
    $shipping->skybillValue->objectType = $_POST['march'];  
    $shipping->skybillValue->bulkNumber = 2;  
     
    $shipping->skybillValue1->productCode = $_POST['choix'];            
    $shipping->skybillValue1->shipDate = date('c');         
    $shipping->skybillValue1->shipHour = date('G');
    $shipping->skybillValue1->weight = $_POST['poids'];
    $shipping->skybillValue1->service = '0';                 
    $shipping->skybillValue1->objectType = $_POST['march'];  
    $shipping->skybillValue1->bulkNumber = 2;
    traitement.php
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    class SkybillValue
    {
        public $bulkNumber = 2;       
        public $codCurrency = 'EUR';   
        public $codValue;               
        public $content1;           
        public $content2;             
        public $content3;             
        public $content4;              
        public $content5;              
        public $customsCurrency;      
        public $customsValue;          
        public $evtCode = 'DC';         
        public $insuredCurrency;        
        public $insuredValue; 
    }     
    class SkybillValue1
    {
        public $bulkNumber = 2;       
        public $codCurrency = 'EUR';   
        public $codValue;               
        public $content1;           
        public $content2;             
        public $content3;             
        public $content4;              
        public $content5;              
        public $customsCurrency;      
        public $customsValue;          
        public $evtCode = 'DC';         
        public $insuredCurrency;        
        public $insuredValue; 
    } 
     
            public $skybillValue;
    	public $skybillValue1;  
     
    public function __construct()
        {
            //$this->esdValue = new EsdValue();
            $this->headerValue = new HeaderValue();
            $this->shipperValue = new ShipperValue();
            $this->customerValue = new CustomerValue();
            $this->recipientValue = new RecipientValue();
            $this->refValue = new refValue();
            $this->skybillValue = new SkybillValue();
    	$this->skybillValue = new SkybillValue1();
            $this->skybillParamsValue = new SkybillParamsValue();
        }
    J'ai certainement fait une erreur quelque part qui empêche la création des 2 fichiers mais je ne vois pas où.

    Merci de votre aide.

  2. #2
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 091
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 091
    Points : 8 194
    Points
    8 194
    Billets dans le blog
    17
    Par défaut
    J'ai certainement fait une erreur quelque part qui empêche la création des 2 fichiers mais je ne vois pas ou.
    Je vois surtout une erreur de conception pour le moment.

    Le bout de code donné n'a ni queue ni tête, il y a même

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    public $skybillValue;
    public $skybillValue1;
    Qui ne sont pas dans une class.

    Le simple fait d'avoir :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    class SkybillValue { ... }
    class SkybillValue1 { ... }
    Indique qu'il y a un problème de conception et qu'un tableau devrait être utilisé.

    N'en sachant pas plus, il me sera difficile d'en dire davantage
    Un problème exposé clairement est déjà à moitié résolu
    Keep It Smart and Simple

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Intégrateur Web
    Inscrit en
    Mai 2018
    Messages
    57
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Intégrateur Web
    Secteur : Services de proximité

    Informations forums :
    Inscription : Mai 2018
    Messages : 57
    Points : 28
    Points
    28
    Par défaut
    Enfaite j'ai un fichier informations.php avec ce code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    <?php
    require_once 'traitement.php';
     
    $shipping = new Shipping();
     
    $shipping->skybillValue->productCode = $_POST['choix'];            
    $shipping->skybillValue->shipDate = date('c');        
    $shipping->skybillValue->shipHour = date('G');
    $shipping->skybillValue->weight = $_POST['poids'];
    $shipping->skybillValue->service = '0';              
    $shipping->skybillValue->objectType = $_POST['march'];  
    $shipping->skybillValue->bulkNumber = 2;  
     
    $shipping->skybillValue1->productCode = $_POST['choix'];            
    $shipping->skybillValue1->shipDate = date('c');         
    $shipping->skybillValue1->shipHour = date('G');
    $shipping->skybillValue1->weight = $_POST['poids'];
    $shipping->skybillValue1->service = '0';                 
    $shipping->skybillValue1->objectType = $_POST['march'];  
    $shipping->skybillValue1->bulkNumber = 2;
     
    $client = new Chronopost();
     
    try {
        $result = $client->genereEtiquette($shipping);
    } catch (SoapFault $soapFault) {
        var_dump($soapFault);
        exit($soapFault->faultstring);
    }
     
    if ($result->return->errorCode) {
        echo 'Erreur n° ' . $result->return->errorCode . ' : ' . $result->return->errorMessage;
        var_dump($result);
    } else {
        $fp = fopen(''.$_POST['commande'].'.pdf', 'w');
        fwrite($fp, $result->return->skybill);
        fclose($fp);
        echo 'OK';
    	header('Location: '.$_POST['commande'].'.pdf');
    }
    ?>
    Et un fichier traitement.php avec ce code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    <?php
     
    class SkybillValue
    {
        public $bulkNumber = 2;       
        public $codCurrency = 'EUR';   
        public $codValue;               
        public $content1;           
        public $content2;             
        public $content3;             
        public $content4;              
        public $content5;              
        public $customsCurrency;      
        public $customsValue;          
        public $evtCode = 'DC';         
        public $insuredCurrency;        
        public $insuredValue; 
    }     
    class SkybillValue1
    {
        public $bulkNumber = 2;       
        public $codCurrency = 'EUR';   
        public $codValue;               
        public $content1;           
        public $content2;             
        public $content3;             
        public $content4;              
        public $content5;              
        public $customsCurrency;      
        public $customsValue;          
        public $evtCode = 'DC';         
        public $insuredCurrency;        
        public $insuredValue; 
    } 
     
            public $skybillValue;
    	public $skybillValue1;  
     
    public function __construct()
        {
            //$this->esdValue = new EsdValue();
            $this->headerValue = new HeaderValue();
            $this->shipperValue = new ShipperValue();
            $this->customerValue = new CustomerValue();
            $this->recipientValue = new RecipientValue();
            $this->refValue = new refValue();
            $this->skybillValue = new SkybillValue();
    	$this->skybillValue = new SkybillValue1();
            $this->skybillParamsValue = new SkybillParamsValue();
        }
     
    class ShippingResponse
    {
        public $return; // resultExpeditionValue
    }
     
     
    class Chronopost
    {
        const WSDL_SHIPPING_SERVICE = "https://ws.chronopost.fr/shipping-cxf/ShippingServiceWS?wsdl";
     
        public function __construct()
        {
            // Check is SOAP is available
            if (!extension_loaded('soap')) {
                die('The SOAP extension is not available or configured on the server ; The module will not work without this extension ! Please contact your host to activate it in your PHP installation.');
            }
        }
     
     
        /**
         * Génère une étiquette
         *
         * @param Shipping $parameters
         * @return ShippingResponse
         * @throws SoapFault
         */
        public function genereEtiquette(Shipping $params)
        {
            $client_ch = new soapClient(self::WSDL_SHIPPING_SERVICE);
            $client_ch->soap_defencoding = 'UTF-8';
            $client_ch->decode_utf8 = false;
     
            return $client_ch->shipping($params);
        }
    }
    ?>
    Actuellement cela fonction pour 1 colis soit une étiquette mais pas pour plus.
    le but est d'avoir :
    <skybillValue>
    etiquette 1
    </skybillValue>
    <skybillValue>
    etiquette 2
    </skybillValue>
    Je n'arrive pas a avoir plus d'une étiquette.
    Quel chose doivent être modifier pour y arriver ?

  4. #4
    Nouveau membre du Club
    Homme Profil pro
    Intégrateur Web
    Inscrit en
    Mai 2018
    Messages
    57
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Intégrateur Web
    Secteur : Services de proximité

    Informations forums :
    Inscription : Mai 2018
    Messages : 57
    Points : 28
    Points
    28
    Par défaut
    Bonjour,

    Je suis reparti de zéro et j'ai maintenant des tableaux.
    Mais le souci reste le même car je dois dupliquer la structure skybillValue autant de fois qu'il y a de colis.
    quand je place 2 x la structure skybillValue, ca plante.
    Comment faire ?

    Voici le code.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
     
    try
     
    {
     
    $date=date('Y-m-d\TH:i:s\+02:00');
    $client=new SoapClient("http://ws.chronopost.fr/shipping-cxf/ShippingServiceWS?wsdl",array("trace" => 1, "exception" => 0));
     
    $array = array(
       'headerValue' => array(
          'idEmit' => 'CHRFR',
          'accountNumber' => '',
    	  'subAccount'=>''
          ),
       'shipperValue' => array(
          'shipperCivility' => 'M',
          'shipperName' => 'EXPEDITEUR',
          'shipperName2' => '',
          'shipperAdress1' => 'RUE EXPEDITEUR',
          'shipperAdress2' => '',
          'shipperZipCode' => '75001',
          'shipperCity' => 'PARIS',
          'shipperCountry' => 'FR',
    	  'shipperCountryName'=>'FRANCE',
    	  'shipperEmail'=>'mail@expediteur.fr',
    	  'shipperPreAlert'=>'0'
          ),
       'customerValue' => array(
          'customerCivility' => 'M',
          'customerName' => 'DONNEUR ORDRE',
          'customerName2' => '',
          'customerAdress1' => 'RUE DONNEUR ORDRE',
          'customerAdress2' => '',
          'customerZipCode' => '75001',
          'customerCity' => 'PARIS',
          'customerCountry' => 'FR',
    	  'customerCountryName'=>'FRANCE',
          'customerEmail' => 'mail@donneurordre.fr',
          'customerPhone' => '0999999999',
          'customerMobilePhone' => '0999999999',
    	  'customerPreAlert'=>'0'
          ),
       'recipientValue' => array(
          'recipientName' => 'DESTINATAIRE',
          'recipientName2' => '',
          'recipientAdress1' => 'RUE DESTINATAIRE',
          'recipientAdress2' => '',
          'recipientZipCode' => '31000',
          'recipientCity' => 'TOULOUSE',
          'recipientCountry' => 'FR',
    	  'recipientCountryName'=>'FRANCE',
          'recipientEmail' => 'mail@destinataire.fr',
          'recipientPhone' => '0999999999',
          'recipientMobilePhone' => '0999999999',
    	  'recipientPreAlert'=>'0'
          ),
       'refValue' => array(
          'shipperRef' => 'REF EXPEDITEUR',
          'recipientRef' => 'REF DESTINATAIRE'
          ),
    	'skybillValue' => array(
    	  'bulkNumber' => '2',
          'productCode' => '01',
          'shipDate' =>$date,
          'shipHour' => '11',
          'evtCode'=>'DC',
          'weight' => '5',
          'weightUnit' => 'KGM',
          'service' => '0',
          'objectType' => 'MAR',
    	  'skybillRank' => '1',
          'height' => '150',
          'length' => '20',
          'width' => '25',
    	  'objectType'=>'MAR'
          ),
        'skybillValue' => array(
    	  'bulkNumber' => '2',
          'productCode' => '01',
          'shipDate' =>$date,
          'shipHour' => '11',
          'evtCode'=>'DC',
          'weight' => '5',
          'weightUnit' => 'KGM',
          'service' => '0',
          'objectType' => 'MAR',
    	  'skybillRank' => '1',
          'height' => '150',
          'length' => '20',
          'width' => '25',
    	  'objectType'=>'MAR'
          ),
       'skybillParamsValue' => array(
          'mode' => 'PDF',
    	  'withReservation'=>'0',
    	 ),
         'password' => '',
         'modeRetour' => '2',
         'numberOfParcel' => '2',
    	 'multiParcel'=>'Y',
    	 'version'=>'2.0',
          );
     
    var_dump($array);

  5. #5
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 091
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 091
    Points : 8 194
    Points
    8 194
    Billets dans le blog
    17
    Par défaut
    Ta structure n'est pas bonne, dans ton tableau tu as 2 éléments à la clef "skybillValue" => Le 1er est écrasé par le 2nd

    Si tu as plusieurs "skybillValue" il faut les places dans un tableau, ça pourrait donner :

    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
     
    $array = array(
        'headerValue' => [...],
        'shipperValue' => [...],
        'customerValue' => [...],
        'recipientValue' => [...],
        'refValue' => [...],
        // Tableau de skybillValue
        'skybillValues' => [ 
            0 => array(
                'bulkNumber' => '2',
                'productCode' => '01',
                'shipDate' =>$date,
                'shipHour' => '11',
                'evtCode'=>'DC',
                'weight' => '5',
                'weightUnit' => 'KGM',
                'service' => '0',
                'objectType' => 'MAR',
                'skybillRank' => '1',
                'height' => '150',
                'length' => '20',
                'width' => '25',
                'objectType'=>'MAR'
            ),
            1 => array(
                'bulkNumber' => '2',
                'productCode' => '01',
                'shipDate' =>$date,
                'shipHour' => '11',
                'evtCode'=>'DC',
                'weight' => '5',
                'weightUnit' => 'KGM',
                'service' => '0',
                'objectType' => 'MAR',
                'skybillRank' => '1',
                'height' => '150',
                'length' => '20',
                'width' => '25',
                'objectType'=>'MAR'
            )
        ],
        'skybillParamsValue' => [...],
        'password' => '',
        'modeRetour' => '2',
        'numberOfParcel' => '2',
        'multiParcel'=>'Y',
        'version'=>'2.0',
    );


    PS : utilise la syntaxe tableau courte avec des [ ] plutôt que la vieille syntaxe avec array(), c'est plus lisible
    Un problème exposé clairement est déjà à moitié résolu
    Keep It Smart and Simple

  6. #6
    Nouveau membre du Club
    Homme Profil pro
    Intégrateur Web
    Inscrit en
    Mai 2018
    Messages
    57
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Intégrateur Web
    Secteur : Services de proximité

    Informations forums :
    Inscription : Mai 2018
    Messages : 57
    Points : 28
    Points
    28
    Par défaut
    J'ai modifié mais en fait j'obtiens :
    <skybillValue>
    0
    1
    </skybillValue>
    Mais je dois avoir en résultat :
    <skybillValue>
    .................. Tableau 0
    </skybillValue>
    <skybillValue>
    .................. Tableau 1
    </skybillValue>
    Comment faire pour avoir ce type de résultat.

    Merci,
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
     
    <?php
     
    try
     
    {
     
    $date=date('Y-m-d\TH:i:s\+02:00');
    $client=new SoapClient("http://ws.chronopost.fr/shipping-cxf/ShippingServiceWS?wsdl",array("trace" => 1, "exception" => 0));
     
    $array = array(
       'headerValue' => array(
          'idEmit' => 'CHRFR',
          'accountNumber' => '19869502',
    	  'subAccount'=>''
          ),
       'shipperValue' => array(
          'shipperCivility' => 'M',
          'shipperName' => 'EXPEDITEUR',
          'shipperName2' => '',
          'shipperAdress1' => 'RUE EXPEDITEUR',
          'shipperAdress2' => '',
          'shipperZipCode' => '75001',
          'shipperCity' => 'PARIS',
          'shipperCountry' => 'FR',
    	  'shipperCountryName'=>'FRANCE',
    	  'shipperEmail'=>'mail@expediteur.fr',
    	  'shipperPreAlert'=>'0'
          ),
       'customerValue' => array(
          'customerCivility' => 'M',
          'customerName' => 'DONNEUR ORDRE',
          'customerName2' => '',
          'customerAdress1' => 'RUE DONNEUR ORDRE',
          'customerAdress2' => '',
          'customerZipCode' => '75001',
          'customerCity' => 'PARIS',
          'customerCountry' => 'FR',
    	  'customerCountryName'=>'FRANCE',
          'customerEmail' => 'mail@donneurordre.fr',
          'customerPhone' => '0999999999',
          'customerMobilePhone' => '0999999999',
    	  'customerPreAlert'=>'0'
          ),
       'recipientValue' => array(
          'recipientName' => 'DESTINATAIRE',
          'recipientName2' => '',
          'recipientAdress1' => 'RUE DESTINATAIRE',
          'recipientAdress2' => '',
          'recipientZipCode' => '31000',
          'recipientCity' => 'TOULOUSE',
          'recipientCountry' => 'FR',
    	  'recipientCountryName'=>'FRANCE',
          'recipientEmail' => 'mail@destinataire.fr',
          'recipientPhone' => '0999999999',
          'recipientMobilePhone' => '0999999999',
    	  'recipientPreAlert'=>'0'
          ),
       'refValue' => array(
          'shipperRef' => 'REF EXPEDITEUR',
          'recipientRef' => 'REF DESTINATAIRE'
          ),
    	'skybillValue' => [ 
            0 => array(
                'bulkNumber' => '2',
                'productCode' => '01',
                'shipDate' =>$date,
                'shipHour' => '11',
                'evtCode'=>'DC',
                'weight' => '5',
                'weightUnit' => 'KGM',
                'service' => '0',
                'objectType' => 'MAR',
                'skybillRank' => '1',
                'height' => '150',
                'length' => '20',
                'width' => '25',
                'objectType'=>'MAR'
            ),
            1 => array(
                'bulkNumber' => '2',
                'productCode' => '01',
                'shipDate' =>$date,
                'shipHour' => '11',
                'evtCode'=>'DC',
                'weight' => '5',
                'weightUnit' => 'KGM',
                'service' => '0',
                'objectType' => 'MAR',
                'skybillRank' => '2',
                'height' => '150',
                'length' => '20',
                'width' => '25',
                'objectType'=>'MAR'
            )
        ],
       'skybillParamsValue' => array(
          'mode' => 'PDF',
    	  'withReservation'=>'0',
    	 ),
         'password' => '255562',
         'modeRetour' => '2',
         'numberOfParcel' => '2',
    	 'multiParcel'=>'Y',
    	 'version'=>'2.0',
          );
     
    var_dump($array);
     
    $result=$client->shippingMultiParcelV4($array);
     
     
    $binaire=$result->return->resultMultiParcelValue->pdfEtiquette;
    $filename=$result->return->resultMultiParcelValue->skybillNumber.'.pdf';
     
     
     
    $fichier=fopen($filename,"w+");
    fwrite($fichier,$binaire);
    fclose($fichier);
     
     
    // Header content type 
    header('Content-type: application/pdf'); 
    header('Content-Disposition: inline; filename="' . $filename . '"'); 
    header('Content-Transfer-Encoding: binary'); 
    header('Accept-Ranges: bytes'); 
    @readfile($filename); 
     
     
     
    }
     
    catch(Exception $e)
     
    {
     
        die('Erreur : '.$e->getMessage());
     
    }
     
    ?>

  7. #7
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 091
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 091
    Points : 8 194
    Points
    8 194
    Billets dans le blog
    17
    Par défaut
    Comment faire pour avoir ce type de résultat.
    Il faudra sûrement adapter tes fonctions qui traitent $array.
    Un problème exposé clairement est déjà à moitié résolu
    Keep It Smart and Simple

  8. #8
    Nouveau membre du Club
    Homme Profil pro
    Intégrateur Web
    Inscrit en
    Mai 2018
    Messages
    57
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Intégrateur Web
    Secteur : Services de proximité

    Informations forums :
    Inscription : Mai 2018
    Messages : 57
    Points : 28
    Points
    28
    Par défaut
    Peut être faudrait il que je crée plusieurs tableaux comme cela ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $result=$client->shippingMultiParcelV4($debut, $array1, $array2, $fin);

  9. #9
    Nouveau membre du Club
    Homme Profil pro
    Intégrateur Web
    Inscrit en
    Mai 2018
    Messages
    57
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Intégrateur Web
    Secteur : Services de proximité

    Informations forums :
    Inscription : Mai 2018
    Messages : 57
    Points : 28
    Points
    28
    Par défaut
    Je viens d'essayer ,ca ne marche pas non plus.
    Apparemment les données ne son pas envoyer correctement vers le serveur.
    Avez-vous une solution qui peut être applicable ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
     
    <?php
     
    try
     
    {
     
    $date=date('Y-m-d\TH:i:s\+02:00');
    $client=new SoapClient("http://ws.chronopost.fr/shipping-cxf/ShippingServiceWS?wsdl",array("trace" => 1, "exception" => 0));
     
    $debut = array(
       'headerValue' => array(
          'idEmit' => 'CHRFR',
          'accountNumber' => '19869502',
    	  'subAccount'=>''
          ),
       'shipperValue' => array(
          'shipperCivility' => 'M',
          'shipperName' => 'EXPEDITEUR',
          'shipperName2' => '',
          'shipperAdress1' => 'RUE EXPEDITEUR',
          'shipperAdress2' => '',
          'shipperZipCode' => '75001',
          'shipperCity' => 'PARIS',
          'shipperCountry' => 'FR',
    	  'shipperCountryName'=>'FRANCE',
    	  'shipperEmail'=>'mail@expediteur.fr',
    	  'shipperPreAlert'=>'0'
          ),
       'customerValue' => array(
          'customerCivility' => 'M',
          'customerName' => 'DONNEUR ORDRE',
          'customerName2' => '',
          'customerAdress1' => 'RUE DONNEUR ORDRE',
          'customerAdress2' => '',
          'customerZipCode' => '75001',
          'customerCity' => 'PARIS',
          'customerCountry' => 'FR',
    	  'customerCountryName'=>'FRANCE',
          'customerEmail' => 'mail@donneurordre.fr',
          'customerPhone' => '0999999999',
          'customerMobilePhone' => '0999999999',
    	  'customerPreAlert'=>'0'
          ),
       'recipientValue' => array(
          'recipientName' => 'DESTINATAIRE',
          'recipientName2' => '',
          'recipientAdress1' => 'RUE DESTINATAIRE',
          'recipientAdress2' => '',
          'recipientZipCode' => '31000',
          'recipientCity' => 'TOULOUSE',
          'recipientCountry' => 'FR',
    	  'recipientCountryName'=>'FRANCE',
          'recipientEmail' => 'mail@destinataire.fr',
          'recipientPhone' => '0999999999',
          'recipientMobilePhone' => '0999999999',
    	  'recipientPreAlert'=>'0'
          ),
       'refValue' => array(
          'shipperRef' => 'REF EXPEDITEUR',
          'recipientRef' => 'REF DESTINATAIRE'
          ),
    	  );
     
    	$array2 = array(
    	'skybillValue' => array(
                'bulkNumber' => '2',
                'productCode' => '01',
                'shipDate' =>$date,
                'shipHour' => '11',
                'evtCode'=>'DC',
                'weight' => '5',
                'weightUnit' => 'KGM',
                'service' => '0',
                'objectType' => 'MAR',
                'skybillRank' => '1',
                'height' => '150',
                'length' => '20',
                'width' => '25',
                'objectType'=>'MAR'
            ),
    		);
    		$array3 = array(
    	'skybillValue' => array(
                'bulkNumber' => '2',
                'productCode' => '01',
                'shipDate' =>$date,
                'shipHour' => '11',
                'evtCode'=>'DC',
                'weight' => '5',
                'weightUnit' => 'KGM',
                'service' => '0',
                'objectType' => 'MAR',
                'skybillRank' => '2',
                'height' => '150',
                'length' => '20',
                'width' => '25',
                'objectType'=>'MAR'
            ),
    		);
    	$fin = array(
       'skybillParamsValue' => array(
          'mode' => 'PDF',
    	  'withReservation'=>'0',
    	 ),
     
         'password' => '255562',
         'modeRetour' => '2',
         'numberOfParcel' => '2',
    	 'multiParcel'=>'Y',
    	 'version'=>'2.0',
          );
     
    var_dump($debut, $array2, $array3, $fin);
     
    $result=$client->shippingMultiParcelV4($debut, $array2, $array3, $fin);
     
     
    $binaire=$result->return->resultMultiParcelValue->pdfEtiquette;
    $filename=$result->return->resultMultiParcelValue->skybillNumber.'.pdf';
     
     
     
    $fichier=fopen($filename,"w+");
    fwrite($fichier,$binaire);
    fclose($fichier);
     
     
    // Header content type 
    header('Content-type: application/pdf'); 
    header('Content-Disposition: inline; filename="' . $filename . '"'); 
    header('Content-Transfer-Encoding: binary'); 
    header('Accept-Ranges: bytes'); 
    @readfile($filename); 
     
     
     
    }
     
    catch(Exception $e)
     
    {
     
        die('Erreur : '.$e->getMessage());
     
    }
     
    ?>

  10. #10
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 091
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 091
    Points : 8 194
    Points
    8 194
    Billets dans le blog
    17
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $result=$client->shippingMultiParcelV4($debut, $array1, $array2, $fin);
    Les tableaux permettent JUSTEMENT d'éviter d'avoir à faire des $array1, $array2, $array3, $array4, $array5, $array6, $array7, $array8, $array9, $array10, $array11, $array12, $array13, etc.

    Avez-vous une solution qui peut être applicable ?
    Ben je te l'ai déjà dit. Tu utilises un tableau, c'est bien. Maintenant il faut l'exploiter, et comme tu ne donnes pas ton code pour qu'on voit ce qui s'y passe on ne peut rien faire de plus pour toi.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $result=$client->shippingMultiParcelV4($array);
    Il se passe quoi ici ? As-tu adapté shippingMultiParcelV4() pour que le tableau $array['shippingValues'] soit traité correctement ?
    Un problème exposé clairement est déjà à moitié résolu
    Keep It Smart and Simple

  11. #11
    Nouveau membre du Club
    Homme Profil pro
    Intégrateur Web
    Inscrit en
    Mai 2018
    Messages
    57
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Intégrateur Web
    Secteur : Services de proximité

    Informations forums :
    Inscription : Mai 2018
    Messages : 57
    Points : 28
    Points
    28
    Par défaut
    Enfaite je n'est pas accès a shippingMultiParcelV4().
    Le fichier se trouve sur le serveur de La Poste.
    Le code que j'ai mis est l'intégralité du code de mon coté.
    Mais apparemment cela n'est pas possible de le faire en PHP.
    La solution serait de faire du cURL.

  12. #12
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 091
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 091
    Points : 8 194
    Points
    8 194
    Billets dans le blog
    17
    Par défaut
    Ah mais c'est un webservice La Poste / Chronopost qui te génère tes fichiers.

    Il faut voir les possibilités offertes par le webservice et s'y conformer.

    Où est la doc de ce webservice ?
    Un problème exposé clairement est déjà à moitié résolu
    Keep It Smart and Simple

  13. #13
    Nouveau membre du Club
    Homme Profil pro
    Intégrateur Web
    Inscrit en
    Mai 2018
    Messages
    57
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Intégrateur Web
    Secteur : Services de proximité

    Informations forums :
    Inscription : Mai 2018
    Messages : 57
    Points : 28
    Points
    28
    Par défaut
    Enfaite j'ai réussi à faire plusieurs étiquettes mais je bloque encore sur la possibilité de faire un foreach sur <skybillValue>.
    Impossible de placer du PHP dans le code.

    Voici le code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
     
    <?php
     
    try
     
    {
     
    $xml='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cxf="http://cxf.shipping.soap.chronopost.fr/">
       <soapenv:Header/>
       <soapenv:Body>
          <cxf:shippingMultiParcelV4>
             <headerValue>
        		  <accountNumber>19869502</accountNumber>
                <idEmit>CHRFR</idEmit>
                <identWebPro></identWebPro>
                <subAccount></subAccount>
             </headerValue>
             <shipperValue>
                <shipperAdress1>ADRESSE EXPEDITEUR</shipperAdress1>
                <shipperAdress2></shipperAdress2>
                <shipperCity>PARIS</shipperCity>
                <shipperCivility>M</shipperCivility>
                <shipperContactName>NOM CONTACT</shipperContactName>
                <shipperCountry>FR</shipperCountry>
                <shipperCountryName>FRANCE</shipperCountryName>
                <shipperEmail>adresse@mail.fr</shipperEmail>
                <shipperMobilePhone></shipperMobilePhone>
                <shipperName>NOM EXPEDITEUR</shipperName>
                <shipperName2></shipperName2>
                <shipperPhone>0102030405</shipperPhone>
                <shipperPreAlert>0</shipperPreAlert>
                <shipperZipCode>75002</shipperZipCode>
                <shipperType>1</shipperType>
             </shipperValue>
             <customerValue>
                <customerAdress1>'.$_POST['adresse'].'</customerAdress1>
                <customerAdress2></customerAdress2>
                <customerCity>'.$_POST['ville'].'</customerCity>
                <customerCivility>M</customerCivility>
                <customerContactName>'.$_POST['entreprise'].'</customerContactName>
                <customerCountry>'.$_POST['ab'].'</customerCountry>
                <customerCountryName>'.$_POST['pays'].'</customerCountryName>
                <customerEmail>'.$_POST['email'].'</customerEmail>
                <customerMobilePhone></customerMobilePhone>
                <customerName>'.$_POST['entreprise'].'</customerName>
                <customerName2></customerName2>
                <customerPhone>0600000000</customerPhone>
                <customerPreAlert>0</customerPreAlert>
                <customerZipCode>'.$_POST['cp'].'</customerZipCode>
                <printAsSender>N</printAsSender>
             </customerValue>
             <recipientValue>
                <recipientName>'.$_POST['entreprise'].'</recipientName>
    		  <recipientName2></recipientName2>
    		  <recipientAdress1>'.$_POST['adresse'].'</recipientAdress1>
    		  <recipientAdress2></recipientAdress2>
    		  <recipientZipCode>'.$_POST['cp'].'</recipientZipCode>
    		  <recipientCity>'.$_POST['ville'].'</recipientCity>
    		  <recipientCountry>'.$_POST['ab'].'</recipientCountry>
    		  <recipientContactName>'.$_POST['entreprise'].'</recipientContactName>
    		  <recipientEmail>'.$_POST['email'].'</recipientEmail>
    		  <recipientPhone>1234567890</recipientPhone>
    		  <recipientMobilePhone></recipientMobilePhone>
    		  <recipientPreAlert>0</recipientPreAlert>
                <recipientType>2</recipientType>
             </recipientValue>
             <refValue>
                <customerSkybillNumber></customerSkybillNumber>
                <recipientRef>REF DESTINATAIRE</recipientRef>
                <shipperRef>REF EXPEDITEUR</shipperRef>
                <idRelais></idRelais>
             </refValue>
             <skybillValue>
                <bulkNumber>2</bulkNumber>
                <codCurrency>EUR</codCurrency>
                <codValue>0</codValue>
                <content1></content1>
                <content2></content2>
                <content3></content3>
                <content4></content4>
                <content5></content5>
                <customsCurrency>EUR</customsCurrency>
                <customsValue></customsValue>
                <evtCode>DC</evtCode>
                <insuredCurrency>EUR</insuredCurrency>
                <insuredValue>0</insuredValue>
                <latitude></latitude>
                <longitude></longitude>
                <masterSkybillNumber/>
                <objectType>MAR</objectType>
                <portCurrency></portCurrency>
                <portValue>0</portValue>
                <productCode>01</productCode>
                <qualite></qualite>
                <service>0</service>
                <shipDate>2020-07-10</shipDate>
                <shipHour>17</shipHour>
                <skybillRank>1</skybillRank>
                <source></source>
                <weight>10</weight>
                <weightUnit>KGM</weightUnit>
                <height>30</height>
                <length>50</length>
                <width>40</width>
                <as></as>
                <subAccount></subAccount>
                <toTheOrderOf></toTheOrderOf>
                <skybillNumber></skybillNumber>
                <carrier>1</carrier>
                <skybillBackNumber></skybillBackNumber>
                <alternateProductCode></alternateProductCode>
                <labelNumber></labelNumber>
             </skybillValue>
    		 <skybillValue>
                <bulkNumber>2</bulkNumber>
                <codCurrency>EUR</codCurrency>
                <codValue>0</codValue>
                <content1></content1>
                <content2></content2>
                <content3></content3>
                <content4></content4>
                <content5></content5>
                <customsCurrency>EUR</customsCurrency>
                <customsValue></customsValue>
                <evtCode>DC</evtCode>
                <insuredCurrency>EUR</insuredCurrency>
                <insuredValue>0</insuredValue>
                <latitude></latitude>
                <longitude></longitude>
                <masterSkybillNumber/>
                <objectType>MAR</objectType>
                <portCurrency></portCurrency>
                <portValue>0</portValue>
                <productCode>01</productCode>
                <qualite></qualite>
                <service>0</service>
                <shipDate>2020-07-10</shipDate>
                <shipHour>17</shipHour>
                <skybillRank>2</skybillRank>
                <source></source>
                <weight>0</weight>
                <weightUnit>KGM</weightUnit>
                <height>30</height>
                <length>50</length>
                <width>40</width>
                <as></as>
                <subAccount></subAccount>
                <toTheOrderOf></toTheOrderOf>
                <skybillNumber></skybillNumber>
                <carrier>1</carrier>
                <skybillBackNumber></skybillBackNumber>
                <alternateProductCode></alternateProductCode>
                <labelNumber></labelNumber>
             </skybillValue>
             <skybillParamsValue>
                <duplicata>N</duplicata>
                <mode>PDF</mode>
                <withReservation>2</withReservation>
             </skybillParamsValue>
             <password>255562</password>
             <modeRetour>2</modeRetour>
             <numberOfParcel>2</numberOfParcel>
             <version>2.0</version>
             <multiParcel>N</multiParcel>        
          </cxf:shippingMultiParcelV4>
       </soapenv:Body>
    </soapenv:Envelope>';
    $url="http://ws.chronopost.fr/shipping-cxf/ShippingServiceWS";
    $ch = curl_init();
     
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml'));
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13'); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     
    //Récup&ration contenu curl pour gestion des erreurs//
     
    $err     = curl_errno( $ch );
    $errmsg  = curl_error( $ch );
    $response = curl_exec($ch);
    curl_close($ch);
     
    $response = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $response);
    $xml = new \SimpleXMLElement($response);
    $array = json_decode(json_encode((array)$xml), TRUE);
    //print_r($array);
     
     
    $reservationNumber=$array['soapBody']['ns1shippingMultiParcelV4Response']['return']['reservationNumber'];
    //var_dump($reservationNumber);
     
     
    //on va récupérer le ou les étiquettes reservées avec soapClient et getReservedSkybill//
    $client=new SoapClient("http://ws.chronopost.fr/shipping-cxf/ShippingServiceWS?wsdl",array("trace" => 1, "exception" => 0));
     
    $array=array(
    'reservationNumber'=>$reservationNumber,
    'mode'=>'PDF',);
     
    $result=$client->getReservedSkybillWithTypeAndModeByReservation($array);
    $binaire=$result->return->skybill;
    $chaine=base64_decode($binaire);
     
     
    $filename=$reservationNumber.'.pdf';
    $file=$reservationNumber.'.pdf';
    $fichier=fopen($filename,"w+");
    fwrite($fichier,$chaine);
    fclose($fichier);
     
     
    // Header content type 
    header('Content-type: application/pdf'); 
    header('Content-Disposition: inline; filename="' . $filename . '"'); 
    header('Content-Transfer-Encoding: binary'); 
    header('Accept-Ranges: bytes'); 
    @readfile($file); 
     
     
    }
     
    catch(Exception $e)
     
    {
     
        die('Erreur : '.$e->getMessage());
     
    }
     
     
     
    ?>
    Y a t-il un moyen de faire une boucle for pour dupliquer la structure souhaité ?

Discussions similaires

  1. Réponses: 9
    Dernier message: 17/08/2004, 16h16
  2. [C#] Transférer des informations entre 2 formulaires
    Par monoeilouais dans le forum Windows Forms
    Réponses: 2
    Dernier message: 14/07/2004, 17h21
  3. [ENCODAGE][JAVA]Afficher correctement des accents
    Par kornelius dans le forum PostgreSQL
    Réponses: 3
    Dernier message: 17/02/2004, 16h37
  4. Comment récuperer des informations d'un .swf (flash) ?
    Par diado dans le forum API, COM et SDKs
    Réponses: 7
    Dernier message: 12/01/2004, 21h32
  5. Réponses: 6
    Dernier message: 28/09/2003, 17h49

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo