'attach', 'cash' => 'cash', ); $param['api_product'] = 'dhcz'; $this->api='dockapi/index/buy'; return $this->submit($param, $check); } public function cardbuy($param) { $check = array ( 'cash' => 'cash', ); $param['api_product'] = 'cardbuy'; $this->api='dockapi/index/buy'; return $this->submit($param, $check); } public function yxkm_cardbuy($param) { $check = array ( 'cash' => 'cash', ); $param['api_product'] = 'cardbuy'; $this->api='dockapi/index/buy'; return $this->submit($param, $check); } # 中石油油卡充值 拼音来吧 public function zsycz($param) { $check = array ( 'card' => 'card', 'cash' => 'cash', //'idCard' => 'idCard', //'realName' => 'realName', 'api_product' => 'api_product', ); $param['api_product'] = 'zsycz'; return $this->submit($param, $check); } # 中石化油卡充值 public function zshcz($param) { $check = array ( 'card' => 'card', 'cash' => 'cash', 'api_product' => 'api_product', ); $param['api_product'] = 'zshcz_tc'; return $this->submit($param, $check); } # 中石化油卡充值透传 public function zshcz_tc($param) { $check = array ( 'card' => 'card', 'cash' => 'cash', 'api_product' => 'api_product', ); $param['api_product'] = 'zshcz_tc'; return $this->submit($param, $check); } #Q币充值 public function qbcz($param) { $check = array ( // 'cash' => 'cash', 'num' => 'buynum', 'account' => 'attach' ); if(!isset($param['num'])){ $param['num'] = 1; } // $this->product= 'cardbuy'; $this->api='dockapi/index/buy'; return $this->submit($param, $check); } # 通知处理 主要返回状态 2是成功 3是失败 public function notify($data) { $request = $data; unset($request['sign']); // $request = $this->getParam($request, $this->token, 2); // if ($request['signature'] != $data['signature']) { // return false; // } $result = array(); $result['cash'] = 1; $result['status'] = 4; if(isset($data['query_status'])){ $data['status'] = $data['query_status']; $data['is_query'] = 1; } if(isset($data['status'])){ if ($data['status'] == 5) { $result['status'] = 2; } elseif ($data['status'] == 4) { $result['status'] = 3; } else { $result['status'] = 4; } } if(isset($this->data['channel_order_id']) && $this->data['channel_order_id'] && isset($data['outorderno']) && $data['outorderno'] && $data['outorderno'] != $this->data['channel_order_id']){ $result['yes'] = 'fail'; $result['status'] = 4; $data['msg'] = $result['msg'] = '上游订单号不匹配'; $result['data'] = $data; return $result; } if ($result['status'] == 2 && isset($data['receipt'])) { # 流水号 $data['s_number'] = $result['s_number'] = $data['receipt']; } if ($result['status'] == 3 && isset($data['refundreceipt']) && $data['refundreceipt']) { # 错误信息 $data['msg'] = $result['msg'] = $data['refundreceipt']; } // $result['data'] = $data; $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['code']) && $array['code'] == 1) { # 正确 $msg = 'ok'; } else { # 错误 $msg = $array['msg'] ?? 'error'; } return array ( 'msg' => $msg, 'data' => $data, 'array' => $array, ); } # 查询接口 public function query($order) { $request['userid'] = $this->mid; $request['orderno'] = $order['order_id']; $request['sign'] = $this->_sign($request); $url = $this->host . 'dockapi/index/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,true); $result = array(); $result['status'] = 4; if (isset($array['code'])&&$array['code']==1 ) { if($array['data']['status'] ==5){ $result['query_status'] = 5; $result['status'] = 2; }elseif ($array['data']['status'] == 4){ $result['query_status'] = 4; $result['status'] = 3; } } if(isset($array['cardlist'])){ $result['kami']=array( // 'cardno' => isset($array['data']['cards'][0]['card_no'])?$array['data']['cards'][0]['card_no']:'', // 'cardpwd' => $array['data']['cards'][0]['card_password'], // 'expired' => $array['data']['cards'][0]['expired_at'], ); } return $result; } # 查询余额接口 public function account($day) { $request['day'] = $day; $request['appid'] = $this->mid; $request['api_product'] = 'query'; $request = $this->getParam($request, $this->token, 2); $url = $this->host . 'gateway/api.handle/accountByDay'; $response = $this->curl('post', $url, $request); $response = $this->response($response); return $response['array']['data']; } # 提交数据 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']; if(isset($this->product) && $this->product['key']){ switch ($this->product['key']){ case 'qbcz': $price = $this->getPrice($param['cash']); $total_cash = $param['cash']*$request['buynum']; $out_price = $this->getPrice($total_cash); $total_price =$price*$request['buynum'] ; if(1<$total_cash && $total_cash<5){ #修改导致价格高于,走新价格 $total_price = 20; } if($out_price != -1){ if($total_price> $out_price){ $request['goodsid'] = $this->getGid($total_cash); $request['buynum'] = 1; $request['maxmoney'] = $out_price; }else{ $request['goodsid'] = $this->getGid($param['cash']); $request['maxmoney'] = $total_price; } }else{ $request['goodsid'] = $this->getGid($param['cash']); $request['maxmoney'] = $total_price; } break; } } $request['userid'] = $this->mid; $request['outorderno'] = $param['order']; $request['callbackurl'] = $this->getNotify($param['order'], 1); $request['sign'] =$this->_sign($request); $url = $this->host . $this->api; $response = $this->curl('post', $url, $request); $response = $this->response($response); $channel_order_id = ''; if($response['array']['code']==1 && isset($response['array']['orderno'])){ $channel_order_id = $response['array']['orderno']; } $this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']); return $response['msg']; } protected function getPrice($cash) { $info = $this->product; if ($info) { if (isset($info['rule']) && $info['rule']) { $rule = json_decode($info['rule'], true); if (isset($rule[$cash]) && $rule[$cash]) { $price_rule = $rule[$cash]; if($info['percent_type'] == 1){ $price = $price_rule / 100 * $cash; }elseif($info['percent_type'] == 2){ $price = $price_rule; } return $price; } } // if (isset($info['percent']) && $info['percent']) { // if($info['percent_type'] == 1){ // $price = $info['percent'] / 100 * $cash; // }elseif($info['percent_type'] == 2){ // $price = $info['percent']; // } // return $price; // } } return -1; } private function _sign($param){ ksort($param); //排序post参数 reset($param); //内部指针指向数组中的第一个元素 $signtext=''; foreach ($param AS $key => $val) { //遍历POST参数 if ($val == '' || $key == 'sign') continue; //跳过这些不签名 if ($signtext) $signtext .= '&'; //第一个字符串签名不加& 其他加&连接起来参数 $signtext .= "$key=$val"; //拼接为url参数形式 } $newsign=md5($signtext.$this->token); return $newsign; } }