log($input, 'query'); $result = array(); // $sign = $this->_sign($input, array('customerId', 'data', 'timestamp')); // if ($sign && isset($input['data']) && isset($input['sign']) && $sign == $input['sign']) { $order_id = ''; $merchant_order_id = $input['user_order_id']; $orderService = OrderService::instance(); $order = $orderService->get($order_id, $merchant_order_id); if (!$order) { $orderHistoryService = OrderLastweekHistoryService::instance(); $order = $orderHistoryService->get($order_id, $merchant_order_id); } if ($order) { $result['code'] = '1'; $result['message'] = '查询成功'; if ($order['status'] == 2) { $data['status'] = 2; $data['rsp_info'] = '充值成功'; if(isset($order['channel_callback_at']) && $order['channel_callback_at']){ $data['rsp_time'] = strtotime($order['channel_callback_at']); }else{ $data['rsp_time'] = time(); } } elseif ($order['status'] == 3) { $data['status'] = 3; $data['rsp_info'] = '充值失败'; if(isset($order['channel_callback_at']) && $order['channel_callback_at']){ $data['rsp_time'] = strtotime($order['channel_callback_at']); }else{ $data['rsp_time'] = time(); } } else { $data['status'] = 1; } $result['data'] = json_encode($data); } else { $result['code'] = '1'; $result['message'] = '订单不存在'; } throw new HttpResponseException(json($result)); // } else { // $result['retCode'] = '104'; // $result['retMessage'] = '传入的参数有误'; // } // return json_encode($result); } # 获取订单 public function charge() { $this->input = $input = input(); /**/ $this->log($input, 'charge'); $result = array(); $this->appid = input('app_key'); $this->appid = 'PT_'.$this->appid ; $this->proid = input('outer_goods_code'); # 根据产品id 获取信息 $pinfo = \app\channel\service\ProductBaseService::instance()->getOne($this->proid); if (!$pinfo) { $this->no(-2); } $this->input['proid'] = $this->proid; $this->product = $pinfo['key']; if ($this->product != 'dhcz') { if (!strstr($this->product, '_cash')) { $this->input['cash'] = $pinfo['value']; } } else { $this->proid = false; } # 从数据库中或者缓存中取出商户的信息,并验证是否有效 $this->getMerchant(); $datas = $input['datas']; $this->input['order'] = $input['user_order_id']; $this->input['account'] = $input['target']; $settingStatus = sysconf('settingStatus'); // if ($settingStatus == 1) { // $this->noTB(401003); // } $data = $this->channel($this->mid, $this->product, true); if (is_string($data) && $data != 'ok' && $data != 'success'&& $data != 'yescard' && $data != '订单号重复' ) { $response = [ 'code'=>'FAIL', 'message'=>$data ]; throw new HttpResponseException(json($response)); } $response = [ 'code'=>'SUCCESS' ]; throw new HttpResponseException(json($response)); // return } # 通知处理 public function notify() { $log['type'] = 'merchant_notify'; $log['request'] = input(); if (!isset($log['request']['merchant_order_id'])) { echo 'error';die; } $merchant_order_id = $log['request']['merchant_order_id']; if (strstr($merchant_order_id, 't')) { echo 'success';die; } if (isset($log['request']['status']) && ($log['request']['status'] == 2 || $log['request']['status'] == 3)) { if ($log['request']['status'] == 2) { $status = "9"; $rsp_info = "充值成功"; } else { $status = "8"; $rsp_info = "充值失败"; } $this->appid = $log['request']['appid']; $this->getMerchant(); $order_id = $log['request']['order_id']; $merchant_order_id = $log['request']['merchant_order_id']; $url = 'https://shop.task.mf178.cn/userapi/sgd/updateStatus'; $request = []; $request['app_key'] = $this->merchant['agentId']; $request['timestamp'] =time(); $data = [ 'user_order_id'=>$merchant_order_id, 'status'=>$status, 'rsp_info'=>$rsp_info ]; $request['data'] = json_encode($data); $request['sign'] = $this->_sign($request, $this->agentkey); $response = $this->curl('post', $url, $request,true); if ($response) { $response = json_decode($response, true); if (isset($response['code']) && $response['code'] == '0') { echo 'success';die; } } } echo 'error';die; } # 记录日志 protected function log($data, $type = 'request') { Log::write('feedov', $type, $data); } private function _sign($request, $app_secret) { ksort($request); $buff = ''; foreach ($request as $k => $v) { if ($k != "sign") { $buff .= $k . $v; } } $buff .= $app_secret; return md5($buff); } }