Пример #1
0
 /**
  * Get order id from the alipay return.
  * 
  * @param  string $mode  return|notify
  * @access public
  * @return object
  */
 public function getOrderFromAlipay($mode = 'return')
 {
     $this->app->loadClass('alipay', true);
     $alipay = new alipay($this->config->alipay);
     $orderID = 0;
     if ($mode == 'return') {
         if (1 or $alipay->checkNotify($_GET) and $this->get->trade_status == 'TRADE_FINISHED' || $this->get->trade_status == 'TRADE_SUCCESS') {
             $orderID = $this->get->out_trade_no;
             $sn = $this->get->trade_no;
         }
     } elseif ($mode == 'notify') {
         if ($alipay->checkNotify($_POST) and $this->post->trade_status == 'TRADE_FINISHED' || $this->post->trade_status == 'TRADE_SUCCESS') {
             $orderID = $this->post->out_trade_no;
             $sn = $this->post->trade_no;
         }
     }
     if ($orderID) {
         $orderID = $this->getRawOrder($orderID);
     }
     $order = $this->getByID($orderID);
     $order->sn = $sn;
     return $order;
 }
Пример #2
0
 function onPaymentNotification(&$statuses)
 {
     $vars = array();
     $data = array();
     $filter = JFilterInput::getInstance();
     foreach ($_REQUEST as $key => $value) {
         $key = $filter->clean($key);
         if (preg_match("#^[0-9a-z_-]{1,30}\$#i", $key) && !preg_match("#^cmd\$#i", $key)) {
             $value = JRequest::getString($key);
             $vars[$key] = $value;
             $data[] = $key . '=' . urlencode($value);
         }
     }
     $data = implode('&', $data) . '&cmd=_notify-validate';
     $order_id = (int) @$vars['out_trade_no'];
     $order_status = '';
     $dbOrder = $this->getOrder($order_id);
     $this->loadPaymentParams($dbOrder);
     if (empty($this->payment_params)) {
         return false;
     }
     $this->loadOrderData($dbOrder);
     if ($this->payment_params->debug) {
         $this->writeToLog(print_r($vars, true) . "\n\n\n");
         $this->writeToLog(print_r($dbOrder, true) . "\n\n\n");
     }
     if (empty($dbOrder)) {
         echo "Could not load any order for your notification " . $order_id;
         return false;
     }
     $old_status = $dbOrder->order_status;
     $url = HIKASHOP_LIVE . 'administrator/index.php?option=com_hikashop&ctrl=order&task=edit&order_id=' . $order_id;
     $order_text = "\r\n" . JText::sprintf('NOTIFICATION_OF_ORDER_ON_WEBSITE', $dbOrder->order_number, HIKASHOP_LIVE);
     $order_text .= "\r\n" . str_replace('<br/>', "\r\n", JText::sprintf('ACCESS_ORDER_WITH_LINK', $url));
     if ($this->payment_params->debug) {
         $this->writeToLog(print_r($dbOrder, true) . "\n\n\n");
     }
     $history = new stdClass();
     $email = new stdClass();
     $alipay = new alipay();
     $alipay->set_transport($this->payment_params->transport);
     $alipay->set_security_code($this->payment_params->security_code);
     $alipay->set_sign_type($this->payment_params->sign_type);
     $alipay->set_partner_id($this->payment_params->partner_id);
     if ($alipay->_transport == "https") {
         $notify_url = $alipay->_notify_gateway . "service=notify_verify" . "&partner=" . $alipay->_partner_id . "&notify_id=" . $_POST["notify_id"];
     } else {
         $notify_url = $alipay->_notify_gateway . "partner=" . $alipay->_partner_id . "&notify_id=" . $_POST["notify_id"];
     }
     $url_array = parse_url($notify_url);
     $errno = '';
     $errstr = '';
     $notify = array();
     $response = array();
     if ($url_array['scheme'] == 'https') {
         $transport = 'ssl://';
         $url_array['port'] = '443';
     } else {
         $transport = 'tcp://';
         $url_array['port'] = '80';
     }
     if ($this->payment_params->debug) {
         $this->writeToLog(print_r($url_array, true) . "\n\n\n");
     }
     $fp = @fsockopen($transport . $url_array['host'], $url_array['port'], $errno, $errstr, 60);
     if (!$fp) {
         $email->subject = JText::sprintf('NOTIFICATION_REFUSED_FOR_THE_ORDER', 'Alipay') . ' ' . JText::sprintf('PAYPAL_CONNECTION_FAILED', $dbOrder->order_number);
         $email->body = str_replace('<br/>', "\r\n", JText::sprintf('NOTIFICATION_REFUSED_NO_CONNECTION', 'Alipay')) . "\r\n\r\n" . $order_text;
         $this->modifyOrder($order_id, null, false, $email);
         JError::raiseError(403, JText::_('Access Forbidden'));
         return false;
     } else {
         fputs($fp, "POST " . $url_array['path'] . " HTTP/1.1\r\n");
         fputs($fp, "HOST: " . $url_array['host'] . "\r\n");
         fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
         fputs($fp, "Content-length: " . strlen($url_array['query']) . "\r\n");
         fputs($fp, "Connection: close\r\n\r\n");
         fputs($fp, $url_array['query'] . "\r\n\r\n");
         while (!feof($fp)) {
             $notify[] = @fgets($fp, 1024);
         }
         fclose($fp);
         if ($this->payment_params->debug) {
             $this->writeToLog(print_r($notify, true) . "\n\n\n");
         }
         $response = implode(',', $notify);
     }
     if (is_array($_POST)) {
         $tmp_array = array();
         foreach ($_POST as $key => $value) {
             if ($value != '' && $key != 'sign' && $key != 'sign_type') {
                 $tmp_array[$key] = $value;
             }
         }
         ksort($tmp_array);
         reset($tmp_array);
         $params = $tmp_array;
     } else {
         return false;
     }
     $sign = $alipay->_sign($params);
     if ($this->payment_params->debug) {
         $this->writeToLog("\n sign1 : \n" . print_r($sign, true) . "\n\n\n");
         $this->writeToLog("\n sign2 : \n" . print_r($_POST['sign'], true) . "\n\n\n");
     }
     if (preg_match('/true$/i', $response) && $sign == $_POST['sign'] && ($_POST['trade_status'] == 'TRADE_FINISHED' || $_POST['trade_status'] == 'TRADE_SUCCESS' || $_POST['trade_status'] == 'WAIT_SELLER_SEND_GOODS' || $_POST['trade_status'] == 'WAIT_BUYER_PAY')) {
         $price_check = round($dbOrder->order_full_price, (int) $this->currency->currency_locale['int_frac_digits']);
         $history->notified = 1;
         $history->amount = $price_check;
         $history->data = ob_get_clean();
         $order_status = $this->payment_params->verified_status;
         if ($dbOrder->order_status == $order_status) {
             return true;
         }
         $mail_status = $statuses[$order_status];
         $email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER', 'Alipay', $_POST['trade_status'], $dbOrder->order_number);
         $email->body = str_replace('<br/>', "\r\n", JText::sprintf('PAYMENT_NOTIFICATION_STATUS', 'Alipay', $_POST['trade_status'])) . ' ' . JText::sprintf('ORDER_STATUS_CHANGED', $mail_status) . "\r\n\r\n" . $order_text;
         $this->modifyOrder($order_id, $order_status, $history, $email);
         return true;
     } else {
         $email->subject = JText::sprintf('NOTIFICATION_REFUSED_FOR_THE_ORDER', 'Alipay') . 'invalid response';
         $email->body = JText::sprintf("Hello,\r\n An Alipay notification was refused because the response from the Alipay server was invalid") . "\r\n\r\n" . $order_text;
         $this->modifyOrder($order_id, null, false, $email);
         if ($this->payment_params->debug) {
             $this->writeToLog('invalid response' . "\n\n\n");
         }
         return false;
     }
 }
