'szPhoneNum', 'cash' => 'nMoney', 'nSortType'=>'nSortType', 'szProductId'=>'szProductId', ); // print_r(); $param['nSortType'] = '1'; if (isset($param['isp']) && $param['isp']) { $param['nSortType']= $param['isp']; } $param['szProductId'] = '1000001'; if($param['nSortType'] == '1') { switch ($param['cash']) { case "30": $param['szProductId'] = '1000005'; break; case "50": $param['szProductId'] = '1000006'; break; case "100": $param['szProductId'] = '1000007'; break; case "200": $param['szProductId'] = '1000008'; break; } }elseif($param['nSortType'] == '2') { switch ($param['cash']) { case "30": $param['szProductId'] = '2000001'; break; case "50": $param['szProductId'] = '2000002'; break; case "100": $param['szProductId'] = '2000003'; break; case "200": $param['szProductId'] = '2000004'; break; } } $param['nProductClass']=1; $param['nProductType']=1; $this->sign = array('szAgentId', 'szOrderId', 'szPhoneNum', 'nMoney', 'nSortType', 'nProductClass','nProductType','szProductId','szTimeStamp'); $this->api = 'api/submitorder'; return $this->submit($param, $check); } # 通知处理 主要返回状态 2是成功 3是失败 public function notify($data) { $request = $data; $result = array(); $result['cash'] = 1; $result['status'] = 4; if ($data['nFlag'] == 2) { $result['status'] = 2; } else if($data['nFlag'] == 3) { $result['status'] = 3; }else { $result['status'] = 4; } if (isset($data['szRtnMsg']) && $data['szRtnMsg']) { # 错误信息 $msg = $result['msg'] = $data['szRtnMsg']; } $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['nRtn']) && $array['nRtn'] == '0') { # 正确 $msg = 'ok'; } else { # 错误 $msg = isset($array['desc']) ? $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 query($param) { } # 提交数据 private function submit($param, $check) { $param = $this->param($param, $check); if (is_string($param) || (is_array($param) && $param['status'] == 1)) { return $param; } // var_dump($request['szProductId']);exit; #TODO 结束 $request = $param['detail']; $request['szAgentId'] = $this->mid; $request['szOrderId'] = $param['order']; // $request['szPhoneNum'] = $param['account']; // $request['nMoney'] = $param['cash']; // $request['nSortType'] = $this->lprefix; $request['nProductClass'] = 1; $request['nProductType'] = 1; // $request['szProductId'] = $this->getGid($param['cash']); $request['szTimeStamp'] = date("Y-m-d H:i:s",time()); ksort($request); $request['szVerifyString'] = $this->_sign($request); $request['szNotifyUrl'] = $this->getNotify($param['order'], 1); // $request['szProductId'] = $productInfo['mapping_id']; $url = $this->host . $this->api; // $response = $this->curl('post', $url, $request,false,'Content-Type:application/x-www-form-urlencoded'); $response = $this->send_post($url,$request,'POST'); $response = $this->response($response); //$response['data'] = ''; //$response['msg'] = 'ok'; $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 _sign($request, $param='') { // $signature_string = ''; // // foreach ($request as $k => $v) { // if (isset($request[$k]) && $request[$k]) { // $signature_string .= $k . '=' . $request[$k] . '&'; // } // } $signature_string='szAgentId='.$request['szAgentId'].'&szOrderId='.$request['szOrderId'].'&szPhoneNum='.$request['szPhoneNum'].'&nMoney='.$request['nMoney'].'&nSortType='.$request['nSortType'].'&nProductClass='.$request['nProductClass'].'&nProductType=' .$request['nProductType'].'&szTimeStamp='.$request['szTimeStamp'].'&szKey='.$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; } }