'code', 'account' => 'account', 'num' => 'number', ); $this->api = 'api/order/tk'; return $this->submit($param, $check); } # 数据响应格式处理 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'] == '0' ) { # 正确 if(isset($array['data']['cardNoData'])){ $msg = 'yescard'; $kami = $this->decrypt_3des($array['data']['cardNoData']); if($kami){ $kami = explode(',', $kami); $array['kami'] = [ 'cardno' => $kami[0], 'cardpwd' => $kami[1], 'expired' => $kami[2]??'', ]; }else{ $msg = 'ok'; } }else{ $msg = 'ok'; } # 正确 } else { # 错误 $msg = $array['msg'] ?? 'error'; } return array ( 'msg' => $msg, 'data' => $array, 'array' => $array, ); } # 查询接口 public function query($order) { $request['appid'] = $this->mid; $request['orderNo'] = $order['order_id']; $request['sign'] = $this->_sign($request); $url = $this->host . 'api/order/tkQuery'; $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); $array['status'] = 4; if (isset($array['code']) && $array['code'] == '0' ) { # 正确 if(isset($array['data']['cardNoData'])){ $msg = 'yescard'; $kami = $this->decrypt_3des($array['data']['cardNoData']); if($kami){ $kami = explode(',', $kami); $array['kami'] = [ 'cardno' => $kami[0], 'cardpwd' => $kami[1], 'expired' => $kami[2]??'', ]; $this->upOrderResponse( $array['kami'],$order['merchant_order_id'],$order['response']); $array['status'] = 7; }else{ $array['status'] = 2; } } } else { $array['status'] = 3; } return $array; } # 通知处理 主要返回状态 2是成功 3是失败 public function notify($data) { $result = array(); $result['cash'] = 1; $result['status'] = $data['status'] ; if (isset($data['kami']) && $data['kami']['cardno']) { # 流水号 $data['s_nubmer'] = $result['s_nubmer'] = $data['kami']['cardno']; } $result['yes'] = 'ok'; $result['data'] = $data; return $result; } # 提交数据 private function submit($param, $check) { $param = $this->param($param, $check); if (is_string($param) || (is_array($param) && $param['status'] == 1)) { return $param; } // var_dump($param);die; $request = $param['detail']; $request['appid'] = $this->mid; $request['type'] = $this->getGid($param['cash']); $request['orderNo'] = $param['order']; $request['is_dynamic'] = 0; $request['sign'] = $this->_sign($request); $url = $this->host . $this->api; $response = $this->curl('post', $url, $request,true); $response = $this->response($response); $channel_order_id = ''; if (isset($response['array']['data']['orderNo'])) { $channel_order_id = $response['array']['data']['orderNo']; } $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) { $signature_string = ''; ksort($request); foreach ($request as $k => $v) { // if (isset($request[$v]) && $request[$v]) { $signature_string .= $k . '=' . $v . '&'; } $signature_string .= 'key='.($this->token); $sign = MD5($signature_string); // var_dump($signature_string);die; // $signature_string = iconv("UTF-8", "gbk", $signature_string); return strtoupper($sign); } #3des解密 public function decrypt_3des($encrypted_string){ $cipher = "des-ede3"; // 3des-ebc 使用的是des-ede3算法 $mode = "ebc"; // 工作模式为ebc $iv = ""; // EBC模式不需要IV,留空即可 $json = $this->channel['other_data']; $array = $this->json_decode($json); if(isset($array['aeskey'])){ $this->deskey = $array['aeskey']; } return openssl_decrypt(hex2bin($encrypted_string), $cipher, $this->deskey, $options=OPENSSL_RAW_DATA, $iv); // 输出解密后的字符串 } public function upOrderResponse($kami,$merchant_order_id,$orderResponse) { $orderService = OrderService::instance(); $response = json_decode($orderResponse,true); $response['kami'] = $kami; $data = ['response' => json_encode($response)]; $orderService->db()->where(array('merchant_order_id' => $merchant_order_id))->update($data); } }