diff --git a/config/define.php b/config/define.php index 49c7a75..af4450f 100644 --- a/config/define.php +++ b/config/define.php @@ -25,7 +25,13 @@ define('PDD_CLIENT_SECRET', 'bf3dfd836648d0d53657030d17b10e2dfa7056a0'); define('PDD_REDIRECT_URI', 'http://www.kuailelunwen.com/callback/pdd'); define('PDD_AUTH_STATE', 'pddauth'); - define('PDD_APPLICATION_BUY_URL', ''); + define('PDD_APPLICATION_BUY_URL', 'https://fuwu.pinduoduo.com/service-market/service-detail?detailId=70328'); + + // PDD_CLIENT_SECRET 前20位 后20位 + define('API_PDD_UID', 'bf3dfd836648d0d53657'); + define('API_PDD_TOKEN', '030d17b10e2dfa7056a0'); + + define('API_KUAILELUNWEN_UPDATE_PDD_AUTH_INFO', 'http://api.kuailelunwen.com/update_pdd_auth_info'); # order_status 1:待发货,2:已发货待签收,3:已签收 5:全部 define('ORDER_STATUS_WAIT_DELIVER_GOODS', 1); diff --git a/control/api.php b/control/api.php new file mode 100644 index 0000000..38003b2 --- /dev/null +++ b/control/api.php @@ -0,0 +1,87 @@ +get_access_token(); + + $obj = new PDD(PDD_CLIENT_ID, PDD_CLIENT_SECRET, $access_token); + + $order_sn = $this->post('order_sn'); + if (empty($order_sn)) $this->ajax_json(false, '订单号不能为空'); + + $res = $obj->getOrderInformation($order_sn); + // {"order_info_get_response":{"request_id":"16547568855546893","order_info":{"support_nationwide_warranty":0,"country":"中国","group_status":1,"free_sf":0,"discount_amount":0.0,"platform_discount":0.0,"return_freight_payer":0,"order_status":1,"id_card_num":"","risk_control_status":0,"province":"","town_id":0,"item_list":[{"goods_name":"checkpass论文查重无限次数低价免注册查重","outer_goods_id":"","goods_price":1.0,"goods_id":329073007863,"sku_id":1115504481445,"goods_count":1,"goods_spec":"千字符","outer_id":"","goods_img":"https://img.pddpic.com/mms-material-img/2022-03-28/0c075d33-b036-46f7-a0bf-d40774f68190.png.a.jpeg"}],"pay_no":"","last_ship_time":"2022-06-11 14:37:23","delivery_one_day":0,"created_time":"2022-06-09 14:37:14","card_info_list":[],"refund_status":1,"town":"","is_stock_out":0,"receiver_address_mask":"","receive_time":"","pay_time":"2022-06-09 14:37:23","gift_list":[],"capital_free_discount":0.0,"receiver_phone_mask":"13*******67","country_id":0,"city_id":0,"invoice_status":0,"service_fee_detail":[],"city":"","order_tag_list":[{"name":"delivery_one_day","value":0},{"name":"no_trace_delivery","value":0},{"name":"self_contained","value":0},{"name":"return_freight_payer","value":0},{"name":"free_sf","value":0},{"name":"duoduo_wholesale","value":0},{"name":"support_nationwide_warranty","value":0},{"name":"only_support_replace","value":0},{"name":"oversea_tracing","value":0},{"name":"distributional_sale","value":0},{"name":"open_in_festival","value":0},{"name":"same_city_distribution","value":0},{"name":"region_black_delay_shipping","value":0},{"name":"has_subsidy_postage","value":0},{"name":"has_sf_express_service","value":0},{"name":"community_group","value":0},{"name":"has_ship_additional","value":0},{"name":"ship_additional_order","value":0}],"is_lucky_flag":1,"yyps_time":"","mkt_biz_type":0,"shipping_type":0,"remark":"","pre_sale_time":"","inner_transaction_id":"","order_change_amount":0.0,"only_support_replace":0,"logistics_id":0,"updated_at":"2022-06-09 14:37:33","street":"","receiver_name_mask":"","receiver_name":"","tracking_number":"","pay_type":"","duoduo_wholesale":0,"buyer_memo":"","is_pre_sale":0,"shipping_time":"","home_delivery_type":0,"after_sales_status":0,"address":"","id_card_name":"","self_contained":0,"goods_amount":1.0,"pay_amount":1.0,"seller_discount":0.0,"address_mask":"","yyps_date":"","confirm_status":1,"confirm_time":"2022-06-09 14:37:23","stock_out_handle_status":-1,"postage":0.0,"province_id":0,"cat_id_3":9056,"cat_id_4":0,"cat_id_1":8726,"receiver_address":"","cat_id_2":8786,"trade_type":0,"urge_shipping_time":"","receiver_phone":"$3MpaxbKBnse9$AgAAAAF2+qYGan7+ggANYOk6e6B2tcD3m4NUAgu6bY4=$0$$","order_sn":"220609-635730697112661"}}} + $res = json_decode($res, true); + if (isset($res['error_response'])) $this->ajax_json(false, $res['error_response']['error_msg'].' '.$res['error_response']['sub_msg']); + + $order_info = $res['order_info_get_response']['order_info']; + + $data = array(); + $data['confirm_status'] = $order_info['confirm_status']; + $data['refund_status'] = $order_info['refund_status']; + $data['order_status'] = $order_info['order_status']; + $data['group_status'] = $order_info['group_status']; + $data['after_sales_status'] = $order_info['after_sales_status']; + $data['is_pre_sale'] = $order_info['is_pre_sale']; + $data['item_list'] = $order_info['item_list']; + $data['goods_amount'] = $order_info['goods_amount']; + $data['risk_control_status'] = $order_info['risk_control_status']; + + $this->ajax_json(true, 'succ', $data); + } + + public function _api_get_goods_list() { + $access_token = $this->get_access_token(); + $obj = new PDD(PDD_CLIENT_ID, PDD_CLIENT_SECRET, $access_token); + + $goods_name = $this->post('goods_name'); + if (empty($goods_name)) $this->ajax_json(false, '商品名称不能为空'); + + $res = $obj->getGoodsList($goods_name); + + // {"goods_list_get_response":{"goods_list":[{"is_more_sku":1,"goods_name":"checkpass论文查重无限次数低价免注册查重","thumb_url":"https://img.pddpic.com/gaudit-image/2022-03-28/edac0af376a509b227714488bd5dfa37.jpeg","goods_reserve_quantity":0,"image_url":"","sku_list":[{"outer_goods_id":"","is_sku_onsale":1,"reserve_quantity":0,"sku_id":1115504481445,"outer_id":"","spec":"千字符","sku_quantity":1277},{"outer_goods_id":"","is_sku_onsale":1,"reserve_quantity":0,"sku_id":1115476736663,"outer_id":"","spec":"无限次数","sku_quantity":1495}],"goods_quantity":2772,"goods_id":329073007863,"is_onsale":1}],"total_count":1,"request_id":"16551061312578732"}} + $res = json_decode($res, true); + + if (isset($res['error_response'])) $this->ajax_json(false, $res['error_response']['error_msg'].' '.$res['error_response']['sub_msg']); + + + $this->ajax_json(true, 'succ', $res['goods_list_get_response']['goods_list']); + } + + public function _api_get_goods_info() { + $access_token = $this->get_access_token(); + $obj = new PDD(PDD_CLIENT_ID, PDD_CLIENT_SECRET, $access_token); + + $goods_id = $this->post('goods_id'); + if (empty($goods_id)) $this->ajax_json(false, '商品编码不能为空'); + + $res = $obj->getGoodsInformation($goods_id); + + // {"goods_info_get_response":{"goods_info":{"goods_name":"checkpass论文查重无限次数低价免注册查重","last_category":"论文检测与查询","image_url":"","shipment_limit_second":"172800","goods_quantity":2772,"goods_id":"329073007863","goods_sn":"329073007863","goods_category":"教育培训","is_onsale":"1","is_refundable":"0","second_hand":0,"sku_list":[{"single_price":"12.00","sku_img":"https://img.pddpic.com/mms-material-img/2022-03-28/3cd06438-b959-42ac-936a-93c273367355.png.a.jpeg","outer_goods_id":"","is_sku_onsale":"1","sku_id":"1115476736663","group_price":"10.00","outer_id":"","spec":"无限次数","sku_quantity":"1495"},{"single_price":"2.00","sku_img":"https://img.pddpic.com/mms-material-img/2022-03-28/0c075d33-b036-46f7-a0bf-d40774f68190.png.a.jpeg","outer_goods_id":"","is_sku_onsale":"1","sku_id":"1115504481445","group_price":"1.00","outer_id":"","spec":"千字符","sku_quantity":"1277"}],"goods_type":"1","group_required_customer_num":"2"},"request_id":"16551080285427607"}} + $res = json_decode($res, true); + if (isset($res['error_response'])) $this->ajax_json(false, $res['error_response']['error_msg'].' '.$res['error_response']['sub_msg']); + + $this->ajax_json(true, 'succ', $res['goods_info_get_response']['goods_info']); + } + + public function _api_get_order_status() { + $access_token = $this->get_access_token(); + $obj = new PDD(PDD_CLIENT_ID, PDD_CLIENT_SECRET, $access_token); + + $tids = $this->post('order_sns'); + if (empty($tids)) $this->ajax_json(false, '订单编号不能为空'); + + $res = $obj->getOrderStatus($tids); + + $res = json_decode($res, true); + if (isset($res['error_response'])) $this->ajax_json(false, $res['error_response']['error_msg'].' '.$res['error_response']['sub_msg']); + + $this->ajax_json(true, 'succ', $res['order_status_get_response']['order_status_list']); + } +} diff --git a/control/callback.php b/control/callback.php index 04c806a..2e42e3d 100644 --- a/control/callback.php +++ b/control/callback.php @@ -12,11 +12,10 @@ class callback extends publicBase { $info = $obj->getPddAccessToken($this->get('code')); $obj->writeLog('application', 'pdd_auth.log', json_encode($info)."\n"); - - // if($info['expires_at']==0) $this->show_message('对不起,服务已到期,请续费后再使用。', PDD_APPLICATION_BUY_URL); +// if($info['expires_in']<=0) $this->show_message('对不起,服务已到期,请续费后再使用。', PDD_APPLICATION_BUY_URL); $access_token = $info['access_token']; - // if(empty($access_token)) $this->show_message('授权信息token不存在'); +// if(empty($access_token)) $this->show_message('授权信息token不存在'); $name = urldecode($info['owner_name']); $expire_time = date("Y-m-d H:i:s", $info['expires_at']); @@ -29,6 +28,27 @@ class callback extends publicBase { $_SESSION['app_uid'] = $shopinfo['uid']; $_SESSION['app_name'] = $shopinfo['name']; + $state = $this->get('state'); + if(strpos($state, "kuaileaid") !== false) { + $aid = str_replace('kuaileaid_', '', $state)+0; + if ($aid) { + $params = array( + '_uid' => API_PDD_UID, + '_token' => API_PDD_TOKEN, + 'aid' => $aid, + 'access_token' => $access_token, + 'name' => $name, + 'expire_time' => $expire_time + ); + $json_res = $sobj->postCUrl(API_KUAILELUNWEN_UPDATE_PDD_AUTH_INFO, $params); + $res = json_decode($json_res, true); + if (!$res['status']) $this->show_message($res['info']); + + header('Location: http://www.kuailelunwen.com/pay/pay_list/paytype/1'); + exit; + } + } + header('Location: /'); exit; } diff --git a/index.php b/index.php index 0e39629..c4e7aa4 100644 --- a/index.php +++ b/index.php @@ -50,17 +50,40 @@ class run extends publicBase { } private function aftercheckpara() { - $no_login_list = array('callback', 'tpl'); + $no_login_list = array('callback', 'tpl', 'api'); $is_need_login = in_array($this->control_name, $no_login_list) ? false : true; - if (!$is_need_login) return true; + if (!$is_need_login) { + // 接口 + if ($this->control_name == 'api') { + if (empty($_POST['_uid'])) $this->ajax_json(false, '_uid参数不能为空'); + if (empty($_POST['_token'])) $this->ajax_json(false, '_token参数不能为空'); + + if ($_POST['_uid'] != API_PDD_UID) $this->ajax_json(false, '_uid参数值不正确'); + if ($_POST['_token'] != API_PDD_TOKEN) $this->ajax_json(false, '_token参数值不正确'); + + $obj = new mShop(); + $shopinfo = $obj->getShopByName($_POST['name']); + if (empty($shopinfo)) $this->ajax_json(false, '店铺信息不存在'); + if (empty($shopinfo['access_token'])) $this->ajax_json(false, '店铺授权信息不存在'); + if (strtotime($shopinfo['expire_time']) < time()) $this->ajax_json(false, '店铺授权已过期,过期时间'.$shopinfo['expire_time']); + + $this->para['_access_token'] = $shopinfo['access_token']; + + $this->control_func = '_api_'.$this->control_func; + } + + return true; + } $app_uid = $_SESSION['app_uid']; $app_name = $_SESSION['app_name']; if (empty($app_uid) || empty($app_name)) { + $state = $_GET['aid'] ? 'kuaileaid_'.$_GET['aid'] : PDD_AUTH_STATE; + $pobj = new mPdd(); - $url = $pobj->getPddAuthUrl(); + $url = $pobj->getPddAuthUrl($state); header('Location:'.$url); exit; diff --git a/model/mPdd.php b/model/mPdd.php index 53684ed..22e064a 100644 --- a/model/mPdd.php +++ b/model/mPdd.php @@ -15,9 +15,9 @@ class mPdd extends mBase { } - public function getPddAuthUrl() { + public function getPddAuthUrl($state=PDD_AUTH_STATE) { $obj = new PDD(PDD_CLIENT_ID, PDD_CLIENT_SECRET); - return $obj->getWebAuthUrl(PDD_REDIRECT_URI, PDD_AUTH_STATE); + return $obj->getWebAuthUrl(PDD_REDIRECT_URI, $state); } public function getPddAccessToken($code) {