php - 如何使用 PHP 为 Aliexpress API 生成 _aop_signature?

标签 php api aliexpress

我正在使用 Aliexpress APIgeneratePromotionLinks。此 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=[signature]

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

最佳答案

<?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);
?>

关于php - 如何使用 PHP 为 Aliexpress API 生成 _aop_signature?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55805101/

相关文章:

python - 如何使用Python和Selenium访问网站https ://www. aliexpress.com/后点击并关闭横幅

php - 如何在没有引用的情况下复制对象?

javascript - AJAX 联系表单重新加载页面但不发送电子邮件

php/mysql - 向 MySQL 发送多个数据

php - Docker-compose(CakePHP 2x 和 MySQL)抛出 PHP fatal error

C# 错误(使用接口(interface)方法): An object reference is required for the non-static field, 方法或属性

c# - 未从 .NET MVC MultipartFormDataContent POST 收到 .NET Core API List<IFormFile> 文件

c# - 求请求时传入回调url