京佣开放接口V4接口签名与订单接口PHP示例代码


京佣开放接口V4接口签名与订单接口PHP示例代码:

//获取时间戳毫秒
function msectime(){
    list($msec, $sec) = explode(' ', microtime());
    $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
    return $msectime;
}

//curl post  
function vip_http_post($url,$param,$post_file=false,$header = null){
    $oCurl = curl_init();
    if (is_array($header)) {
        curl_setopt($oCurl, CURLOPT_HTTPHEADER, $header); 
    }
    if(stripos($url,"https://")!==FALSE){
        curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
    }




    if (is_string($param) || $post_file) {
        $strPOST = $param;
    } else {
        $strPOST=json_encode($param);
    }


    curl_setopt($oCurl, CURLOPT_HTTPHEADER,array(
                'Content-Type: application/json; charset=utf-8',
                'Content-Length:' . strlen($strPOST),
                'Cache-Control: no-cache',
                'Pragma: no-cache'
    ));

    curl_setopt($oCurl, CURLOPT_URL, $url);
    curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt($oCurl, CURLOPT_POST,true);
    curl_setopt($oCurl, CURLOPT_POSTFIELDS,$strPOST);
    $sContent = curl_exec($oCurl);
    $aStatus = curl_getinfo($oCurl);
    curl_close($oCurl);
    if(intval($aStatus["http_code"])==200){
        return $sContent;
    }else{
        return false;
    }
}

//京佣接口所需要的 appKey secretKey
$appKey="";
$secretKey="";

//业务请求参数,这里是以订单为例
$data=array(
        'code'=>$appKey,
        'startTime'=>'2020-12-16 10:15:00',
        'endTime'=>'2020-12-16 10:30:00',
        'pageSize'=>1,
        'pageNo'=>1,
        'type'=>1
    );

//生成签名 sign
$current=msectime();
$signBody=$appKey.$secretKey.$current.json_encode($data);
$sign = md5($signBody);

//拼接请求地址,请求调用接口
$url ="https://jyapi.jd.com/open-api/jy/order/query-items?appKey=$appKey&sign=$sign&current=$current";
echo '<pre/>';
print_r(json_decode(vip_http_post($url,$data),true));

返回数据:

Array
(
    [errorCode] => 
    [errorMessage] => 
    [currentTime] => 1608176401674
    [data] => Array
        (
            [result] => Array
                (
                    [0] => Array
                        (
                            [orderId] => 139921608999
                            [parentId] => 0
                            [skuId] => 2133114
                            [skuName] => 博士伦清朗舒适隐形眼镜月抛 6片装 900度
                            [skuNum] => 1
                            [skuReturnNum] => 0
                            [frozenSkuNum] => 0
                            [price] => 79
                            [payPrice] => 79
                            [commissionRate] => 2.5
                            [subSideRate] => 90
                            [subsidyRate] => 10
                            [finalRate] => 100
                            [estimateCosPrice] => 79
                            [estimateCommission] => 1.98
                            [estimateFee] => 1.98
                            [actualCosPrice] => 79
                            [actualCommission] => 1.98
                            [actualFee] => 1.98
                            [traceType] => 2
                            [spId] => 3002820776
                            [siteId] => 0
                            [unionAlias] => 
                            [pid] => 
                            [unionTrafficGroup] => 
                            [firstLevel] => 9192
                            [secondLevel] => 13893
                            [thirdLevel] => 13895
                            [subUnionId] => 24204
                            [unionTag] => 00000000000000000000000000000000
                            [cpActId] => 0
                            [unionRole] => 1
                            [rowId] => 542287881676439552
                            [orderTime] => 1608085105000
                            [finishTime] => 1608107536000
                            [payMonth] => 20210120
                            [validCode] => 17
                        )

                )

            [pageNo] => 1
            [pageSize] => 1
            [totalItems] => 
            [hasNext] => 1
        )

    [success] => 1
)