<?php
if(!defined('R_P')) exit('Access Denied');
$pd = array();
parse_str(qbase :: authcode(trim(urldecode($_GET['param'])), 'DECODE'), $pd);
if(empty($pd['id']) || empty($pd['channelid']) || empty($pd['d']) || !isset($pd['u']) || empty($pd['action'])) qbase::showmsg("bad request");
$_output = qbase::get_object('content', $pd['channelid'], $pd['id'], false)->get();
if(empty($_output))  qbase::showmsg("bad request");
$_pay_purview = array(
	'id' => $_output['id'],
	'cid' => $_output['cid'],
	'point' => $_output['requirepoint'],
	'read_purview' => $_output['read_purview'],
	'pay_type' => $_output['pay_type'],
	'read_last' => $_output['read_last'],
);
require_once(R_P . '/include/class.userpay.php');
if($pd['action'] == 'check'){
	$purview = new userpay($_output['channelid'], $_pay_purview);
	$data = $purview -> purviewContent();
	if($data['status'] == 200){
		if($data['paytype'] == true || $data['pay_log'] > 0){
			 $data['location'] = $purview->createSureLink('view');
		}else{
			$data['pay_link'] = $purview->createSureLink('pay');
		}
	}
}else if($pd['action'] == 'pay'){
	$purview = new userpay($_output['channelid'], $_pay_purview, trim(urldecode($_GET['param'])));
	if($purview->view == 0) qbase::showmsg("bad request view");
	$data = $purview -> purviewContent();
	$data['location'] = $purview->createSureLink('view');
}else{
	qbase::showmsg("bad request");
}
$data['action'] = $pd['action'];
$data['info'] = $_pay_purview;
echo qbase::xmlprint(qbase::jsonencode($data));
?>