Example #1
0
function _log_focus($openid, $operation, $user_info = NULL)
{
    R::addDatabase('wechat_csc', $GLOBALS['db_wechat_csc_url'], $GLOBALS['db_wechat_csc_user'], $GLOBALS['db_wechat_csc_pass']);
    R::selectDatabase('wechat_csc');
    if (!R::testConnection()) {
        exit('DB failed' . PHP_EOL);
    }
    R::freeze(true);
    try {
        $user = R::getRedBean()->dispense('wxcsc_focus');
        $user->openid = $openid;
        $user->operation = $operation;
        if ($operation == 'focus' && $user_info != NULL) {
            $user->nickname = $user_info['nickname'];
            $user->sex = $user_info['sex'];
            $user->language = $user_info['language'];
            $user->city = $user_info['city'];
            $user->province = $user_info['province'];
            $user->country = $user_info['country'];
        }
        $user_id = R::store($user);
    } catch (Exception $e) {
        header('Content-type:text/json;charset=utf-8');
        echo json_encode(['result' => 'failed', 'error' => 'db error wechat', 'details' => $e->getMessage()]);
        die;
    }
    R::close();
}
Example #2
0
 public function __construct()
 {
     require_once 'libs/rb.php';
     if (!R::testConnection()) {
         R::setup('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS);
     }
 }
Example #3
0
session_start();
$callback = isset($_REQUEST['bcb']) ? $_REQUEST['bcb'] : '';
$openid = isset($_SESSION['openid']) ? $_SESSION['openid'] : (isset($_REQUEST['openid']) ? $_REQUEST['openid'] : '');
_log(json_encode(['openid' => $openid, 'callback' => $callback]));
// Check
if ($openid == '') {
    header('Location: ' . $csc_url_base . '/static/html/user_not_focus_csc.html?bcb=' . $callback . '&rand=' . rand() . '#mp.weixin.qq.com');
    die;
}
if (!isset($_SESSION['openid'])) {
    $_SESSION['openid'] = $openid;
}
// Query
R::addDatabase('wechat_csc', $GLOBALS['db_wechat_csc_url'], $GLOBALS['db_wechat_csc_user'], $GLOBALS['db_wechat_csc_pass']);
R::selectDatabase('wechat_csc');
if (!R::testConnection()) {
    exit('DB failed' . PHP_EOL);
}
R::freeze(true);
try {
    $user_email = R::getCell('SELECT wu.email' . '  FROM wxcsc_users wu' . ' WHERE wu.openid = :openid' . ' LIMIT 1', [':openid' => $openid]);
} catch (Exception $e) {
    header('Location: ' . $csc_url_base . '/static/html/error_message.html?msg=' . urlencode($e->getMesage()) . '&rand=' . rand() . '#mp.weixin.qq.com');
    die;
}
R::close();
_log(json_encode(['openid' => $openid, 'user_email' => $user_email]));
// Error return
if ($user_email == '') {
    if ($callback == 'user_bind_check_csc') {
        header('Location: ' . $csc_url_base . '/static/html/user_bind_1_csc.html?rand=' . rand() . '#mp.weixin.qq.com');
Example #4
0
function init()
{
    // Setup our RedBean environment.
    R::setup('mysql:host=' . DATABASE_HOST . '; dbname=' . DATABASE_NAME, DATABASE_USERNAME, DATABASE_PASSWORD, REDBEAN_FREEZE_ENABLED);
    // Attempt to connect to the configured Database
    if (!R::testConnection()) {
        throw new Exception('Couldn\'t connect to database. Please check backend configuration.');
    }
    // Enable debug mode
    R::debug(REDBEAN_DEBUG_ENABLED);
    // Use camelCase for bean export
    R::useExportCase('camel');
}
Example #5
0
<?php

/**
 * Pretest
 *
 * These tests will run before the configuration takes place
 * in the unit test suite (mostly error handling tests).
 *
 * @file    RedUNIT/Pretest.php
 * @desc    Test scripts that run before configuration
 * @author  Gabor de Mooij and the RedBeanPHP Community
 * @license New BSD/GPLv2
 *
 * (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community.
 * This source file is subject to the New BSD/GPLv2 License that is bundled
 * with this source code in the file license.txt.
 */
testpack('Running pre-tests. (before config).');
try {
    R::debug(TRUE);
    fail();
} catch (Exception $e) {
    pass();
}
asrt(R::testConnection(), FALSE);
R::addDatabase('broken', 'mysql:host=nowhere', 'defunct', 'void');
R::selectDatabase('broken');
asrt(R::testConnection(), FALSE);
Example #6
0
function get_pe_wechat($staff_email)
{
    // Wechat PE
    //R::addDatabase('wechat_pe', $GLOBALS['db_wechat_pe_url'], $GLOBALS['db_wechat_pe_user'], $GLOBALS['db_wechat_pe_pass']);
    R::selectDatabase('wechat_pe');
    if (!R::testConnection()) {
        exit('DB failed' . PHP_EOL);
    }
    R::freeze(true);
    if (TEST_SEND) {
        $staff_email = DEBUG_EMAIL;
    }
    $email_prefix = explode("@", $staff_email);
    try {
        $openids = R::getAll(' SELECT openid ' . '   FROM wechat_pe.wxpe_users ' . '  WHERE email = :email_1 ' . '     OR email = :email_2 ', [':email_1' => $email_prefix[0], ':email_2' => ucfirst($email_prefix[0])]);
    } catch (Exception $e) {
        die(json_encode(['result' => 'failed', 'error' => 'db error wechat_pe', 'details' => $e->getMessage()]));
    }
    R::close();
    return $openids;
}