'phone', 'cash' => 'price', 'teltype'=>'teltype', ); $param['teltype']= 1; if (isset($param['isp']) && $param['isp']) { $param['teltype']= $param['isp']; } $this->sign = array('mchid', 'phone', 'orderid', 'price', 'teltype','notify' ,'time','rand'); $this->api = 'api/telpay'; return $this->submit($param, $check); } public function ltcz($param) { $check = array ( 'mobile' => 'szPhoneNum', 'cash' => 'nMoney', 'nSortType'=>'nSortType', ); // $param['nSortType'] = '1'; // if (isset($param['isp']) && $param['isp']) { // $param['nSortType']= $param['isp']; // } $param['nSortType'] = 2; $param['nProductClass']=1; $param['nProductType']=1; $this->Operator = '联通'; $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(isset($data['query_status'])){ $data['status'] =$data['query_status']; } if ($data['status'] == 1) { $result['status'] = 2; } else if($data['status'] == 2) { $result['status'] = 3; }else { $result['status'] = 4; } if (isset($data['card_no']) && $data['card_no']) { # 流水号 $data['s_nubmer'] = $result['s_nubmer'] = $data['card_no']; } $result['yes'] = 'success';//根据接口要求响应对应数据 $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['desc'] ?? 'error'; } return array ( 'msg' => $msg, 'data' => $data, 'array' => $array, ); } # 查询接口 public function query($order) { $request['mchid'] = $this->mid; $request['order_id'] = $order['order_id']; $request['sign'] = $this->_sign($request, array('mchid', 'order_id')); $url = $this->host . 'api/telpay/query'; $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['status']) ) { if($array['status'] == 2){ $result['query_status'] = 1; $result['status'] = 2; }elseif ($array['status'] == 3){ $result['query_status'] = 2; $result['status'] = 3; } if (isset($array['voucher']) && $array['voucher']) { # 流水号 // $data['szRtnMsg'] $result['s_number'] = $array['voucher']; } } return $result; } private function _sign1($request, $param) { // ksort($request); // var_dump($request);die; $signature_string = ''; foreach ($param as $k => $v) { // var_dump($request[$v]);die; // if (isset($request[$v]) && $request[$v]) { $signature_string .= $v . '=' . $request[$v] . '&'; // var_dump($signature_string);die; } $signature_string = substr($signature_string, 0, -1); $signature_string .= '&szKey='.$this->token; // var_dump($signature_string);die; // $signature_string = iconv("UTF-8", "gbk", $signature_string); 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; } #TODO 以下修改 // $getphoneinfo = \app\core\Service::instance()->ispguishudi($param['account']); // if($getphoneinfo == 1){ // $getphoneinfo = $this->getMobileInfo($param['account']); // } // // $getphoneinfo['province'] = str_replace('省','', $getphoneinfo['province']); // // if($this->Operator){ // $getphoneinfo['sp'] = $this->Operator ; // } // // $mappingname = $getphoneinfo['province'].$getphoneinfo['sp'].$param['cash'].'元'; // // // $productInfo = ProductMappingService::instance()->getMapping($mappingname,$this->channel['id'],'mapping_id');#2=cid,$mappingname为名字,mappingid直接返回映射id // if(!$productInfo){ // // $productInfo = ProductMappingService::instance()->getMapping('全国'.$getphoneinfo['sp'].$param['cash'].'元',$this->channel['id'],'mapping_id');#2=cid,$mappingname为名字,mappingid直接返回映射id // if(!$productInfo){ // $productInfo = ProductMappingService::instance()->getMapping($mappingname,2,'mapping_id');#2=cid,$mappingname为名字,mappingid直接返回映射id // } // // if(!$productInfo){ // $productInfo = ProductMappingService::instance()->getMapping('全国'.$getphoneinfo['sp'].$param['cash'].'元',2,'mapping_id');#2=cid,$mappingname为名字,mappingid直接返回映射id // } // //// if ($param['cash'] == '100'){ //// $mapping_id = '2000100'; //// }elseif($param['cash'] == '200'){ //// $mapping_id = '2000200'; //// } //// $productInfo = [ //// 'mapping_id' => $mapping_id //// ]; //// //// }else{ // // // // } #TODO 结束 $request = $param['detail']; $request['mchid'] = $this->mid; $request['orderid'] = $param['order']; $request['time'] = time(); $request['rand'] = rand(100000,999999); $request['notify'] = $this->getNotify($param['order'], 1); ksort($request); $request['sign'] = $this->_sign($request); // $request['notify'] = $this->getNotify($param['order'], 1); // $request['szProductId'] = $productInfo['mapping_id']; $url = $this->host . $this->api; $response = $this->curl('post', $url, $request); // $response = $this->send_post($url,$request,'POST'); $response = $this->response($response); //$response['data'] = ''; //$response['msg'] = 'ok'; $channel_order_id = ''; // if (isset($response['array']['code']) && $response['array']['code'] != 1) { // #警告类型 // $channel_order_id = $response['array']['order_id']; // } // $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='mchid='.$request['mchid'].'&phone='.$request['phone'].'&price='.$request['price'].'&orderid='.$request['orderid'].'&teltype='.$request['teltype'].'¬ify='.$request['notify'].'&time=' .$request['time'].'&rand='.$request['rand'].$this->token; 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; } }