Пример #3
0
 private function payType1($order)
 {
     $inc_file = ROOT . '/api/payment/alipay/alipay.php';
     if (!file_exists($inc_file)) {
         $this->myError('error_common_param_error');
     }
     require_once $inc_file;
     $payment_api = new alipay($this->getPaymentInfo(1), $order);
     @header("Location:" . $payment_api->get_payurl());
     exit;
 }
Пример #4
0
 /**
  * postDeliveryToAlipay 
  * 
  * @param  int    $order 
  * @access public
  * @return void
  */
 public function postDeliveryToAlipay($order)
 {
     $this->app->loadClass('alipay', true);
     $alipayConfig = $this->config->alipay->secured;
     $alipayConfig->pid = $this->config->alipay->pid;
     $alipayConfig->key = $this->config->alipay->key;
     $alipayConfig->email = $this->config->alipay->email;
     $alipay = new alipay($alipayConfig);
     $expressList = $this->loadModel('tree')->getPairs(0, 'express');
     $express = zget($expressList, $this->post->express);
     return $alipay->postDelivery($order->sn, $express, $this->post->waybill);
 }
Пример #5
0
include_once ROOT_PATH . 'includes/lib_clips.php';
include_once ROOT_PATH . 'includes/lib_transaction.php';
include_once ROOT_PATH . 'includes/lib_payment.php';
include_once ROOT_PATH . 'includes/lib_order.php';
$act = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : 'default';
$order_id = isset($_REQUEST['order_id']) ? trim($_REQUEST['order_id']) : 0;
$smarty->assign('order_id', $order_id);
/*
$smarty->assign('appid', $appid);
$timestamp=time();
$smarty->assign('timestamp', $timestamp );
$class_weixin=new class_weixin($appid,$appsecret);
$signature=$class_weixin->getSignature($timestamp);
$smarty->assign('signature', $signature);
*/
$order_info = order_info($order_id);
$smarty->assign('order_info', $order_info);
if ($ua == 1) {
    //微信上打开
    //将openid记录下
    $smarty->assign('xaphp_sopenid', $_SESSION['xaphp_sopenid']);
    $smarty->display("toalipay.dwt");
} else {
    //其他浏览器上打开
    include_once 'includes/modules/payment/alipay.php';
    $pay_obj = new alipay();
    $payment = payment_info($order_info['pay_id']);
    $pay_online = $pay_obj->get_code($order_info, unserialize_config($payment['pay_config']));
    //$order['pay_desc'] = $payment['pay_desc'];
    echo $pay_online;
}