Sat Singh Rana
Sat Singh Rana

Reputation: 41

How to generate the _aop_signature for Aliexpress API using PHP?

I'm using the Aliexpress API generatePromotionLinks. This API requires an parameter which is _aop_signature

URL is this :

https://gw.api.alibaba.com/openapi/param2/1/portals.open/api.generatePromotionLinks/[appKey]?trackingId=[trackingId]&targetUrls=[url]&locale=[global]&linkType=HOT_PRODUCT_LINK&_aop_signature=[signature]

I want to know where I can get the _aop_signature, or how to generate the _aop_signature using PHP.

Upvotes: 4

Views: 1640

Answers (1)

newProgrammer
newProgrammer

Reputation: 128

<?php
 $url = 'https://gw.api.alibaba.com/openapi/';
 $appKey = ***;
 $appSecret ='***';
 $apiInfo = 'param2/1/portals.open/api.generatePromotionLinks/' . $appKey;
 $code_arr = array(
    'urls' => 'https://ru.aliexpress.com/af/mp3.html?d=y&origin=n&SearchText=mp3&catId=0&initiative_id=SB_20191106040548',
    'linkType' => 'SEARCH_LINK',
    'fields' => 'promotionUrls,trackingId,publisherId',
    'trackingId' => 'Please create a unique affiliate ID for your site(s).',

);
 $aliParams = array();
 foreach ($code_arr as $key => $val) {
     $aliParams[] = $key . $val;
 }
 sort($aliParams);
 $sign_str = join('', $aliParams);
 $sign_str = $apiInfo . $sign_str;
 $code_sign = strtoupper(bin2hex(hash_hmac("sha1", $sign_str, $appSecret, true)));

 $url = $url.$apiInfo.'?'.http_build_query($code_arr)."&_aop_signature=".$code_sign;
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_HEADER, 0);
 curl_setopt($ch, CURLOPT_VERBOSE, 0);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
 curl_setopt($ch, CURLOPT_URL, $url);
 $response = curl_exec($ch);
 curl_close($ch);
 print_r($response);
?>

Upvotes: 2

Related Questions