Example #1
0
try {
    $posts = WaPost::FindPostByWall($wall, $totalLimit);
    if (!$posts) {
        throw new Exception('暂无新帖。');
    }
} catch (Exception $e) {
    returnError($e->getMessage());
    return;
}
for ($i = 0; $i < $offset; $i++) {
    next($posts);
}
while (list($key, $post) = each($posts)) {
    $post_id = $post['post_id'];
    try {
        $postInfo = WaPost::GetPostInfo($post_id);
        if (!$postInfo) {
            throw new Exception('');
        }
    } catch (Exception $e) {
        continue;
    }
    $post = array();
    $post['post_id'] = $postInfo['post_id'];
    $post['post_title'] = $postInfo['post_title'];
    $post['post_content'] = $postInfo['post_content'];
    $creator = $postInfo['post_creator'];
    try {
        $creator_info = WaUser::GetUserInfo($creator);
    } catch (Exception $e) {
        continue;
Example #2
0
function createPost($wall, $title, $content)
{
    global $loginUser;
    if (!$loginUser) {
        returnError('请先登录');
        return;
    }
    try {
        $userData = WaUser::GetUserData($loginUser);
        if (!$userData) {
            throw new Exception('获取用户失败。');
        }
    } catch (Exception $e) {
        returnError($e->getMessage());
        return;
    }
    $wealth = $userData['user_wealth'];
    if ($wealth < 1) {
        returnError('墙砖不够。');
        return;
    }
    $userData['user_wealth'] -= 1;
    $userData['user_exp'] += 1;
    try {
        $ret = WaPost::CreatePost($wall, $title, $content, $loginUser);
        if (!$ret) {
            throw new Exception('创建帖子失败。');
        }
        $ret = WaUser::SetUserData($loginUser, $userData);
        if (!$ret) {
            throw new Exception('扣墙砖失败。');
        }
    } catch (Exception $e) {
        returnError($e->getMessage());
        return;
    }
    $ret = array('post_id', $ret);
    echo json_encode($ret);
}