'number', ); $this->productId = true; if (isset($param['isp']) && $param['isp']) { $this->lprefix = $param['isp']; } $this->api = 'hqorder/api/submit'; return $this->submit($param, $check); } #联通充值 public function ltcz($param) { $check = array ( 'mobile' => 'number', ); $this->productId = true; if (isset($param['isp']) && $param['isp']) { $this->lprefix = $param['isp']; } $this->api = 'hqorder/api/submit'; return $this->submit($param, $check); } public function ydcz($param) { $check = array ( 'mobile' => 'number', ); $this->productId = true; if (isset($param['isp']) && $param['isp']) { $this->lprefix = $param['isp']; } $this->api = 'hqorder/api/submit'; return $this->submit($param, $check); } public function dxcz($param) { $check = array ( 'mobile' => 'number', ); $this->productId = true; if (isset($param['isp']) && $param['isp']) { $this->lprefix = $param['isp']; } $this->api = 'hqorder/api/submit'; return $this->submit($param, $check); } # 通知处理 主要返回状态 2是成功 3是失败 public function notify($data) { $request = $data; $result = array(); $result['cash'] = 1; $result['status'] = 4; if ($data['status'] == 2) { $result['status'] = 2; } else if($data['status'] == 3) { $result['status'] = 3; }else { $result['status'] = 4; } if (isset($data['voucher']) && $data['voucher']) { # 流水号 $data['s_nubmer'] = $result['s_nubmer'] = $data['voucher']; } $result['yes'] = '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['status']) && $array['status'] == '0') { # 正确 $msg = 'ok'; } else { # 错误 $msg = $array['msg'] ?? 'error'; } return array ( 'msg' => $msg, 'data' => $data, 'array' => $array, ); } # 查询余额接口 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); $request['mchid'] = $this->mid; $request['sign'] = $this->_sign($request); $url = $this->host . 'hqorder/api/query'; $response = $this->curl('post', $url, $request,true); $response = $this->response($response); return $response['array']['data']; } # 查询接口 public function query($order) { $request['mchid'] = $this->mid; $request['orderid'] = $order['order']; $request['sign'] = $this->_sign($request); $url = $this->host . "hqorder/api/query"; $response = $this->curl('post', $url, $request,true); $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['status'])) { if ($array['status'] == '2') { // $result['state'] = $array['data']['state']; $result['status'] = 2; } elseif ($array['status'] == '4' || $array['status'] == '3') { // $result['state'] = $array['data']['state']; $result['status'] = 3; } if (isset($array['voucher']) && $array['voucher']) { # 流水号 // $data['szRtnMsg'] $result['voucher'] = $array['voucher']; } } return $result; } # 取消接口,没有把数据控掉 public function cancel($order) { } # 提交数据 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['mchid'] = $this->mid; $request['orderid'] = $param['order']; if($this->productId){ $request['productid'] =$this->getDhczCode($this->lprefix,$param['cash'] ); }else{ $request['productid'] = $this->getGid($param['cash']); } $request['timestamp'] = time()*1000; $request['sign'] = $this->_sign($request); $request['backurl'] = $this->getNotify($param['order'], 1); // ksort($request); $url = $this->host . $this->api; $response = $this->curl('post', $url, $request,true); // $response = $this->send_post($url,$request,'POST'); $response = $this->response($response); //$response['data'] = ''; //$response['msg'] = 'ok'; $channel_order_id = ''; if (isset($response['array']['data']['oid']) && $response['array']['data']['oid']) { #渠道订单号 $channel_order_id = $response['array']['data']['oid']; } // $channel_order_id = ''; $this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']); return $response['msg']; } private function getDhczCode($paytype,$cash) { if ($paytype == '1') { if ($cash == 50) { return 30; } elseif ($cash == 100) { return 24; } elseif ($cash == 200) { return 25; } } elseif ($paytype == '2') { if ($cash == 50) { return 32; } elseif ($cash == 100) { return 28; } elseif ($cash == 200) { return 29; } } else { if ($cash == 50) { return 31; } elseif ($cash == 100) { return 26; } elseif ($cash == 200) { return 27; } } return false; } // private function _sign($request, $param='') { // 字典排序 ksort($request); // 拼接签名串 $sign_str = http_build_query($request) . '&key='. $this->token; // $sign_str = http_build_query($request) . '&apikey='. $this->token; // var_dump($sign_str);die; // 签名 $sign = md5(urldecode($sign_str)); return $sign; } }