1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
<?php // 设置时区为东八区 date_default_timezone_set('Asia/Shanghai'); $url = "https://xxx.xx.com/routerjson"; $secretkey = "efc01d5c25da41d7a1db03a5a768fa93"; $query = [ "method" => "jd.union.open.goods.promotiongoodsinfo.query", "app_key" => "3644767093ac9afd3d4b4e54a6b7da10", "timestamp" => date('Y-m-d H:i:s', time()), "format" => "json", "v" => "1.0", 'sign_method' => "md5", "360buy_param_json" => json_encode([ "skuIds" => "10074134634734" ]), ]; // 将所有请求参数名(包括系统和业务参数有)按照字母先后顺序排列 ksort($query); print_r(PHP_EOL); print_r($query); print_r(PHP_EOL); // PHP把所有参数名和参数值进行拼接 $sign= $secretkey; foreach ($query as $k => $v) { if (!is_string($v)) { $v = json_encode($v); } $sign .= $k . $v; } print_r(PHP_EOL); print_r($sign); print_r(PHP_EOL); $sign = strtoupper(md5($sign . $secretkey)); print_r($sign); print_r(PHP_EOL); $query['sign'] = $sign; $parms = http_build_query($query); print_r($parms); print_r(PHP_EOL); $link = "{$url}?{$parms}"; print_r($link); print_r(PHP_EOL); $result = @file_get_contents($link); print_r(PHP_EOL); print_r($result); print_r(PHP_EOL); $listObj = json_decode($result, true); print_r($listObj); print_r(PHP_EOL); $list = $listObj['jd_union_open_goods_promotiongoodsinfo_query_responce']; print_r($list); print_r(PHP_EOL); $shop = json_decode($list['queryResult']); print_r(PHP_EOL); print_r($shop); |