'chargeNo', 'cash' => 'denomination', 'chargeType' => 'chargeType', ); $param['chargeType'] = 2; $this->api = 'H1001'; return $this->submit($param, $check); } # 通知处理 主要返回状态 2是成功 3是失败 public function notify($data) { $request = $data; unset($request['sign']); unset($request['s_order']); $sign = $this->_sign($request); if ($sign != $data['sign']) { return false; } $data = $this->ecbDecrypt($request['data'], $this->token); $data = json_decode($data, true); $result = array(); $result['cash'] = 1; if ($data['orderStatus'] == 2) { $result['status'] = 2; } elseif ($data['orderStatus'] == 3) { $result['status'] = 3; } else { $result['status'] = 4; } if (isset($data['remark1']) && $data['orderId']) { # 流水号 //$data['s_nubmer'] = $result['s_nubmer'] = $data['orderId']; } $result['yes'] = '{"result":1}'; $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['result']) && $array['result'] == '1') { # 正确 $msg = 'ok'; } else { # 错误 $msg = isset($array['errDesc']) ? $array['errDesc'] : 'error'; } return array ( 'msg' => $msg, 'data' => $data, 'array' => $array, ); } # 主动查询接口 public function query($order) { } # 提交数据 private function submit($param, $check) { $param = $this->param($param, $check); if (is_string($param) || (is_array($param) && $param['status'] == 1)) { return $param; } $data = $param['detail']; $data['serviceCode'] = $this->api; $data['denomination'] = $data['denomination']*100; $data['prodType'] = 6; $data['channelOrderId'] = $param['order']; $data['orderNum'] = 1; $data['requestTime'] = date('Y-m-d H:i:s'); $data['prodCode'] = $this->getGid($param['cash']);; $data['notifyUrl'] = $this->getNotify($param['order'], 1); $request = array(); $request['partner'] = $this->mid; $request['version'] = '1.0'; list($msec, $sec) = explode(' ', microtime()); $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); $msec = substr($msectime,0,13); $request['time'] = $msec; //$request['data'] = '{"channelOrderId": "XBD2022080523", "requestTime": "2022-08-05 14:58:00", "prodCode": "DB00050198", "serviceCode": "H1001", "chargeType": "2", "orderNum": "1", "notifyUrl": "http://xxx.xx.xxx/notify", "chargeNo": "cat840084", "chargeName": "cat840084", "prodType": "6"}'; //$request['data'] = json_decode($request['data'], true); $request['data'] = $this->ecbEncrypt(json_encode($data), $this->token); $request['sign'] = $this->_sign($request); $url = $this->host; $response = $this->curl('post', $url, $request, true); $response = $this->response($response); $channel_order_id = ''; if (isset($response['array']['detailInfo']['channelOrderId'])) { //$channel_order_id = $response['array']['detailInfo']['channelOrderId']; } $this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']); return $response['msg']; } private function _sign($data) { $json = json_encode($data); $json = str_split($json); asort($json); $json = implode('', $json); $json = str_replace('\\', '', $json); return md5($json); } private function ecbEncrypt($input, $key) { $size = @mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); $input = $this->pkcs5_pad($input, $size); $td = @mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, ''); $iv = @mcrypt_create_iv (@mcrypt_enc_get_iv_size($td), MCRYPT_RAND); @mcrypt_generic_init($td, $key, $iv); $data = @mcrypt_generic($td, $input); @mcrypt_generic_deinit($td); @mcrypt_module_close($td); $data = base64_encode($data); return $data; } private function ecbDecrypt($data, $key) { $decrypted= @mcrypt_decrypt( MCRYPT_RIJNDAEL_128, $key, base64_decode($data), MCRYPT_MODE_ECB ); $dec_s = strlen($decrypted); $padding = ord($decrypted[$dec_s-1]); $decrypted = substr($decrypted, 0, -$padding); return $decrypted; } private function pkcs5_pad($text, $blocksize) { $pad = $blocksize - (strlen($text) % $blocksize); return $text . str_repeat(chr($pad), $pad); } }