分类 日常生活 下的文章

速卖通API接口签名算法[订单url生成]


<?php
    $orderid1 = $_GET['order'];
    $token1 = $_GET['token'];
    $url = 'http://gw.api.alibaba.com:80/openapi';//1688开放平台使用gw.open.1688.com域名
    $appKey = '填写appkey';
    $appSecret ='写签名串'; //签名串
    $orderid = $orderid1;// 订单号
    $token = $token1;//授权码
    $apiInfo = 'param2/1/aliexpress.open/api.findOrderById/' . $appKey;//此处请用具体api进行替换
    
        
    //配置参数,请用apiInfo对应的api参数进行替换
    $code_arr = array(
        // 'client_id'=>$appKey,
        'orderId' => $orderid,
        'access_token' => $token,
    );
    $aliParams = array();
    foreach ($code_arr as $key => $val) {
        $aliParams[] = $key . $val;
    }
    // print_r($aliParams);die;
    sort($aliParams);
    $sign_str = join('', $aliParams);
    $sign_str = $apiInfo . $sign_str; //拼接参数
    $code_sign = strtoupper(bin2hex(hash_hmac("sha1", $sign_str, $appSecret, true))); //签名算法
    $file_get_url = "{$url}/{$apiInfo}?orderId={$orderid}&access_token={$token}&_aop_signature={$code_sign}";
    if (!empty($file_get_url)) {
        $content = file_get_contents($file_get_url);
        $b = json_decode($content,TRUE);
        // print_r($b);die;
        
    }

?>