'phone', 'cash' => 'money', 'type' => 'type', ); $param['type'] = '1'; $this->api = 'card'; return $this->submit($param, $check); } public function ltcz($param) { $check = array ( 'mobile' => 'phone', 'cash' => 'money', 'type' => 'type', ); $param['type'] = '1'; $this->api = 'card'; return $this->submit($param, $check); } public function dxcz($param) { $check = array ( 'mobile' => 'phone', 'cash' => 'money', 'type' => 'type', ); $param['type'] = '1'; $this->api = 'card'; return $this->submit($param, $check); } public function ydcz($param) { $check = array ( 'mobile' => 'phone', 'cash' => 'money', 'type' => 'type', ); $param['type'] = '1'; $this->api = 'card'; return $this->submit($param, $check); } # 通知处理 主要返回状态 2是成功 3是失败 public function notify($data) { $request = $data; $result = array(); $result['cash'] = 1; $result['status'] = 4; if (is_string($data)) { $data = json_decode($data, true); } if ($data['return_code'] == "SUCCESS") { if ($data['return_msg']['attach'] == "支付成功") { $result['status'] = 2; } } else if ($data['return_code'] == "FAIL") { $result['status'] = 3; } else { $result['status'] = 4; } $result['yes'] = '{"return_code":"OK"}'; $result['data'] = $data; return $result; } # 数据响应格式处理 public function response($data) { $log['type'] = 'response'; $log['data'] = $data; $log['config'] = $this->data; $this->log($log); $array = $this->json_decode($data); if (!$array) { $msg = 'error'; } elseif (isset($array['return_code']) && $array['return_code'] == 'SUCCESS') { # 正确 $msg = 'ok'; } // } else { # 错误 $msg = $array['desc'] ?? 'error'; } return array ( 'msg' => $msg, 'data' => $data, 'array' => $array, ); } # 订单查询 public function ddcx($param) { $check = array ( 'order_id' => 'szOrderId', ); $this->sign = array('szAgentId', 'szOrderId'); $this->api = 'api/old/queryorder'; return $this->submit($param, $check); } # 账户余额 public function balance($param) { $check = array (); $this->sign = array('szAgentId'); $this->api = 'api/old/queryBalance'; return $this->submit($param, $check); } # 查询余额接口 public function account($day) { $request['day'] = $day; $request['appid'] = $this->mid; $request['api_product'] = 'query'; $this->token = $this->mid . '|' . $this->token; $request = $this->getParam($request, $this->token); $url = $this->host . 'api/old/queryBalance'; $response = $this->curl('post', $url, $request); $response = $this->response($response); return $response['array']['data']; } # 查询接口 public function query($order) { $request['szAgentId'] = $this->mid; $request['szOrderId'] = $order['order_id']; $request['szVerifyString'] = $this->_sign1($request, array('szAgentId', 'szOrderId')); $request['szFormat'] = 'json'; $url = $this->host . 'api/old/queryorder'; $response = $this->curl('post', $url, $request); $log['type'] = 'query_response'; $log['data'] = $response; $log['config'] = $this->data; $this->log($log); $array = $this->json_decode($response); $result = array(); $result['status'] = 4; if (isset($array['nRtn'])) { if ($array['nRtn'] == '5012') { $result['nFlag'] = 2; $result['status'] = 2; } elseif ($array['nRtn'] == '5013') { $result['nFlag'] = 3; $result['status'] = 3; } if (isset($array['szRtnMsg']) && $array['szRtnMsg']) { $result['szRtnMsg'] = $array['szRtnMsg']; } } return $result; } private function _sign1($request, $param) { $signature_string = ''; foreach ($param as $k => $v) { $signature_string .= $v . '=' . $request[$v] . '&'; } $signature_string = substr($signature_string, 0, -1); $signature_string .= '&szKey=' . $this->token; return md5($signature_string); } # 提交数据 private function submit($param, $check) { $param = $this->param($param, $check); if (is_string($param) || (is_array($param) && $param['status'] == 1)) { return $param; } $request = $param['detail']; $request['uid'] = $this->mid; $request['orderid'] = $param['order']; $request['notify_url'] = $this->getNotify($param['order'], 1); ksort($request); $request['sign'] = $this->_sign($request); $url = $this->host . $this->api; $response = $this->curl('post', $url, $request); $response = $this->response($response); $channel_order_id = ''; if (isset($response['array']['szRtnCode']) && $response['array']['szRtnCode'] != 'success') { #警告类型 $channel_order_id = $response['array']['szRtnCode']; } $this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']); return $response['msg']; } private function _sign($request) { ksort($request); $signature_string = ''; foreach ($request as $k => $v) { $signature_string .= ($k . '=' . $v); } $signature_string .= $this->token; // $signature_string .='szKey='. $this->token; // var_dump($signature_string);exit; return md5($signature_string); } public function send_post($notify_url, $post_data, $type) { $postdata = http_build_query($post_data); $options = array( 'http' => array( 'method' => $type, 'header' => 'Content-type:application/x-www-form-urlencoded', 'content' => $postdata, 'timeout' => 15 * 60 // 超时时间(单位:s) ) ); $context = stream_context_create($options); $result = file_get_contents($notify_url, false, $context); return $result; } }