'新单', '13' => '自提退货', '2' => '等待支付', '14' => '确认自提', '3' => '等待支付确认', '16' => '等待确认收货', '4' => '延迟付款确认', '17' => '配送退货', '5' => '订单暂停', '18' => '货到付款确认', '6' => '店长最终审核', '19' => '已完成', '7' => '等待打印', '21' => '收款确认', '8' => '等待出库', '22' => '锁定', '9' => '等待打包', '29' => '等待三方出库', '10' => '等待发货', '30' => '等待三方发货', '11' => '自提途中', '31' => '等待三方发货完成', '12' => '上门提货' ); function jd_add_log($url, $post, $rs) { global $db; if(is_array($post)) $post = json_encode($post); $db->query("insert into tb_jd_api_log set url = '".addslashes($url)."', post = '".addslashes($post)."', rs = '".addslashes($rs)."', addtime = now() ", 'SILENT'); } function jd_encrypt($s) { global $publickey, $publickeyData; if(!$publickey) $publickey = openssl_get_publickey($publickeyData); openssl_public_encrypt($s, $s2, $publickey); $s2 = base64_encode($s2); return $s2; } function jd_decrypt($s) { global $privatekey, $privatekeyData, $accessKey; if(!$privatekey) $privatekey = openssl_get_privatekey($privatekeyData); $s = base64_decode($s); openssl_private_decrypt($s, $s2, $privatekey); return $s2; } function jd_decrypt_public($s) { global $publickey, $publickeyData; if(!$publickey) $publickey = openssl_get_publickey($publickeyData); $s = base64_decode($s); openssl_public_decrypt($s, $s2, $publickey); return $s2; } function jd_sign($data, $isLogin = false) { global $privatekey, $privatekeyData, $accessKey; if(!$privatekey) $privatekey = openssl_get_privatekey($privatekeyData); $data['accessKey'] = $accessKey; $time = time(); if(!$isLogin) $time = $time*1000; $data['timestamp'] = $time; $s = ''; ksort($data); foreach($data as $key => $value) { if($s != '') $s .= "&"; $s .= $key."=".$value; } //echo $s."\n"; $sha = hash("sha256", $s); openssl_private_encrypt($sha, $sign, $privatekey); $sign = base64_encode($sign); if($isLogin) { foreach($data as $key => $value) { $data[$key] = jd_encrypt($value); } } $data['sign'] = $sign; return $data; } function jd_verify($data) { global $privatekey, $privatekeyData, $accessKey; if(!$privatekey) $privatekey = openssl_get_privatekey($privatekeyData); if(!$data['sign']) return false; foreach($data as $key => $value) { if(($value."") === "") { unset($data[$key]); } else { if($key != 'sign') $data[$key] = jd_decrypt($value); } } //foreach($data as $key => $value) { // if($key != 'sign') $data[$key] = jd_decrypt($value); //} $sha_jd = jd_decrypt_public($data['sign']); unset($data['sign']); $s = ''; ksort($data); foreach($data as $key => $value) { if($s != '') $s .= "&"; $s .= $key."=".$value; } //echo $s."\n"; $sha = hash("sha256", $s); if($sha != $sha_jd) return false; return $data; } function gotoJd($uid, $returnUrl = '/index') { global $accessKey; $timestamp = time(); //$jd_url = "https://mes.jd.com/{$accessKey}/autoLogin"; //$returnUrl = "https://mes.jd.com/{$accessKey}".$returnUrl; //$jd_url = "https://jxi-fuli-login.jd.com/autoLogin?appTarget=5&loginCode={$accessKey}"; //$returnUrl = "https://jfd-m.jd.com/fuli_page_wegoIndex"; $jd_url = "https://jxi-fuli-login.jd.com/autoLogin?appTarget=5&loginCode={$accessKey}"; $returnUrl = "https://jxi-fuli-m.jd.com/fuli_page_index"; //echo $uid;exit; $uid = "yzmsdc_".$uid; $data = array( 'returnUrl' => $returnUrl, 'uid' => $uid ); $data = jd_sign($data, true); $html = 'jd'; $html .= '
'; foreach($data as $key => $value) $html .= ''; $html .= ''; $html .= '
'; echo $html; } function jd_get_order_list() { global $accessKey; $post = array( 'pageNo' => '1', 'pageSize' => '20', ); $post = jd_sign($post); //print_r($post);exit; $s = gquery("https://cvop.jd.com/component/http/JSON/youli/v1/order/getList", $post); echo $s; } function jd_get_order_detail($jdOrderId) { $post = array( 'jdOrderId' => $jdOrderId, ); $post = jd_sign($post); //print_r($post);exit; $s = gquery("https://cvop.jd.com/component/http/JSON/youli/v1/order/getDetail", $post); if(!$s) return false; $a = json_decode($s, true); if(!$a || $a['success'] != 1 || !$a['result']['jdOrderId']) return false; return $a['result']; } function jd_get_order_track($jdOrderId) { $post = array( 'jdOrderId' => $jdOrderId, ); $post = jd_sign($post); //print_r($post);exit; $s = gquery("https://cvop.jd.com/component/http/JSON/youli/v1/order/orderTrack", $post); if(!$s) return false; $a = json_decode($s, true); if(!$a || $a['success'] != 1 || !$a['result']['jdOrderId']) return false; return $a['result']; } function jd_cancel_order($jdOrderId) { $post_r = array( 'jdOrderId' => $jdOrderId, ); $post = jd_sign($post_r); //print_r($post);exit; $url = "https://cvop.jd.com/component/http/JSON/youli/v1/order/cancel"; $s = gquery($url, $post); jd_add_log($url, $post_r, $s); if(!$s) return false; $a = json_decode($s, true); if(!$a) return false; return $a; } function jd_confirm_order($jdOrderId) { $post_r = array( 'jdOrderId' => $jdOrderId, ); $post = jd_sign($post_r); $url = "https://cvop.jd.com/component/http/JSON/youli/v1/order/confirm"; $s = gquery($url, $post); jd_add_log($url, $post_r, $s); if(!$s) return false; $a = json_decode($s, true); if(!$a) return false; return $a; } function jd_get_aftersale($jdOrderId) { $post = array( 'orderId' => $jdOrderId, 'pageSize' => 20, 'pageNo' => 1, ); $post = jd_sign($post); //print_r($post);exit; $s = gquery("https://cvop.jd.com/component/http/JSON/youli/v1/afterSale/getList", $post); if(!$s) return false; $a = json_decode($s, true); if(!$a || $a['success'] != 1) return false; return $a; } function jd_get_returnBpInfo($jdOrderId = '', $startDate = '', $pageNum = 1) { $post = array( 'pageSize' => 100, 'pageNum' => $pageNum, ); if($jdOrderId) $post['orderId'] = $jdOrderId; if($startDate) $post['startDate'] = $startDate; $post = jd_sign($post); //print_r($post);exit; $s = gquery("https://cvop.jd.com/component/http/JSON/youli/v1/order/queryReturnBpInfo", $post); if(!$s) return false; $a = json_decode($s, true); if(!$a || $a['success'] != 1) return false; return $a['result']; } function money_equal($m1, $m2) { return round($m1*100)==round($m2*100); } if($act == 'jd_autoLogin') { $GLOBALS['in_page'] = 1; $GLOBALS['in_page_func'] = "jdLoginGetHTML"; //echoRs(0, '测试!'); $user = check_token(); $user_id = $user['id']; $area_id = $user['area_id']; $company_id = $user['company_id']; $companyInfo = $db->get_one("select * from tb_company where id=".$company_id); if(!$companyInfo) exit; $jd_wg_key = $companyInfo['jd_wg_key']; $a = explode("##", $jd_wg_key); if(count($a) != 3) { echoRs(0, '未开放商城!'); } $publickeyData = "-----BEGIN PUBLIC KEY-----\n".implode("\n", str_split($a[0], 70))."\n-----END PUBLIC KEY-----\n"; $privatekeyData = "-----BEGIN PRIVATE KEY-----\n".implode("\n", str_split($a[1], 70))."\n-----END PRIVATE KEY-----\n"; $accessKey = $a[2]; gotoJd($user_id); exit; } if($act == 'jd_cancel_order') { $user = check_token(); $user_id = $user['id']; $order_id = intval($_POST['order_id']); $orderInfo = $db->get_one("select * from tb_goods_wg_order where id = {$order_id} and uid={$user_id}"); if(!$orderInfo) { echoRs(0, '订单不存在!'); } $status = $orderInfo['status']; if($status == 1) { echoRs(0, '该订单已支付!'); } else if($status == 2) { echoRs(0, '该订单已取消!'); } else if($status != 0) { exit; } $rs = jd_cancel_order($orderInfo['orderId']); if(!$rs) { echoRs(0, '取消失败,请重试!'); } if($rs['success']) { $db->query("update tb_goods_wg_order set status=2 where id=".$order_id); echoRs(1, 'ok'); } else { echoRs(0, '取消失败:'.$rs['resultMessage']); } exit; } if($act == 'jd_get_wg_wuliu') { $user = check_token(); $user_id = $user['id']; $wgid = intval($_REQUEST['wgid']); $wOrder = $db->get_one("select * from tb_goods_wg_order where id = {$wgid} and uid=".$user_id); if(!$wOrder) exit; $wSkus = $db->get_all("select * from tb_goods_wg_order_skus where order_id = {$wgid}"); $list = array(); foreach($wSkus as $item) { $list[$item['childOrderId']][] = $item; } ?> wglogin