Example #1
0
<?php

include_once "log.php";
include_once "recharge.php";
$config = (include "config.php");
header("Content-type: text/html; charset=utf-8");
log::init('./log', 'apple_log');
$uri = $_SERVER['REQUEST_URI'];
$body = file_get_contents('php://input');
log::instance()->debug("new con: {$uri} {$body}");
$body = json_decode(urldecode($body), true);
//$url = "https://buy.itunes.apple.com/verifyReceipt";
$url = "https://sandbox.itunes.apple.com/verifyReceipt";
$receipt = json_encode(array("receipt-data" => $body["receipt-data"]));
$response = sendPostData($url, $receipt);
$content = json_decode($response['content'], true);
if ($content["status"] !== 0) {
    log::instance()->error("ret: 验证失败 errCode:" . $content["status"]);
    echo "fail";
    exit;
}
$pf_info = $config["apple"]["appstore"];
$note = $content["receipt"];
$ret = recharge($pf_info["PF"], $body["sid"], $body["odr"], $body["uid"], $note["product_id"], "apple", $note["transaction_id"], 0);
log::instance()->debug("ret: " . $ret);
if ($ret == "SUCCESS" || $ret == "TRADE_NO NOT EXIST") {
    echo "success";
} else {
    echo "fail";
}
function sendPostData($url, $data)
Example #2
0
}
// Response url
$url = "https://hooks.slack.com/services/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";
// Pull latest event post ID
$id = $conn->query("SELECT ID FROM wp_posts\n\t\t\t\t\t\tWHERE post_type = 'post'\n\t\t\t\t\t\tAND post_status = 'publish'\n\t\t\t\t\t\tORDER BY ID\n\t\t\t\t\t\tDESC LIMIT 1");
// Convert ID from MySQLi object to associative array (hash/dictionary) and then to string
$id = $id->fetch_assoc();
$id = $id['ID'];
// Pull metadata from that post ID
$result = $conn->query("SELECT meta_key,meta_value FROM wp_postmeta\n\t\t\t\t\t\tWHERE post_id = '{$id}'");
$data = array();
// Return formatted data
while ($row = $result->fetch_assoc()) {
    $data[$row['meta_key']] = array();
    $data[$row['meta_key']][] = $row['meta_value'];
}
// Construct payload
$payload = ["text" => "Latest event is: *<http://www.mvlaza.org?p=" . $id . "|" . $data['Event name'][0] . ">*", "attachments" => [["fallback" => "Event info", "color" => "#D00000", "fields" => [["title" => "Start location", "value" => $data['Start location'][0], "short" => true], ["title" => "Start time", "value" => $data['Start date'][0] . " at " . $data['Start time'][0], "short" => true], ["title" => "End location", "value" => $data['End location'][0], "short" => true], ["title" => "End time", "value" => $data['End date'][0] . " at " . $data['End time'][0], "short" => true], ["title" => "What to bring", "value" => $data['What to bring'][0], "short" => false]]]]];
// Encode it and send it away
$payload = json_encode($payload);
sendPostData($url, $payload);
function sendPostData($url, $payload)
{
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type' => 'application/json'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
    curl_exec($ch);
    curl_close($ch);
}
$conn->close();
Example #3
0
function updateSentiment($i)
{
    require "../includes/connect.php";
    require "../functions/string.php";
    //empty ranking table
    //$truncateQuery = "TRUNCATE TABLE `sentrank`";
    //mysqli_query($conn, $truncateQuery) or die(mysqli_error($conn));
    $updateDate = new DateTime();
    $updateDate = $updateDate->format('Y-m-d G:i:s');
    //G = 24 hour format
    //convert to dd/mm/yyyy
    //$oldDate = $updateDate;
    //$timestamp = strtotime($oldDate);
    //$updateDate = date('d/m/Y', $timestamp);
    $rowCountQuery = "SELECT COUNT(*) FROM moviename";
    $rowCount = mysqli_query($conn, $rowCountQuery);
    $rowCountRow = mysqli_fetch_array($rowCount);
    $rowCount = $rowCountRow[0];
    $count = round($rowCount / 2, 0, PHP_ROUND_HALF_UP);
    if ($i == 1) {
        $selectQuery = "SELECT movieId FROM moviename LIMIT {$count}";
    } else {
        if ($i == 2) {
            //(SELECT * FROM table ORDER BY id DESC LIMIT 50) ORDER BY id ASC
            $selectQuery = "SELECT * FROM (\n\t\t\t\t\t\t\t    SELECT * FROM moviename ORDER BY movieId DESC LIMIT {$count}\n\t\t\t\t\t\t\t) sub\n\t\t\t\t\t\t\tORDER BY movieId ASC";
        }
    }
    //$selectQuery = "SELECT movieId FROM moviename";
    $selectResult = mysqli_query($conn, $selectQuery) or die(mysqli_error($conn));
    $unwantedChars = array(',', '!', '?', "'", " ", ":", "+", "#");
    // create array with unwanted chars
    while ($row = mysqli_fetch_array($selectResult)) {
        $movieId = mysqli_real_escape_string($conn, $row['movieId']);
        $name = normalizeCaseSen($row['movieId']);
        $results = array();
        //rpp = tweetcount (max=  100)
        $tweetUrl = "http://tweets2csv.com/results.php?q=%23" . $name . "&rpp=40&submit=Search";
        echo $tweetUrl . "<br>";
        $htmltext = file_get_contents($tweetUrl);
        $regex = "#<div class='user'>(.*)(\\s*)<div class='text'>(.*)<div class='description'>#";
        preg_match_all($regex, $htmltext, $matches, PREG_SET_ORDER);
        $data = array("data" => array());
        //for word cloud
        $wordArray = array();
        $unwantedTweetChars = array('/', "\\", 'http', "@", "-", "<a");
        foreach ($matches as $tweet) {
            $newData = array("text" => htmlentities($tweet[3]));
            array_push($data["data"], $newData);
            //get keywords from tweets
            $words = explode(" ", $tweet[3]);
            foreach ($words as $word) {
                if (!contains($word, $unwantedTweetChars) && !in_array(normalize($word), $stopwords) && strpos($word, "href") == false) {
                    if (!isset($wordArray[$word])) {
                        $wordArray[$word] = 1;
                    } else {
                        $wordArray[$word]++;
                    }
                }
            }
        }
        //word cloud
        //if array not empty then update
        if (strpos(json_encode($wordArray), '[]') !== false) {
            $wordFilename = normalize($row['movieId']);
            $wordFilepath = '../words/' . $wordFilename . '.txt';
            if (file_put_contents($wordFilepath, json_encode($wordArray)) != false) {
                echo "added";
            } else {
                echo "Cannot create file (" . basename($newFileName) . ")";
            }
            echo "<br> word cloud done ";
        }
        //sentiment140 api
        $url_send = 'http://www.sentiment140.com/api/bulkClassifyJson?jackchan715@hotmail.com';
        //$data = '{"data": [{"text": "I love Titanic."}, {"text": "I hate Titanic."}]}';
        /*
        Requests should be sent via HTTP POST to http://www.sentiment140.com/api/bulkClassifyJson. 
        The body of the message should be a JSON object
        
        e.g. {"data": [{"text": "I love Titanic."}, 
                 					 {"text": "I hate Titanic."}]}
        */
        /*
        $data = array(
        			"data"=> array(0=>array("text"=>"I love Titanic."), 
        						   1=>array("text"=> "I hate Titanic.")
        						   )
        			);
        */
        $str_data = json_encode($data);
        $result = sendPostData($url_send, $str_data);
        //echo $result;
        $data = json_decode($result);
        //true for array format
        //print_r to see the json in array for so you know how to parse
        //$rating = $data['data']['movies'][0]['rating'];
        //print_r($data);
        $sent = array("positive" => 0, "negative" => 0, "neutral" => 0, "tweetCount" => 0);
        foreach ($data->data as $tweet) {
            if ($tweet->polarity == 4) {
                $sent['positive']++;
            } else {
                if ($tweet->polarity == 2) {
                    $sent['neutral']++;
                } else {
                    if ($tweet->polarity == 0) {
                        $sent['negative']++;
                    }
                }
            }
            $sent['tweetCount']++;
        }
        $positive = $sent['positive'];
        $negative = $sent['negative'];
        $sentQuery = "INSERT into `sentrank` (`movieId`, `positive`, `negative`) VALUES ('{$movieId}', '{$positive}', '{$negative}') ON DUPLICATE KEY UPDATE `positive`='{$positive}', `negative`='{$negative}'";
        if (!mysqli_query($conn, $sentQuery)) {
            die('Error: ' . mysqli_error($conn));
        }
        echo "sentrank updated,  ";
        //format (just split by / and :)
        $newFileName = '../sentiment/' . $name . ".txt";
        $appendContent = $sent['positive'] . ";" . $sent['negative'] . ";" . $sent['neutral'] . ";" . $sent['tweetCount'] . ";" . $updateDate . "/";
        //If filename does not exist, the file is created. Otherwise, the existing file is overwritten, unless the FILE_APPEND flag is set.
        if (file_put_contents($newFileName, $appendContent, FILE_APPEND) != false) {
            echo "File created (" . basename($newFileName) . ")";
        } else {
            echo "Cannot create file (" . basename($newFileName) . ")";
        }
    }
    mysqli_close($conn);
}
Example #4
0
function updateSentiment()
{
    require "../includes/connect.php";
    require "../functions/string.php";
    $selectQuery = "SELECT movieId FROM moviename WHERE name LIKE '%Star Wars%'";
    $selectResult = mysqli_query($conn, $selectQuery) or die(mysqli_error($conn));
    $unwantedChars = array(',', '!', '?', "'", " ", ":", "+", "#");
    // create array with unwanted chars
    while ($row = mysqli_fetch_array($selectResult)) {
        $movieId = mysql_real_escape_string($row['movieId']);
        $name = normalizeCaseSen($row['movieId']);
        //$hashtag = "#".$name;
        $results = array();
        //rpp = tweetcount (max=  100)
        $tweetUrl = "http://tweets2csv.com/results.php?q=%23" . $name . "&rpp=40&submit=Search";
        echo $tweetUrl . "<br>";
        $htmltext = file_get_contents($tweetUrl);
        $regex = "#<div class='user'>(.*)(\\s*)<div class='text'>(.*)<div class='description'>#";
        preg_match_all($regex, $htmltext, $matches, PREG_SET_ORDER);
        $data = array("data" => array());
        foreach ($matches as $tweet) {
            //'text'=>$tweet[3],
            $newData = array("text" => htmlentities($tweet[3]));
            array_push($data["data"], $newData);
        }
        //sentiment140 api
        $url_send = 'http://www.sentiment140.com/api/bulkClassifyJson?jackchan715@hotmail.com';
        //$data = '{"data": [{"text": "I love Titanic."}, {"text": "I hate Titanic."}]}';
        /*
        $data = array(
        			"data"=> array(0=>array("text"=>"I love Titanic."), 
        						   1=>array("text"=> "I hate Titanic.")
        						   )
        			);
        */
        $str_data = json_encode($data);
        $result = sendPostData($url_send, $str_data);
        //echo $result;
        $data = json_decode($result);
        //true for array format
        //print_r to see the json in array for so you know how to parse
        //$rating = $data['data']['movies'][0]['rating'];
        //print_r($data);
        $sent = array("positive" => 0, "negative" => 0, "neutral" => 0, "tweetCount" => 0);
        foreach ($data->data as $tweet) {
            if ($tweet->polarity == 4) {
                $sent['positive']++;
            } else {
                if ($tweet->polarity == 2) {
                    $sent['neutral']++;
                } else {
                    if ($tweet->polarity == 0) {
                        $sent['negative']++;
                    }
                }
            }
            $sent['tweetCount']++;
        }
        print_r($sent);
    }
}