Esempio n. 1
0
 public static function getMongoUtilObject()
 {
     $mongoConfig = TenYear::get_val('mongoConfig');
     $config = array('host' => $mongoConfig['host'], 'port' => $mongoConfig['port'], 'option' => array('connect' => true), 'db_name' => $mongoConfig['db'], 'username' => $mongoConfig['user'], 'password' => $mongoConfig['pass']);
     $mongoUtilObj = new MongoUtil();
     $mongoUtilObj->init($config);
     $mongoUtilObj->selectCollection($mongoConfig['collection']);
     return $mongoUtilObj;
 }
Esempio n. 2
0
 function GetMessage()
 {
     $url = 'https://mp.weixin.qq.com/cgi-bin/message?t=message/list&count=1000' . '&day=7&token=' . $this->token . '&lang=zh_CN';
     $httpClient = new HttpUtil();
     $httpClient->referer = 'https://mp.weixin.qq.com/advanced/autoreply?t=ivr/reply&action=beadded&token=' . $this->token . '&lang=zh_CN';
     $httpClient->getHeader = "0";
     $result = $httpClient->GetContent($url);
     if (preg_match('/\\{\\"msg_item\\":\\[(.*)\\]\\}/', $result, $matches)) {
         $objectres = json_decode($matches[0]);
         $mongoClient = new MongoUtil("testwechat");
         foreach ($objectres->msg_item as $object) {
             $findres = $mongoClient->finone("message", array("messageid" => $object->id));
             if (!isset($findres)) {
                 $doc = array("messageid" => $object->id, "fakeid" => $object->fakeid, "nick_name" => $object->nick_name, "content" => $object->content, "date_time" => $object->date_time);
                 $mongoClient->insert("message", $doc);
             } else {
                 break;
             }
         }
     } else {
         print_r($result);
     }
 }
Esempio n. 3
0
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
include __DIR__ . '/Mongo/MongoUtil.php';
Route::get('/', function () {
    $mongoClient = new MongoUtil('testwechat');
    $list = $mongoClient->getTop100('message');
    return View::make('hello')->with('list', $list);
});
Route::get('add/{id}', function ($id) {
    $mongoClient = new MongoUtil('testwechat');
    $querydoc = array('_id' => new MongoId($id));
    $queryres = $mongoClient->finone('message', $querydoc);
    if ($queryres != null) {
        $doc = array('messageid' => $queryres['messageid'], 'fakeid' => $queryres['fakeid'], 'nick_name' => $queryres['nick_name'], 'content' => $queryres['content']);
        $mongoClient->insert('pushqueue', $doc);
    }
    return Redirect::to('/');
});