java中常见的几种异常
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
$auth = base64_encode(json_encode($pass));
}
$vars = array();
$vars['uniacid'] = $_W['uniacid'];
$vars['__auth'] = $auth;
$vars['forward'] = base64_encode($url);
return $_W['siteroot'] . 'app/' . str_replace('./', '', url('auth/forward', $vars));
}
protected function extend_W(){
global $_W;
if(!empty($_W['openid'])){
load()->model('mc');
$_W['member'] = mc_fetch($_W['openid']);
}
if(empty($_W['member'])){
$_W['member'] = array();
}
if(!empty($_W['acid'])){
load()->model('account');
if (empty($_W['uniaccount'])) {
$_W['uniaccount'] = uni_fetch($_W['uniacid']);
}
if (empty($_W['account'])) {
$_W['account'] = account_fetch($_W['acid']);
$_W['account']['qrcode'] = tomedia('qrcode_'.$_W['acid'].'.jpg').'?time='.$_W['timestamp'];
$_W['account']['avatar'] = tomedia('headimg_'.$_W['acid'].'.jpg').'?time='.$_W['timestamp'];
$_W['account']['groupid'] = $_W['uniaccount']['groupid'];
}
}
}
}
abstract class WeModuleReceiver extends WeBase {
public $params;
public $response;
public $keyword;
public $message;
abstract function receive();
}
abstract class WeModuleSite extends WeBase {
public $inMobile;
public function __call($name, $arguments) {
$isWeb = stripos($name, 'doWeb') === 0;
$isMobile = stripos($name, 'doMobile') === 0;
if($isWeb || $isMobile) {
$dir = IA_ROOT . '/addons/' . $this->modulename . '/inc/';
if($isWeb) {
$dir .= 'web/';
$fun = strtolower(substr($name, 5));
}
if($isMobile) {
$dir .= 'mobile/';
$fun = strtolower(substr($name, 8));
}
$file = $dir . $fun . '.inc.php';
if(file_exists($file)) {
require $file;
exit;
}
}
trigger_error("访问的方法 {$name} 不存在.", E_USER_WARNING);
return null;
}
protected function pay($params = array(), $mine = array()) {
global $_W;
if(!$this->inMobile) {
message('支付功能只能在手机上使用');
}
$params['module'] = $this->module['name'];
$pars = array();
$pars[':uniacid'] = $_W['uniacid'];
$pars[':module'] = $params['module'];
$pars[':tid'] = $params['tid'];
if($params['fee'] <= 0) {
$pars['from'] = 'return';
$pars['result'] = 'success';
$pars['type'] = 'alipay';
$pars['tid'] = $params['tid'];
$site = WeUtility::createModuleSite($pars[':module']);
$method = 'payResult';
if (method_exists($site, $method)) {
exit($site->$method($pars));
}
}
$sql = 'SELECT * FROM ' . tablename('core_paylog') . ' WHERE `uniacid`=:uniacid AND `module`=:module AND `tid`=:tid';
$log = pdo_fetch($sql, $pars);
if(!empty($log) && $log['status'] == '1') {
message('这个订单已经支付成功, 不需要重复支付.');
}
$setting = uni_setting($_W['uniacid'], array('payment', 'creditbehaviors'));
if(!is_array($setting['payment'])) {
message('没有有效的支付方式,
请联系网站管理员.');
}
$pay = $setting['payment'];
if (empty($_W['member']['uid'])) {
$pay['credit']['switch'] = false;
}
if (!empty($pay['credit']['switch'])) {
$credtis = mc_credit_fetch($_W['member']['uid']);
}
$iscard = pdo_fetchcolumn('SELECT iscard FROM ' . tablename('modules') . ' WHERE name = :name', array(':name' => $params['module']));
$you = 0;
if($pay['card']['switch'] == 2 && !empty($_W['openid'])) {
if($_W['card_permission'] == 1 && !empty($params['module'])) {
$cards = pdo_fetchall('SELECT a.id,a.card_id,a.cid,b.type,b.title,b.extra,b.is_display,b.status,b.date_info FROM ' . tablename('coupon_modules') . ' AS a LEFT JOIN ' . tablename('coupon') . ' AS b ON a.cid = b.id WHERE a.acid = :acid AND a.module = :modu AND b.is_display = 1 AND b.status = 3 ORDER BY a.id DESC', array(':acid' => $_W['acid'], ':modu' => $params['module']));
$flag = 0;
if(!empty($cards)) {
foreach($cards as $temp) {
$temp['date_info'] = iunserializer($temp['date_info']);
if($temp['date_info']['time_type'] == 1) {
$starttime = strtotime($temp['date_info']['time_limit_start']);
$endtime = strtotime($temp['date_info']['time_limit_end']);
if(TIMESTAMP < $starttime || TIMESTAMP > $endtime) {
continue;
} else {
$param = array(':acid' => $_W['acid'], ':openid' => $_W['openid'], ':card_id' => $temp['card_id']);
$num = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('coupon_record') . ' WHERE acid = :acid AND openid = :openid AND card_id = :card_id AND status = 1', $param);
if($num <= 0) {
continue;
} else {
$flag = 1;
$card = $temp;
break;
}
}
} else {
$deadline = intval($temp['date_info']['deadline']);
$limit = intval($temp['date_info']['limit']);
$param = array(':acid' => $_W['acid'], ':openid' => $_W['openid'], ':card_id' => $temp['card_id']);
$record = pdo_fetchall('SELECT addtime,id,code FROM ' . tablename('coupon_record') . ' WHERE acid = :acid AND openid = :openid AND card_id = :card_id AND status = 1', $param);
if(!empty($record)) {
foreach($record as $li) {
$time = strtotime(date('Y-m-d', $li['addtime']));
$starttime = $time + $deadline * 86400;
$endtime = $time + $deadline * 86400 + $limit * 86400;
if(TIMESTAMP < $starttime || TIMESTAMP > $endtime) {
continue;
} else {
$flag = 1;
$card = $temp;
break;
}
}
}
if($flag) {
break;
}
}
}
}
if($flag) {
if($card['type'] == 'discount') {
$you = 1;
$card['fee'] = sprintf("%.2f", ($params['fee'] * ($card['extra'] / 100)));
} elseif($card['type'] == 'cash') {
$cash = iunserializer($card['extra']);
if($params['fee'] >= $cash['l
east_cost']) {
$you = 1;
$card['fee'] = sprintf("%.2f", ($params['fee'] - $cash['reduce_cost']));
}
}
load()->classs('coupon');
$acc = new coupon($_W['acid']);
$card_id = $card['card_id'];
$time = TIMESTAMP;
$randstr = random(8);
$sign = array($card_id, $time, $randstr, $acc->account['key']);
$signature = $acc->SignatureCard($sign);
if(is_error($signature)) {
$you = 0;
}
}
}
}
if($pay['card']['switch'] == 3 && $_W['member']['uid']) {
$cards = array();
if(!empty($params['module'])) {
$cards = pdo_fetchall('SELECT a.id,a.couponid,b.type,b.title,b.discount,b.condition,b.starttime,b.endtime FROM ' . tablename('activity_coupon_modules') . ' AS a LEFT JOIN ' . tablename('activity_coupon') . ' AS b ON a.couponid = b.couponid WHERE a.uniacid = :uniacid AND a.module = :modu AND b.condition <= :condition AND b.starttime <= :time AND b.endtime >= :time ORDER BY a.id DESC', array(':uniacid' => $_W['uniacid'], ':modu' => $params['module'], ':time' => TIMESTAMP, ':condition' => $params['fee']), 'couponid');
if(!empty($cards)) {
$condition = '';
if($iscard == 1) {
$condition = " AND grantmodule = '{$params['module']}'";
}
foreach($cards as $key => &$card) {
$has = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('activity_coupon_record') . ' WHERE uid = :uid AND uniacid = :aid AND couponid = :cid AND status = 1' . $condition, array(':uid' => $_W['member']['uid'], ':aid' => $_W['uniacid'], ':cid' => $card['couponid']));
if($has > 0){
if($card['type'] == '1') {
$card['fee'] = sprintf("%.2f", ($params['fee'] * $card['discount']));
$card['discount_cn'] = sprintf("%.2f", $params['fee'] * (1 - $card['discount']));
} elseif($card['type'] == '2') {
$card['fee'] = sprintf("%.2f", ($params['fee'] - $card['discount']));
$card['discount_cn'] = $card['discount'];
}
} else {
unset($cards[$key]);
}
}
}
}
if(!empty($cards)) {
$cards_str = json_encode($cards);
}
}
include $this->template('common/paycenter');
}
public function payResult($ret) {
global $_W;
if($ret['from'] == 'return') {
if ($ret['type'] == 'credit2') {
message('已经成功支付', url('mobile/channel', array('name' => 'index', 'weid' => $_W['weid'])));
} else {
message('已经成功支付', '../../' . url('mobile/channel', array('name' => 'index', 'weid' => $_W['weid'])));
}
}
}
protected function payResultQuery($tid) {
$sql = 'SELECT * FROM ' . tablename('core_paylog') . ' WHERE `module`=:module AND `tid`=:tid';
$params = array();
$params[':module'] = $this->module['name'];
$params[':tid'] = $tid;
$log = pdo_fetch($sql, $params);
$ret = array();
if(!empty($log)) {
$ret['uniacid'] = $log['uniacid'];
$ret['result'] = $log['status'] == '1'
? 'success' : 'failed';
$ret['type'] = $log['type'];
$ret['from'] = 'query';
$ret['tid'] = $log['tid'];
$ret['user'] = $log['openid'];
$ret['fee'] = $log['fee'];
}
return $ret;
}
protected function grant($params = array()) {
global $_W, $_GPC;
if (empty($_W['member']['uid'])) {
checkauth();
}
load()->model('activity');
$params['module'] = $this->module['name'];
if(empty($params['module'])) {
message('模块信息错误', referer(), 'error');
}
$iscard = pdo_fetchcolumn('SELECT iscard FROM ' . tablename('modules') . ' WHERE name = :name', array(':name' => $params['module']));
if(!$iscard) {
message('模块不支持领取优惠券', referer(), 'error');
}
$pindex = max(1, intval($_GPC['page']));
$psize = 5;
$user = mc_fetch($_W['member']['uid'], array('groupid'));
$groupid = $user['groupid'];
$modules_limit = pdo_fetchall("SELECT couponid FROM ".tablename('activity_coupon_modules')." WHERE uniacid = :uniacid AND module = :module", array(':uniacid' => $_W['uniacid'], ':module' => $params['module']), 'couponid');
$groups_limit = pdo_fetchall("SELECT couponid FROM ".tablename('activity_coupon_allocation')." WHERE uniacid = :uniacid AND groupid = :groupid", array(':uniacid' => $_W['uniacid'], ':groupid' => $groupid), 'couponid');
$modules_limit = array_keys($modules_limit);
$groups_limit = array_keys($groups_limit);
$intersect = array_intersect($modules_limit, $groups_limit);
if(empty($intersect)) {
message('没有该模块适用的优惠券', referer(), 'error');
}
$intersect = implode(',', array_values($intersect));
$par = array(':uniacid' => $_W['uniacid'], ':time' => TIMESTAMP);
$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('activity_coupon') . " WHERE uniacid = :uniacid AND dosage < amount AND endtime >= :time AND couponid IN ({$intersect})", $par);
$cards = pdo_fetchall('SELECT * FROM ' . tablename('activity_coupon') . " WHERE uniacid = :uniacid AND dosage < amount AND endtime >= :time AND couponid IN ({$intersect}) ORDER BY endtime ASC LIMIT " . ($pindex - 1) * $psize . ', ' . $psize, $par);
if(!empty($cards)) {
foreach($cards as $key => &$card) {
$has = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('activity_coupon_record') . ' WHERE uid = :uid AND uniacid = :aid AND couponid = :cid AND status > 0', array(':uid' => $_W['member']['uid'], ':aid' => $_W['uniacid'], ':cid' => $card['couponid']));
$card['is_grant'] = 1;
if($card['limit'] <= $has) {
$card['is_grant'] = 0;
}
$card['grant_num'] = $has;
$card['grant_url'] = base64_encode(json_encode(array('id' => $card['couponid'], 'm' => $params['module'])));
}
$creditnames = array();
$unisettings = uni_setting($_W['uniacid'], array('creditnames'));
if (!empty($unisettings) && !empty($unisettings['creditnames'])) {
foreach ($unisettings['creditnames'] as $key=>$credit) {
$creditname
s[$key] = $credit['title'];
}
}
}
$pager = pagination($total, $pindex, $psize, '', array('before' => 0, 'after' => 0));
include $this->template('common/grant');
}
public function grantResult($ret) {
global $_W;
if($ret['result'] == 'success') {
$types = array('', 'coupon', 'token');
message('领取优惠券成功', url('activity/' . $types[$ret['type']] . '/mine'), 'success');
}
}
public function grantCherk($ret) {
global $_W;
return true;
}
protected function share($params = array()) {
global $_W;
$url = murl('utility/share', array('module' => $params['module'], 'action' => $params['action'], 'sign' => $params['sign'], 'uid' => $params['uid']));
echo <<
EOF;
}
protected function click($params = array()) {
global $_W;
$url = murl('utility/click', array('module' => $params['module'], 'action' => $params['action'], 'sign' => $params['sign'], 'tuid' => $params['tuid'], 'fuid' => $params['fuid']));
echo <<
EOF;
}
}
abstract class WeModuleCron extends WeBase {
public function __call($name, $arguments) {
if($this->modulename == 'task') {
$dir = IA_ROOT . '/framework/builtin/task/cron/';
} else {
$dir = IA_ROOT . '/addons/' . $this->modulename . '/cron/';
}
$fun = strtolower(substr($name, 6));
$file = $dir . $fun . '.inc.php';
if(file_exists($file)) {
require $file;
exit;
}
trigger_error("访问的方法 {$name} 不存在.", E_USER_WARNING);
return error(-1009, "访问的方法 {$name} 不存在.");
}
public function addCronLog($tid, $errno, $note, $tag = array()) {
global $_W;
if(!$tid) {
message(error(-1, 'tid参数错误'), '', 'ajax');
}
$data = array(
'uniacid' => $_W['uniacid'],
'module' => $this->modulename,
'type' => $_W['cron']['filename'],
'tid' => $tid,
'note' => $note,
'tag' => iserializer($tag),
'createtime' => TIMESTAMP
);
pdo_insert('core_cron_record', $data);
message(error($errno, $note), '', 'ajax');
}
}