<?php header('Content-type: text/json; charset=UTF-8'); set_time_limit(0); ini_set('display_errors', 1); error_reporting(E_ALL); // if ($_SERVER['REQUEST_METHOD'] == 'POST') { require_once "../include/apps.config.php"; require_once "../include/database.php"; require_once "../lib/wechat/wechat.class.php"; require_once "../include/global_func.php"; extract($_REQUEST); if (isset($mod)) { $returnArr = array('code' => 200); foreach ($SYSCONFIG['DB'] as $key => $schema) { if (($mysql = initDataBase($SYSCONFIG['DB'][$key])) == false) { die($mysql->error); } # get app configs $query = "SELECT name, value FROM app_configs\n WHERE name IN( '%s' )"; $_query = sprintf($query, implode('\', \'', $SYSCONFIG['APP_CONFIG'])); $mysql->query($_query); $configs = array(); foreach ($mysql->data as $config) { $configs[$config['name']] = $config['value']; } $config = array('schema' => $schema, 'appid' => $configs['appid'], 'secret' => $configs['app_secret'], 'encrypt_token' => $configs['encrypt_token'], 'encodingAESKey' => $configs['encodingAESKey'], 'app_token' => 'uop05d6RmYZbOvBLs-WomFawCPMv6hEarWLBmbLdppEhN1Ns-N1EES5e7BOB9eznoOKt_xtCdP5NjnsSVqFWDjJg3hq0rE-9wfeiVb4N4NwQFNiAAAYNV', 'app_token_expire' => 1550674698); # init Wechat API $wechat = new WeChat($config); if ($mod == 'userList') { require_once 'userList.php';
log_error('update_userInfo', array('token' => $_SESSION['wechat']['access_token'], 'next_openid' => $next_openid), json_encode($resultSet)); $returnArr['code'] = 500; $returnArr['err'] = $resultSet['errmsg']; die(json_encode($returnArr)); } if ($resultSet['count'] != 0) { $userlist = array_merge($userlist, $resultSet['data']['openid']); } if ($resultSet['next_openid'] != '') { $next_openid = $resultSet['next_openid']; } else { break; } } $userlist = array_chunk($userlist, 500); $db = initDataBase(); # clear table $query = 'TRUNCATE hk_wechat_users '; $stmt = $db->prepare($query); $stmt->execute(); try { foreach ($userlist as $index => $group) { $dbFieldsArr = array(); $dbParamArr = array(); foreach ($group as $key => $user) { $userInfo = curl_subscribe_list('info', $user); if (isset($userInfo['errcode'])) { log_error('update_userInfo', array('token' => $_SESSION['wechat']['access_token'], 'openid' => $user), json_encode($userInfo)); } else { array_push($dbFieldsArr, "( :subscribe_{$key}, :openid_{$key}, :nickname_{$key}, :sex_{$key}, :city_{$key}, :country_{$key}, :province_{$key}, :language_{$key}, :headimgurl_{$key}, :subscribe_time_{$key}, :remark_{$key}, :groupid_{$key} )"); array_push($dbParamArr, array('name' => ":subscribe_{$key}", 'value' => isset($userInfo['subscribe']) ? $userInfo['subscribe'] : NULL));
<?php // ini_set('display_errors', 1); // error_reporting(E_ALL); require_once "../include/apps.config.php"; require_once "../lib/wechat/wechat.class.php"; require_once "../include/database.php"; require_once "../include/global_func.php"; require_once '../include/ArrayToXML.php'; $schema = 'hk_mo'; $responseXML = ''; $time = time(); try { if (($mysql = initDataBase($SYSCONFIG['DB'][$schema])) == false) { throw new Exception($mysql->error); } # get app configs $query = "SELECT name, value FROM app_configs\n WHERE name IN( '%s' )"; $_query = sprintf($query, implode('\', \'', $SYSCONFIG['APP_CONFIG'])); if (!$mysql->query($_query)) { throw new Exception($mysql->error); } else { if ($mysql->num_row == 0) { throw new Exception('App config not found'); } } $configs = array(); foreach ($mysql->data as $config) { $configs[$config['name']] = $config['value']; } $config = array('schema' => $schema, 'appid' => $configs['appid'], 'secret' => $configs['app_secret'], 'encrypt_token' => $configs['encrypt_token'], 'encodingAESKey' => $configs['encodingAESKey'], 'app_token' => null, 'app_token_expire' => null);
$schema = 'cn'; $config = array('schema' => $schema, 'appid' => $SYSCONFIG['WECHAT'][$schema]['appid'], 'secret' => $SYSCONFIG['WECHAT'][$schema]['secret'], 'access_token' => null, 'expires_in' => null); # response $responseXML = ''; $time = time(); $responseArr = array(); $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; //get post data, May be due to the different environments //extract post data if (!empty($postStr)) { libxml_disable_entity_loader(true); $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); try { $postArr = (array) $postObj; $content = isset($postArr['Content']) ? trim($postArr['Content']) : ''; if (($mysql = initDataBase($schema)) == false) { throw new Exception($mysql->error); } $wechat = new WeChat($config); /* --------------------- log request ------------------------- */ if ($postArr['MsgType'] == $wechat::MSGTYPE_EVENT && $postArr['Event'] == $wechat::EVENT_SEND_MASS) { $query = "UPDATE wechat_push_msg\n\t\t\tSET status = :status, totalCount = :totalCount,\n\t\t\tfilterCount = :filterCount, sentCount = :sentCount,\n\t\t\terrorCount = :errorCount, report_date = :report_date\n\t\t\tWHERE msg_id = :msg_id "; $bindArr = array('msg_id' => $postArr['MsgID'], 'status' => $postArr['Status'], 'totalCount' => $postArr['TotalCount'], 'filterCount' => $postArr['FilterCount'], 'sentCount' => $postArr['SentCount'], 'errorCount' => $postArr['ErrorCount'], 'report_date' => date('Y-m-d H:i:s')); if (!$mysql->execute($query, $bindArr)) { throw new Exception($mysql->error); } die(true); } getUserInfo($postArr['FromUserName']); $request_type = $postArr['MsgType']; switch ($postArr['MsgType']) {
<?php require_once dirname(__FILE__) . "/apps.config.php"; require_once dirname(__FILE__) . "/config.inc.php"; require_once dirname(__FILE__) . "/global.inc.php"; require_once dirname(__FILE__) . "/database.php"; require_once dirname(__FILE__) . "/../lib/wechat/wechat.class.php"; require_once dirname(__FILE__) . "/global_func.php"; require_once dirname(__FILE__) . "/global.func.php"; require_once dirname(__FILE__) . "/checksession.php"; if (isset($_SESSION['schema'])) { # init mysql object if (($mysql = initDataBase($SYSCONFIG['DB'][$_SESSION['schema']])) == false) { die($mysql->error); } # get app configs $query = "SELECT name, value FROM app_configs\n WHERE name IN( '%s' )"; $_query = sprintf($query, implode('\', \'', $SYSCONFIG['APP_CONFIG'])); $mysql->query($_query); $configs = array(); foreach ($mysql->data as $config) { $configs[$config['name']] = $config['value']; } # init App Settings $SYSCONFIG['WECHAT'] = array('browserInfo' => $_SERVER['HTTP_USER_AGENT'], 'app_name' => $configs['app_name'], 'thumb' => $configs['app_icon'], 'permission' => 'snsapi_base, snsapi_base, snsapi_userinfo', 'appid' => $configs['appid'], 'secret' => $configs['app_secret']); # init WeChat API $config = array('schema' => $_SESSION['schema'], 'appid' => $SYSCONFIG['WECHAT']['appid'], 'secret' => $SYSCONFIG['WECHAT']['secret'], 'encrypt_token' => $configs['encrypt_token'], 'encodingAESKey' => $configs['encodingAESKey'], 'app_token' => $_SESSION['wechat']['app_token'], 'app_token_expire' => $_SESSION['wechat']['app_token_expire']); $wechat = new WeChat($config); }