4

我正在使用 Aliexpress API generatePromotionLinks。此 API 需要一个参数,即_aop_signature

网址是这样的:

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=[签名]

我想知道在哪里可以得到_aop_signature,或者如何_aop_signature使用 PHP 生成。

4

1 回答 1

2
<?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);
?>
于 2019-11-06T12:08:41.240 回答