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

Services Web Discussion :

Signature Webservice Amazon


Sujet :

Services Web

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Octobre 2005
    Messages
    49
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 49
    Par défaut Signature Webservice Amazon
    Bonjour,

    Depuis août 2009, le web service d'Amazon a changé et nécessite une authentification par signature. Voici mo code avant août 2009 qui fonctionnait super bien
    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
     
    // Initialisation
    amazonWS = new AmazonWebServices.AWSECommerceService();
    amazonItemSearchRequest = new AmazonWebServices.ItemSearchRequest();
    amazonItemSearch = new AmazonWebServices.ItemSearch();
     
    WebbookCommonTools.amazonItemSearchRequest.SearchIndex = "Books";
    						string[] _strResponseGroup = { "ItemAttributes", "Images" };
     
    WebbookCommonTools.amazonItemSearchRequest.ResponseGroup = _strResponseGroup;
    // Applique le critère si on recherche un auteur ou un livre
    if (strTypeSearch == "Author")
    {
    WebbookCommonTools.amazonItemSearchRequest.Author = strCriteria;
    }
    else
    {
    WebbookCommonTools.amazonItemSearchRequest.Title = strCriteria;
    }
     
    WebbookCommonTools.amazonItemSearch.SubscriptionId = Properties.Settings.Default.AmazonAccessKeyId;
     
    WebbookCommonTools.amazonItemSearch.AWSAccessKeyId = Properties.Settings.Default.AmazonAccessKeyId;
     
     
    // Création de la requête
    WebbookCommonTools.amazonItemSearch.Request = new AmazonWebServices.ItemSearchRequest[] { amazonItemSearchRequest };
     
    // Envoi de la requête à Amazon
    AmazonWebServices.ItemSearchResponse amazonResponse = WebbookCommonTools.amazonWS.ItemSearch(WebbookCommonTools.amazonItemSearch);
    // Unpack the results.
    AmazonWebServices.Items resultsItems = amazonResponse.Items[0];
    Or même en rajoutant l'ID Amazon impossible dorénavant de faire fonctionner ce code qui renvoie à chaque fois :"La demande doit être signé".

    Est-ce que quelqu'un aurait un exemple d'un requête authentifié en SOAP vers le webservice d'Amazon car Amazon est trop précis dans ces codes et je suis complètement noyé sous cette profusion d'informations.

    Le but étant de modifier le moins possible la requête et donc d'utiliser les objets ItemSearch, Items et ItemSearchRequest.

    Merci d'avance.

  2. #2
    Membre averti
    Inscrit en
    Octobre 2005
    Messages
    49
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 49
    Par défaut
    Bon j'ai avancé un peu sur le problème. J'arrive maintenant à interroger le webservice d'Amazon seulement, il ne me renvoie aucun résultat mais ne me rejette plus à cause de ma signature.
    Voila le code pour ceux qui gazlère comme moi :

    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
     
    amazonItemSearchRequest = new AmazonAPI.ItemSearchRequest();
    amazonItemSearch = new AmazonAPI.ItemSearch();
     
    amazonItemSearchRequest.ResponseGroup = new string[] { "ItemAttributes", "Images" };
    // Applique le critère si on recherche un auteur ou un livre
    amazonItemSearchRequest.Author = "Marin Ledun";
    amazonItemSearchRequest.SearchIndex = "Books";
    amazonItemSearch.AWSAccessKeyId = MY_AWS_ACCESS_KEY_ID;
     
    // Création de la requête
    amazonItemSearch.Request = new AmazonAPI.ItemSearchRequest[] { amazonItemSearchRequest };
     
    // Envoi de la requête à Amazon
    BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
    binding.MaxReceivedMessageSize = int.MaxValue;  
    AmazonAPI.AWSECommerceServicePortTypeClient client = new AmazonAPI.AWSECommerceServicePortTypeClient(
      binding,
      new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService"));
     
    client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(MY_AWS_ACCESS_KEY_ID, MY_AWS_SECRET_KEY));
     
    // Récupération des résultats
    AmazonAPI.ItemSearchResponse amazonResponse = client.ItemSearch(amazonItemSearch);
    amazonResponse.Items[0].Item est toujours null à la suite de cette requête.
    Est-ce que quelqu'un aurait une idée d'où peut provenir ce souci ?

  3. #3
    Nouveau candidat au Club
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 2
    Par défaut
    Bonjour,

    J'ai le même problème pour mon projet à l'école.

    Avez vous réussi à résoudre le soucis de la signature et le pointeur nul pour les résultats ?

    Merci de m'expliquer votre démarche.

    Cordialement.

    Kb

  4. #4
    Invité de passage
    Inscrit en
    Avril 2010
    Messages
    1
    Détails du profil
    Informations forums :
    Inscription : Avril 2010
    Messages : 1
    Par défaut Amazon Web services
    voici un code source qui existe sur le net
    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
    class Amazon{
     
            public static $secretKey = la clé privé;
            public static $publicKey = la clé public;
            private static $_key;
            private static $_hashAlgorithm;
     
            /**
             * Permet de creer une url pour les services amazon
             * @param string $operation le paramètre opération de la requete
             * @param array $options les autres paramètres.
             * @return string l'url
             */
        public static function createRequest($operation, array $options)
        {
            $options['AWSAccessKeyId'] = self::$publicKey;
            $options['Service']        = 'AWSECommerceService';
            $options['Operation']      = (string) $operation;
     
            $baseUri = 'http://webservices.amazon.fr';
     
            if(self::$secretKey !== null) {
                $options['Timestamp'] = gmdate("Y-m-d\TH:i:s\Z");;
                ksort($options);
                $options['Signature'] = self::computeSignature($baseUri, self::$secretKey, $options);
            }
     
            return 'http://webservices.amazon.fr/onca/xml?'.http_build_query($options, null, '&');
        }
     
        static public function computeSignature($baseUri, $secretKey, array $options)
        {
            $signature = self::buildRawSignature($baseUri, $options);
            return base64_encode(
                self::compute($secretKey, 'sha256', $signature, 'binary')
            );
        }
     
       static public function buildRawSignature($baseUri, $options)
        {
            ksort($options);
            $params = array();
            foreach($options AS $k => $v) {
                $params[] = $k."=".rawurlencode($v);
            }
     
            return sprintf("GET\n%s\n/onca/xml\n%s",
                str_replace('http://', '', $baseUri),
                implode("&", $params)
            );
        }
     
        public static function compute($key, $hash, $data, $output)
        {
            // set the key
            if (!isset($key) || empty($key)) {
                throw new Exception('provided key is null or empty');
            }
            self::$_key = $key;
     
            // set the hash
            self::_setHashAlgorithm($hash);
     
            // perform hashing and return
            return self::_hash($data, $output);
        }
     
       protected static function _setHashAlgorithm($hash)
        {
            if (!isset($hash) || empty($hash)) {
                throw new Exception('provided hash string is null or empty');
            }
     
            $hash = strtolower($hash);
            $hashSupported = false;
     
            if (function_exists('hash_algos') && in_array($hash, hash_algos())) {
                $hashSupported = true;
            }
     
            if ($hashSupported === false) {
                throw new Exception('hash algorithm provided is not supported on this PHP installation; please enable the hash or mhash extensions');
            }
            self::$_hashAlgorithm = $hash;
        }
     
        protected static function _hash($data, $output = 'string', $internal = false)
        {
            if (function_exists('hash_hmac')) {
                if ($output == 'binary') {
                    return hash_hmac(self::$_hashAlgorithm, $data, self::$_key, 1);
                }
                return hash_hmac(self::$_hashAlgorithm, $data, self::$_key);
            }
     
            if (function_exists('mhash')) {
                if ($output == 'binary') {
                    return mhash(self::_getMhashDefinition(self::$_hashAlgorithm), $data, self::$_key);
                }
                $bin = mhash(self::_getMhashDefinition(self::$_hashAlgorithm), $data, self::$_key);
                return bin2hex($bin);
            }
        }
     
        protected static function _getMhashDefinition($hashAlgorithm)
        {
            for ($i = 0; $i <= mhash_count(); $i++)
            {
                $types[mhash_get_hash_name($i)] = $i;
            }
            return $types[strtoupper($hashAlgorithm)];
        }
    }

Discussions similaires

  1. [Web Service] amazon webservices et paramètre signature
    Par hervelyon dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 03/11/2010, 16h23
  2. Silverlight + webservice Amazon
    Par silberfab dans le forum Silverlight
    Réponses: 8
    Dernier message: 27/07/2009, 09h41
  3. Webservices amazon
    Par titoumimi dans le forum Ruby
    Réponses: 7
    Dernier message: 12/09/2007, 16h39
  4. [C#] Qui pourrait m'aider à faire marcher le WebService Amazon
    Par Cazaux-Moutou-Philippe dans le forum Windows Forms
    Réponses: 34
    Dernier message: 24/06/2006, 02h55

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