name = $name; $this->config = $config; } private function getType($type, $currency) { if ($type < 5 && $currency == 'SAR') { $type = 4; } $name = $value = $method = $command = ''; switch ($type) { case 1: # 目前不支持 $name = 'Pay with credit cards (Redirection)'; $method = 'redirection'; break; case 2: $name = 'Pay with installments (Redirection)'; $method = 'redirection'; break; case 3: $name = 'Pay with NAPS'; $value = 'NAPS'; $method = 'redirection'; break; case 4: $name = 'Pay with SADAD'; $value = 'SADAD'; $currency = 'SAR'; $method = 'redirection'; $command = 'AUTHORIZATION'; break; case 11: $name = 'Pay with credit cards (Merchant Page)'; $method = 'page'; $currency = ''; $command = 'TOKENIZATION'; break; case 12: $name = 'Pay with installments (Merchant Page)'; $method = 'page'; break; case 21: $name = 'Pay with credit cards (Merchant Page 2.0)'; $method = 'page_v2'; break; } $currency = strtoupper($currency); return array ( 'id' => $type, 'name' => $name, 'value' => $value, 'method' => $method, 'currency' => $currency, 'command' => $command, ); } /** * 获取统一下单的基本信息 */ public function order($uid, $account, $product_name, $amount, $currency, $type = 1) { $type = $this->getType($type, $currency); $order_id = $this->createOrder($uid, $this->name, $product_name, $amount, $type['currency'], $type['name']); $method = $type['method']; $param = array(); if ($type['currency']) { $param['amount'] = $amount; $param['currency'] = $type['currency']; } $param = $this->param($order_id, $type['command'], $type['value'], $param); return $this->$method($param); } /** * 通知回调 * * @return mixed */ public function notify() { return 1; } /** * 生成基本参数 * * @return mixed */ private function param($order_id, $command, $payment_option, $param = array()) { $param['access_code'] = $this->config['access_code']; $param['merchant_identifier'] = $this->config['merchant_id']; $param['merchant_reference'] = $order_id; $param['language'] = $this->language; if ($payment_option) { $param['payment_option'] = $payment_option; } # AUTHORIZATION(授权)、PURCHASE(购买) TOKENIZATION CHECK_STATUS $param['command'] = $command; $param['return_url'] = Dever::url('api.notify?order_id=' . $order_id, 'payment'); $param['signature'] = $this->signature($this->config['request_phrase'], $param); return $param; } /** * 页面付款,下单后需要填写用户信息 * * @return mixed */ public function page($param) { print_r($param);die; $result = Dever::curl($this->url, $param, 'post'); print_r($result);die; } /** * 直接付款 Redirection * * @return mixed */ public function redirection($param) { $html = '
loading...
'; echo $html;die; } /** * signature * * @return mixed */ private function signature($phrase, $request) { ksort($request); $signature_string = ''; foreach ($request as $k => $v) { $signature_string .= $k . '=' . $v; } $signature_string = $phrase . $signature_string . $phrase; return hash('sha256', $signature_string); } }