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

我正在使用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=[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:不推荐使用password_hash的'salt'选项 - php

我正在使用密码哈希进行注册。我需要手动创建Salt,以下是我使用的代码:$options = [ 'cost' => 11, 'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM) ]; $password = password_hash( $this->…

PHP-全局变量的性能和内存问题 - php

假设情况:我在php中运行一个复杂的站点,并且我使用了很多全局变量。我可以将变量存储在现有的全局范围内,例如$_REQUEST['userInfo'],$_REQUEST['foo']和$_REQUEST['bar']等,然后将许多不同的内容放入请求范围内(这将是适当的用法,因为这些数据指的是要求自…

PHP strtotime困境 - php

有人可以解释为什么这在我的服务器上输出为true吗?date_default_timezone_set('Europe/Bucharest'); var_dump( strtotime('29.03.2015 03:00', time()) === strtotime('29.03.2015 04:00�…

php-casperjs获取内部文本 - php

我正在为casperjs使用php包装器-https://github.com/alwex/php-casperjs我正在网上自动化一些重复的工作,我需要访问一个项目的innerText,但是我尚不清楚如何从casperjs浏览器访问dom。我认为在js中我会var arr = document.querySelector('label.input…

PHP Laravel从另一个驱动器读取文件 - php

我目前正在学习Laravel。我想知道是否有一种方法可以在Laravel中使用Storage::从另一个硬盘访问文件(使用Windows)。例如,我在驱动器C:上安装了带有Laravel的Xampp,但是我想访问网站目录之外的E:上的文件。我试过使用Storage::files('E:')和File::files('E:…