/** * mysql日志 * * @param unknown $error * @param unknown $errstr */ function mysql($errno, $errstr) { $out = date(http::time(), "Y-m-d H:i:s") . ' ' . $errno . ' ' . $errstr; if (filesystem::path($this->_config['mysql_path'])) { file_put_contents($this->_config['mysql_path'], $out); } }
function __call($name, $args) { if (!empty($args)) { return $this->call('index', '__404'); } $template = $this->_template_dir . $name . '.html'; $http = http::getInstance(); $base_template = ROOT . '/application/template/' . $template; if (file_exists($base_template)) { $this->view = new view($this->_config, $template); return $this->view->display(); } else { return $this->call('index', '__404'); } }
/** * 将文件的绝对转化为url访问地址 */ static function realpathToUrl($path) { if (empty($path)) { return ''; } if (substr($path, 0, 4) == 'http') { return $path; } if (is_file($path)) { $path = str_replace(realpath(ROOT), '', realpath($path)); $http = http::getInstance(); $protocal = $http->isHttps() ? 'https://' : 'http://'; return str_replace('\\', '/', rtrim('http://' . $http->host() . $http->path(), '/\\') . $path); } return ''; }
/** * url生成 * @param unknown $parameter * @return mixed */ function url($parameter) { $http = http::getInstance(); $c = $parameter['c']; $a = $parameter['a']; $urlencode = false; if (isset($parameter['urlencode'])) { $urlencode = $parameter['urlencode']; unset($parameter['urlencode']); } unset($parameter['c']); unset($parameter['a']); $array = array('c' => $c, 'a' => $a, 'array' => $parameter); if (!$urlencode) { return call_user_func_array(array($http, 'url'), $array); } else { return urlencode(call_user_func_array(array($http, 'url'), $array)); } }
/** * 退款 * @param $refund 退款申请记录 * @param $order 订单 */ function refund($refund, $order) { $http = http::getInstance(); $account = new \stdClass(); $account->transOut = $this->_system->get('splitpartner', 'alipay'); $account->amount = $this->_system->get('splitrate', 'alipay') * $refund['money']; $account->currency = 'CNY'; $split_fund_info = array($account); $data = array('service' => 'forex_refund', 'partner' => $this->_system->get('partner', 'alipay'), '_input_charset' => $this->_config['input_charset'], 'sign_type' => $this->_config['sign_type'], 'notify_url' => ($http->isHttps() ? 'https://' : 'http://') . $http->host() . '/gateway/alipay/notify.php', 'out_return_no' => $refund['refundno'], 'out_trade_no' => $order['orderno'], 'return_rmb_amount' => $refund['money'], 'currency' => 'EUR', 'gmt_return' => date("YmdHis", $refund['time']), 'reason' => $refund['reason'], 'product_code' => 'NEW_WAP_OVERSEAS_SELLER', 'split_fund_info' => json_encode($split_fund_info)); if ($order['client'] == 'web') { $data['product_code'] = 'NEW_OVERSEAS_SELLER'; } $data = $this->trade($data); $response = file_get_contents($this->_config['gateway_url'] . '?' . http_build_query($data)); $response = xmlToArray($response); return $response; }
/** * 微信支付入口 * @param unknown $order * @param unknown $orderdetail * @param array $prepay 微信预支付订单信息 */ function submit($order, $orderdetail) { $this->_order = $order; $this->_orderdetail = $orderdetail; $http = http::getInstance(); if (empty($this->_get->openid)) { //没有openid则通过gateway获取openid $url = 'http://' . $http->host() . '/gateway/weixin/getopenid.php'; $parameter = array('id' => $order['id'], 'trade_type' => $this->_get->trade_type); $url = $this->createGetRequest($url, $parameter); $response = array('action' => 'redict', 'content' => $url); return $response; } else { //生成商品描述 $body = ''; foreach ($this->_orderdetail as $good) { $body .= $good['productname'] . 'x' . $good['num'] . '|'; } $timeout = (new time())->format($this->_system->get('timeout', 'payment'), false); $notify_url = 'http://' . $_SERVER['HTTP_HOST'] . '/gateway/weixin/notify.php'; //生成预支付订单 $data = array('device_info' => 'WEB', 'time_start' => date("YmdHis", $order['createtime']), 'time_expire' => date("YmdHis", $order['createtime'] + $timeout), 'appid' => $this->_system->get('appid', 'weixin'), 'fee_type' => 'CNY', 'mch_id' => $this->_system->get('mchid', 'weixin'), 'openid' => $this->_get->openid, 'trade_type' => strtoupper($this->_get->trade_type), 'attach' => '', 'body' => $body, 'nonce_str' => random::word(32), 'notify_url' => $notify_url, 'out_trade_no' => $this->_order['orderno'], 'spbill_create_ip' => empty($_SERVER['REMOTE_ADDR']) ? 'unkonwn' : $_SERVER['REMOTE_ADDR'], 'total_fee' => $this->_order['ordertotalamount'] * 100); if ($data['trade_type'] == 'NATIVE') { //扫码支付时添加商品id $data['product_id'] = ''; //商品id } $content = $this->createPrepay($data); $xmlResult = new \SimpleXMLElement($content); $xmlResult = $this->xmlToArray($xmlResult); if ($xmlResult['return_code'] != 'SUCCESS') { return array('action' => 'error', 'content' => $xmlResult['return_msg']); } else { if ($this->verifyResult($xmlResult)) { //有效的微信信息 if ($xmlResult['result_code'] != 'FAIL') { //订单生成成功 return array('action' => 'return', 'content' => $xmlResult); } else { //订单生成失败 比如已经生成过了 return array('action' => 'error', 'content' => $xmlResult['err_code'] . '|' . $xmlResult['err_code_des']); } } else { return array('action' => 'error', 'content' => '无效的微信消息'); } } } }
/** * 映射 * @param unknown $name * @param unknown $args */ function __call($name, $args) { if (!empty($args)) { return $this->call('index', '__404'); } if ($name != 'login') { if (!login::o2o()) { $this->response->setCode(302); $this->response->addHeader('Location', $this->http->url('o2ocenter', 'login')); return false; } } $action = array('index', 'search', 'profile'); $template = $this->_template_dir . $name . '.html'; $http = http::getInstance(); $base_template = ROOT . '/application/template/' . $template; if (file_exists($base_template)) { $this->view = new view($this->_config, $template); if (in_array($name, $action)) { //加载系统配置 $systemModel = $this->model('system'); $system = $systemModel->fetch(array('system')); $temp = array(); foreach ($system as $key => $value) { $temp[$value['name'] . '_' . $value['type']] = $value['value']; } $this->view->assign('system', $temp); //载入用户的o2o配置 $o2oModel = $this->model('o2ouser'); $o2o = $o2oModel->get($this->session->id); if (empty($o2o)) { return $this->call('index', '__404'); } //载入用户的基本信息 $userModel = $this->model('user'); $user = $userModel->get($this->session->id); $this->view->assign('user', $user); switch ($name) { case 'search': $start = empty(filter::int($this->get->start)) ? 0 : filter::int($this->get->start); $length = empty(filter::int($this->get->length)) ? 10 : filter::int($this->get->length); $this->view->assign('start', $start); $this->view->assign('length', $length); $query = str_replace(' ', '%', str_replace(' ', ' ', $this->get->query)); $userModel = $this->model('user'); $userModel->where('user.oid=?', array($this->session->id)); if (!empty($query)) { $userModel->where('(username like ? or telephone like ? or email like ?)', array('%' . $query . '%', '%' . $query . '%', '%' . $query . '%')); } $userModel->limit($start, $length); $search = $userModel->select(); $this->view->assign('search', $search); break; default: } $this->view->assign('o2o', $o2o); } return $this->view->display(); } else { return $this->call('index', '__404'); } }