'cardid', 'num' => 'num', ); $this->api = 'order.aspx'; return $this->submit($param, $check); } # 糖果宏卡购买卡密 public function tghk_cardbuy($param) { // var_dump($param);die; $check = array ( 'proid' => 'cardid', 'num' => 'num', ); $this->api = 'order.aspx'; return $this->submit($param, $check); } #砖石宏卡 public function zshk_cardbuy($param) { // var_dump($param);die; $check = array ( 'proid' => 'cardid', 'num' => 'num', ); $this->api = 'order.aspx'; return $this->submit($param, $check); } public function cardbuy($param) { // var_dump($param);die; $check = array ( 'proid' => 'cardid', 'num' => 'num', ); $this->api = 'order.aspx'; return $this->submit($param, $check); } # 数据响应格式处理 public function response($data) { //$data = '9313Q20221121061042337696218792446200成功0000BpwQYs759WBmODjU3QoRNGuz5GwTVEG8Z+7lcC3ApgXSEujRU8BExjF/Vr3oJrYD2024-04-30 00:00:0010.0000'; $log['type'] = 'response'; $log['data'] = $data; $log['config'] = $this->data; $this->log($log); //$array = $this->json_decode($data); $array = (array) simplexml_load_string($data); // var_dump($array);die; // $array = (array) $array['info']; // var_dump($array);die; if (isset($array['Order']) && $array['Order']) { $array['Order'] = (array) $array['Order']; } if (isset($array['info']) && $array['info']) { $array['info'] = (array) $array['info']; } if (isset($array['Card']) && $array['Card']) { $array['Card'] = (array) $array['Card']; } // if (isset($array['Card']) && $array['Card']) { // // $arrayCard = (array) $array['Card']; // } // var_dump($array);die; // var_dump($array);die; if (!$array) { $msg = 'error'; } elseif (isset($array['info']['ret']) && $array['info']['ret'] == '0' && isset($array['Order']['orderid']) && $array['Order']['orderid']) { # 正确 $msg = 'yescard'; if (isset($array['Card'])) { // $array['Card'] = (array) $array['Card']; $cardlist = $array['Card']; $merchant = MerchantService::instance()->get($this->data['merchant']); // $cardlist = (array) $cardlist; $array['kami'] = array ( 'cardno' => $cardlist['cardnum'], 'cardpwd' => $cardlist['cardpass'], 'expired' => $cardlist['expriedate'], 'value' => $array['Order']['rtlprice'], ); // if (is_array($cardlist)) { // foreach ($cardlist as $k => $v) { // var_dump($v); // $v = (array) $v; // var_dump($v); // $array['card'][] = array // ( // 'cardno' => $v['cardnum'], // 'cardpwd' => $v['cardpass'], // 'expired' => $v['expriedate'], // 'value' => $array['Order']['rtlprice'], // ); // } // } else { // $cardlist = (array) $cardlist; // $array['card'][] = array // ( // 'cardno' => $cardlist['cardnum'], // 'cardpwd' => $cardlist['cardpass'], // 'expired' => $cardlist['expriedate'], // 'value' => $array['Order']['rtlprice'], // ); // } } } else { # 错误 $msg = $array['info']['ret_msg'] ?? 'error'; } return array ( 'msg' => $msg, 'data' => $array, 'array' => $array, ); } # 查询接口 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; } $request = $param['detail']; $request['username'] = $this->mid; $request['cardid'] = $this->getGid($param['cash']); $request['sporder_id'] = $param['order']; $request['paytype'] = '0'; if (isset($_SERVER['SERVER_ADDR'])) { $request['client_ip'] = $_SERVER['SERVER_ADDR']; } elseif (isset($_SERVER['LOCAL_ADDR'])) { $request['client_ip'] = $_SERVER['LOCAL_ADDR']; } else { $request['client_ip'] = '1.1.1.1'; } // $output = shell_exec('curl ifconfig.me 2>/dev/null'); // $ip = trim($output); // var_dump($output);die; $request['password'] = $this->token; $request['client_ip'] = '124.223.48.127'; $request['sporder_time'] = date('YmdHis'); $request['version'] = '1.0'; //$request['returnurl'] = $this->getNotify($param['order'], 1); $request['sign'] = $this->_sign($request, array('username', 'cardid', 'num', 'paytype', 'sporder_id', 'sporder_time','client_ip')); $url = $this->host . $this->api; $response = $this->curl('get', $url, $request); // var_dump($response);die; // var_dump($response); $response = $this->response($response); //$response['data'] = ''; //$response['msg'] = 'ok'; $channel_order_id = ''; if (isset($response['array']['Order']['orderid'])) { $channel_order_id = $response['array']['Order']['orderid']; } $param['account'] = $request['cardid']; $this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']); return $response['array']['card'] ?? $response['msg']; } private function _sign($request, $param) { //ksort($request); $signature_string = ''; foreach ($param as $k => $v) { // if (isset($request[$v]) && $request[$v]) { $signature_string .= $v . '=' . $request[$v] . '&'; } $signature_string = substr($signature_string, 0, -1); $signature_string .= '||'.md5($this->token); // var_dump($signature_string);die; // $signature_string = iconv("UTF-8", "gbk", $signature_string); return md5($signature_string); } }