我正在使用Aliexpress API generatePromotionLinks。该API需要一个_aop_signature
URL是这个:
我想知道在哪里可以得到_aop_signature
,或者如何使用PHP生成_aop_signature
。
答案 0 :(得分:1)
<?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);
?>