添加后台代理代码

This commit is contained in:
2026-03-15 01:27:05 +08:00
parent 11f9ac4dc1
commit ea08c9366a
5254 changed files with 721042 additions and 0 deletions

View File

@@ -0,0 +1,145 @@
<?php
/**
* [Weizan System] Copyright (c) 2014 012WZ.COM
* Weizan is NOT a free software, it under the license terms, visited http://www.012wz.com/ for more details.
*/
function cache_build_template() {
load()->func('file');
rmdirs(IA_ROOT . '/data/tpl', true);
}
function cache_build_setting() {
$sql = 'SELECT * FROM ' . tablename('core_settings');
$setting = pdo_fetchall($sql, array(), 'key');
if (is_array($setting)) {
foreach ($setting as $k => $v) {
$setting[$v['key']] = iunserializer($v['value']);
}
cache_write("setting", $setting);
}
}
// 删除指定公众号的缓存
function cache_build_account_modules() {
$uniacid_arr = pdo_fetchall('SELECT uniacid FROM ' . tablename('uni_account'));
foreach($uniacid_arr as $account){
cache_delete("unimodules:{$account['uniacid']}:1");
cache_delete("unimodules:{$account['uniacid']}:");
cache_delete("unimodulesappbinding:{$account['uniacid']}");
}
}
// 删除指定公众号的应用缓存
function cache_build_account_outapps() {
$uniacid_arr = pdo_fetchall('SELECT uniacid FROM ' . tablename('uni_account'));
foreach($uniacid_arr as $account){
cache_delete("unioutapps:{$account['uniacid']}:1");
cache_delete("unioutapps:{$account['uniacid']}:");
}
}
function cache_build_account() {
global $_W;
$uniacid_arr = pdo_fetchall('SELECT uniacid FROM ' . tablename('uni_account'));
foreach($uniacid_arr as $account){
cache_delete("uniaccount:{$account['uniacid']}");
cache_delete("unisetting:{$account['uniacid']}");
cache_delete("defaultgroupid:{$account['uniacid']}");
}
}
function cache_build_accesstoken() {
global $_W;
$uniacid_arr = pdo_fetchall('SELECT acid FROM ' . tablename('account_wechats'));
foreach($uniacid_arr as $account){
cache_delete("accesstoken:{$account['acid']}");
cache_delete("jsticket:{$account['acid']}");
cache_delete("cardticket:{$account['acid']}");
}
}
function cache_build_users_struct() {
$struct = array();
$result = pdo_fetchall("SHOW COLUMNS FROM " . tablename('mc_members'));
if (!empty($result)) {
foreach ($result as $row) {
$struct[] = $row['Field'];
}
cache_write('usersfields', $struct);
}
return $struct;
}
// 更新系统菜单缓存
function cache_build_frame_menu() {
$data = pdo_fetchall('SELECT * FROM ' . tablename('core_menu') . ' WHERE pid = 0 AND is_display = 1 ORDER BY is_system DESC, displayorder DESC, id ASC');
$frames =array();
if(!empty($data)) {
foreach($data as $da) {
$frames[$da['name']] = array();
$childs = pdo_fetchall('SELECT * FROM ' . tablename('core_menu') . ' WHERE pid = :pid AND is_display = 1 ORDER BY is_system DESC, displayorder DESC, id ASC', array(':pid' => $da['id']));
if(!empty($childs)) {
foreach($childs as $child) {
$temp = array();
$temp['title'] = $child['title'];
$grandchilds = pdo_fetchall('SELECT * FROM ' . tablename('core_menu') . ' WHERE pid = :pid AND is_display = 1 AND type = :type ORDER BY is_system DESC, displayorder DESC, id ASC', array(':pid' => $child['id'], ':type' => 'url'));
if(!empty($grandchilds)) {
foreach($grandchilds as $grandchild) {
$item = array();
$item['id'] = $grandchild['id'];
$item['title'] = $grandchild['title'];
$item['url'] = $grandchild['url'];
$item['permission_name'] = $grandchild['permission_name'];
if(!empty($grandchild['append_title'])) {
$item['append']['title'] = '<i class="'.$grandchild['append_title'].'"></i>';
$item['append']['url'] = $grandchild['append_url'];
}
$temp['items'][] = $item;
}
}
$frames[$da['name']][] = $temp;
}
}
}
}
cache_delete('system_frame');
cache_write('system_frame', $frames);
}
// 更新订阅的消息类型缓存对象
function cache_build_module_subscribe_type() {
global $_W;
// 按订阅的消息类型分组统计哪些模块订阅了当前消息类型
$modules = pdo_fetchall("SELECT name, subscribes FROM ".tablename('modules')." WHERE subscribes <> ''");
$subscribe = array();
if (!empty($modules)) {
foreach ($modules as $module) {
$module['subscribes'] = unserialize($module['subscribes']);
if (!empty($module['subscribes'])) {
foreach ($module['subscribes'] as $event) {
if ($event == 'text') {
continue;
}
$subscribe[$event][] = $module['name'];
}
}
}
}
$module_ban = $_W['setting']['module_receive_ban'];
foreach ($subscribe as $event => $module_group) {
if (!empty($module_group)) {
foreach ($module_group as $index => $module) {
if (!empty($module_ban[$module])) {
unset($subscribe[$event][$index]);
}
}
}
}
// 订阅的消息类型缓存对象
cache_write('module_receive_enable', $subscribe);
}
function cache_build_platform() {
return pdo_query("DELETE FROM ".tablename('core_cache')." WHERE `key` LIKE 'account%' AND `key` <> 'account:ticket';");
}

View File

@@ -0,0 +1,149 @@
<?php
defined('IN_IA') or exit('Access Denied');
define('ALIPAY_GATEWAY', 'https://mapi.alipay.com/gateway.do');
function alipay_build($params, $alipay = array()) {
global $_W;
$tid = $params['uniontid'];
$set = array();
$set['service'] = 'alipay.wap.create.direct.pay.by.user';
$set['partner'] = $alipay['partner'];
$set['_input_charset'] = 'utf-8';
$set['sign_type'] = 'MD5';
$set['notify_url'] = $_W['siteroot'] . 'payment/alipay/notify.php';
$set['return_url'] = $_W['siteroot'] . 'payment/alipay/return.php';
$set['out_trade_no'] = $tid;
$set['subject'] = $params['title'];
$set['total_fee'] = $params['fee'];
$set['seller_id'] = $alipay['account'];
$set['payment_type'] = 1;
$set['body'] = $_W['uniacid'];
$prepares = array();
foreach($set as $key => $value) {
if($key != 'sign' && $key != 'sign_type') {
$prepares[] = "{$key}={$value}";
}
}
sort($prepares);
$string = implode('&', $prepares);
$string .= $alipay['secret'];
$set['sign'] = md5($string);
$response = ihttp_request(ALIPAY_GATEWAY . '?' . http_build_query($set, '', '&'), array(), array('CURLOPT_FOLLOWLOCATION' => 0));
return array('url' => $response['headers']['Location']);
}
function wechat_build($params, $wechat) {
global $_W;
load()->func('communication');
if (empty($wechat['version']) && !empty($wechat['signkey'])) {
$wechat['version'] = 1;
}
$wOpt = array();
if ($wechat['version'] == 1) {// 旧版微信支付接口
$wOpt['appId'] = $wechat['appid']; // 商户APPID
$wOpt['timeStamp'] = TIMESTAMP; // 当前时间戳
$wOpt['nonceStr'] = random(8); // 8位随机字符
$package = array();
$package['bank_type'] = 'WX';
$package['body'] = $params['title'];
$package['attach'] = $_W['uniacid'];
$package['partner'] = $wechat['partner'];
$package['out_trade_no'] = $params['uniontid'];
$package['total_fee'] = $params['fee'] * 100;
$package['fee_type'] = '1';
$package['notify_url'] = $_W['siteroot'] . 'payment/wechat/notify.php';
$package['spbill_create_ip'] = CLIENT_IP;
$package['time_start'] = date('YmdHis', TIMESTAMP);
$package['time_expire'] = date('YmdHis', TIMESTAMP + 600);
$package['input_charset'] = 'UTF-8';
ksort($package);
$string1 = '';
foreach($package as $key => $v) {
if (empty($v)) {
continue;
}
$string1 .= "{$key}={$v}&";
}
$string1 .= "key={$wechat['key']}";
$sign = strtoupper(md5($string1));
$string2 = '';
foreach($package as $key => $v) {
$v = urlencode($v);
$string2 .= "{$key}={$v}&";
}
$string2 .= "sign={$sign}";
$wOpt['package'] = $string2;
$string = '';
$keys = array('appId', 'timeStamp', 'nonceStr', 'package', 'appKey');
sort($keys);
foreach($keys as $key) {
$v = $wOpt[$key];
if($key == 'appKey') {
$v = $wechat['signkey'];
}
$key = strtolower($key);
$string .= "{$key}={$v}&";
}
$string = rtrim($string, '&');
$wOpt['signType'] = 'SHA1';
$wOpt['paySign'] = sha1($string);
return $wOpt;
} else {
$package = array();
$package['appid'] = $wechat['appid']; // 支付商户APPID
$package['mch_id'] = $wechat['mchid']; // 微信支付商户号(MchId)
$package['nonce_str'] = random(8); // 8位随机字符
$package['body'] = $params['title']; // 支付标题
$package['attach'] = $params['attach']; // 支付回调内容
$package['out_trade_no'] = $params['uniontid'];// 订单编号
$package['total_fee'] = $params['fee'] * 100;// 微信支付单位为分
$package['spbill_create_ip'] = CLIENT_IP; // 支付客户端IP
$package['time_start'] = date('YmdHis', TIMESTAMP);// 支付发起时间戳
$package['time_expire'] = date('YmdHis', TIMESTAMP + 600);// 支付有效期
$package['notify_url'] = $_W['siteroot'] . 'callback/';// 支付回调地址
$package['trade_type'] = 'JSAPI';
$package['openid'] = $params['from_user'];
ksort($package, SORT_STRING);
$string1 = '';
foreach($package as $key => $v) {
if (empty($v)) {
continue;
}
$string1 .= "{$key}={$v}&";
}
$string1 .= "key={$wechat['signkey']}";
$package['sign'] = strtoupper(md5($string1));
$dat = array2xml($package);
$response = ihttp_request('https://api.mch.weixin.qq.com/pay/unifiedorder', $dat,false);
if (is_error($response)) {
return $response;
}
$xml = @isimplexml_load_string($response['content'], 'SimpleXMLElement', LIBXML_NOCDATA);
if (strval($xml->return_code) == 'FAIL') {
return error(-1, strval($xml->return_msg));
}
if (strval($xml->result_code) == 'FAIL') {
return error(-1, strval($xml->err_code).': '.strval($xml->err_code_des));
}
$prepayid = $xml->prepay_id;
$wOpt['appId'] = $wechat['appid'];
$wOpt['timeStamp'] = TIMESTAMP;
$wOpt['nonceStr'] = random(8);
$wOpt['package'] = 'prepay_id='.$prepayid;
$wOpt['signType'] = 'MD5';
ksort($wOpt, SORT_STRING);
foreach($wOpt as $key => $v) {
$string .= "{$key}={$v}&";
}
$string .= "key={$wechat['signkey']}";
$wOpt['paySign'] = strtoupper(md5($string));
return $wOpt;
}
}

View File

@@ -0,0 +1,454 @@
<?php
defined('IN_IA') or exit('Access Denied');
use phprs\ezsql\Sql;
define('AUTHTYPE_WECHAT', 0);
define('AUTHTYPE_QQ', 1);
define('AUTHTYPE_JKX', 2);
define('AUTHTYPE_MEMBER', 3);
define('AUTHTYPE_NIUNIUGAME', 4);
// 查询指定的openId和门店Key查询是否存在全局用户信息
function getUserByOpenId($market_key, $UId, $type, $db)
{
$userInfo = array();
switch ($type)
{
case AUTHTYPE_WECHAT: // 微信用户信息查询
$userInfo = Sql::select('a.*')
->from('syweb_users a,syweb_users_weixin b')
->where('b.uid=a.id and b.openid=? and a.market_key=?', $UId, $market_key)
->get($db, null);
break;
case AUTHTYPE_QQ: // QQ用户信息查询
$userInfo = Sql::select('a.*')
->from('syweb_users a,syweb_users_qq b')
->where('b.uid=a.id and b.openid=? and a.market_key=?', $UId, $market_key)
->get($db, null);
break;
case AUTHTYPE_JKX: // 聚开心会员信息查询
$userInfo = Sql::select('a.*')
->from('syweb_users a,syweb_users_jkx b')
->where('b.uid=a.id and b.username=? and a.market_key=?', $UId, $market_key)
->get($db, null);
break;
case AUTHTYPE_MEMBER: // 会员注册登录
$userInfo = Sql::select('a.*')
->from('syweb_users a,syweb_users_normal b')
->where('b.uid=a.id and b.username=? and a.market_key=?', $UId, $market_key)
->get($db, null);
break;
case AUTHTYPE_NIUNIUGAME: // 友乐牛牛注册登录
$userInfo = Sql::select('a.*')
->from('syweb_users a,syweb_users_ylnn b')
->where('b.uid=a.id and b.user_key=? and a.market_key=?', $UId, $market_key)
->get($db, null);
break;
default:
break;
}
if (!empty($userInfo) && count($userInfo) > 0)
return $userInfo[0];
else
return null;
}
function get_wechat_by_user_id($market_key, $open_id, $union_id, $db)
{
if (!empty($union_id))
$userInfo = Sql::select('a.*')
->from('syweb_users a,syweb_users_weixin b')
->where('b.uid = a.id and a.market_key = ? and b.unionid = ?', $market_key, $union_id)
->get($db, null);
else
$userInfo = Sql::select('a.*')
->from('syweb_users a,syweb_users_weixin b')
->where('b.uid = a.id and a.market_key = ? and b.openid = ?', $market_key, $open_id)
->get($db, null);
if (!empty($userInfo) && count($userInfo) > 0)
return $userInfo[0];
else
return null;
}
// 查询指定的openId微信用户是否存在
function getUserById($id, $db)
{
$userInfo = Sql::select('a.*')
->from('syweb_users a')
->where('a.id=?', $id)
->get($db, null);
if (count($userInfo) > 0)
{
return $userInfo[0];
}
return null;
}
// 根据UID查询微信粉丝详细信息
function getWeixinUserByUId($uid, $db)
{
$weixinUserInfo = Sql::select('a.*')
->from('syweb_users_weixin a')
->where('a.uid=?', $uid)
->get($db, null);
if (count($weixinUserInfo) > 0)
{
return $weixinUserInfo[0];
}
return null;
}
// 根据UID查询聚开心粉丝详细信息
function getJkxUserByUId($uid, $db)
{
$weixinUserInfo = Sql::select('a.*')
->from('syweb_users_jkx a')
->where('a.uid=?', $uid)
->get($db, null);
if (count($weixinUserInfo) > 0)
{
return $weixinUserInfo[0];
}
return null;
}
// 根据UID查询友乐牛牛粉丝详细信息
function getYlnnUserByUId($uid, $db)
{
$userInfo = Sql::select('a.*')
->from('syweb_users_ylnn a')
->where('a.uid=?', $uid)
->get($db, null);
if (count($userInfo) > 0)
{
return $userInfo[0];
}
return null;
}
// 根据UID查询微信粉丝详细信息
function getQqUserByUId($uid, $db)
{
$qqUserInfo = Sql::select('syweb_users_qq.*')
->from('syweb_users_qq')
->where('syweb_users_qq.uid=?', $uid)
->get($db, null);
if (!empty($qqUserInfo) > 0 && count($qqUserInfo) > 0)
{
return $qqUserInfo[0];
}
return null;
}
// 增加/更新用户信息
function updateUserInfo($scode, $auth_type, $open_id, $union_id, $market_key, $db, $pdo)
{
// 首先验证指定的账号在全局用户信息中是否存在对应的记录
if (!empty($union_id))
$user_exist = Sql::select('a.id')
->from('syweb_users a')
->where('a.unionid = ? and a.market_key = ? and a.auth_type = ?', $union_id, $market_key, $auth_type)
->get($db, null);
else
$user_exist = Sql::select('a.id')
->from('syweb_users a')
->where('a.openid = ? and a.market_key = ? and a.auth_type = ?', $open_id, $market_key, $auth_type)
->get($db, null);
// 循环创建用户全局唯一ID(临时绑定20分钟有效)
$sid = random(32, false);
while (true)
{
$sid_exist = Sql::select('a.sid')
->from('syweb_users a')
->where('a.sid=?', $sid)
->get($db, null);
if ($sid_exist)
$sid = random(32, false);
else
break;
}
// 循环创建access_id(长时间绑定30天有效)
$access_id = "gm_" . random(13, false);
while (true)
{
$access_id_exist = Sql::select('a.sid')
->from('syweb_users a')
->where('a.access_id=?', $access_id)
->get($db, null);
if ($access_id_exist)
$access_id = "gm_" . random(13, false);
else
break;
}
$access_key = random(36, false);
while (true)
{
$access_key_exist = Sql::select('a.sid')
->from('syweb_users a')
->where('a.access_key=?', $access_key)
->get($db, null);
if ($access_key_exist)
$access_key = random(36, false);
else
break;
}
//SID过期时间(默认2天内有效)
$sid_expire_time = time() + (2 * 24 * 60 * 60);
//AccessToken过期时间(默认两个月内有效)
$access_expire_time = time() + (60 * 24 * 60 * 60);
// 假如当前username不存在则新增一条对应的全局用户记录
if (empty($user_exist) || count($user_exist) <= 0)
{
$data = array(
'main_account_id' => '', /// 默认没有绑定主账户
'sid' => $sid,
'scode' => $scode,
'sid_expire_time' => $sid_expire_time,
'access_id' => $access_id,
'access_key' => $access_key,
'access_expire_time' => $access_expire_time,
'market_key' => $market_key,
'auth_type' => $auth_type,
'openid' => $open_id,
'unionid' => $union_id,
'market_jifen' => 0,
'create_time' => TIMESTAMP,
);
$id = Sql::insertInto('syweb_users')->values($data)->exec($pdo)->lastInsertId();
if (!$id)
return -1;
else
return $id;
}
else
{
// 假如当前username存在则修改一条对应的全局用户记录
$data = array(
'sid' => $sid,
'scode' => $scode,
'sid_expire_time' => $sid_expire_time,
'access_id' => $access_id,
'access_key' => $access_key,
'access_expire_time' => $access_expire_time,
'auth_type' => $auth_type,
);
Sql::update('syweb_users')->setArgs($data)->where('id = ?', $user_exist[0]['id'])->exec($pdo);
return $user_exist[0]['id'];
}
}
// 更新微信用户信息
function updateWeixinUserInfo($weixinUserInfo, $db, $pdo)
{
$uid_exist = Sql::select('a.id')
->from('syweb_users_weixin a')
->where('a.uid=? and a.openid=?', $weixinUserInfo["uid"], $weixinUserInfo["openid"])
->get($db, null);
if (empty($uid_exist) || count($uid_exist) <= 0)
{
// 假如当前uid不存在
$insertData = array();
$insertData['uid'] = $weixinUserInfo["uid"];
$insertData['nickname'] = $weixinUserInfo["nickname"];
$insertData['sex'] = $weixinUserInfo["sex"];
$insertData['province'] = $weixinUserInfo["province"];
$insertData['city'] = $weixinUserInfo["city"];
$insertData['country'] = $weixinUserInfo["country"];
$insertData['headimgurl'] = $weixinUserInfo["headimgurl"];
$insertData['privilege'] = $weixinUserInfo["privilege"];
$insertData['subscribe'] = $weixinUserInfo["subscribe"];
$insertData['subscribe_time'] = $weixinUserInfo["subscribe_time"];
$insertData['openid'] = $weixinUserInfo["openid"];
$insertData['unionid'] = $weixinUserInfo["unionid"];
$id = Sql::insertInto('syweb_users_weixin')->values($insertData)->exec($pdo)->lastInsertId();
if (!$id)
{
return -1;
}
return $id;
}
else
{
$updateData = array();
$updateData['nickname'] = $weixinUserInfo["nickname"];
$updateData['sex'] = $weixinUserInfo["sex"];
$updateData['province'] = $weixinUserInfo["province"];
$updateData['city'] = $weixinUserInfo["city"];
$updateData['country'] = $weixinUserInfo["country"];
$updateData['headimgurl'] = $weixinUserInfo["headimgurl"];
$updateData['privilege'] = $weixinUserInfo["privilege"];
$updateData['subscribe'] = $weixinUserInfo["subscribe"];
$updateData['subscribe_time'] = $weixinUserInfo["subscribe_time"];
$updateData['unionid'] = $weixinUserInfo["unionid"];
Sql::update('syweb_users_weixin')->setArgs($updateData)->where('uid=? and openid=?', $weixinUserInfo["uid"], $weixinUserInfo["openid"])->exec($pdo);
return $uid_exist["id"];
}
}
// 更新QQ用户信息
function updateQqUserInfo($qqUserInfo, $db, $pdo)
{
$uid_exist = Sql::select('syweb_users_qq.id')
->from('syweb_users_qq')
->where('syweb_users_qq.uid=? and syweb_users_qq.openid=?', $qqUserInfo["uid"], $qqUserInfo["openid"])
->get($db, null);
if (empty($uid_exist))
{
// 假如当前uid不存在
$insertData = array();
$insertData['uid'] = $qqUserInfo["uid"];
$insertData['gender'] = $qqUserInfo["gender"];
$insertData['nickname'] = $qqUserInfo["nickname"];
$insertData['province'] = $qqUserInfo["province"];
$insertData['city'] = $qqUserInfo["city"];
$insertData['year'] = $qqUserInfo["year"];
$insertData['figureurl_qq_1'] = $qqUserInfo["figureurl_qq_1"];
$insertData['figureurl_qq_2'] = $qqUserInfo["figureurl_qq_2"];
$insertData['figureurl'] = $qqUserInfo["figureurl"];
$insertData['figureurl_1'] = $qqUserInfo["figureurl_1"];
$insertData['figureurl_2'] = $qqUserInfo["figureurl_2"];
$insertData['vip'] = $qqUserInfo["vip"];
$insertData['level'] = $qqUserInfo["level"];
$insertData['is_yellow_year_vip'] = $qqUserInfo["is_yellow_year_vip"];
$insertData['yellow_vip_level'] = $qqUserInfo["yellow_vip_level"];
$insertData['openid'] = $qqUserInfo["openid"];
$id = Sql::insertInto('syweb_users_qq')->values($insertData)->exec($pdo)->lastInsertId();
if (!$id)
{
return -1;
}
return $id;
}
else
{
$updateData = array();
$updateData['gender'] = $qqUserInfo["gender"];
$updateData['nickname'] = $qqUserInfo["nickname"];
$updateData['province'] = $qqUserInfo["province"];
$updateData['city'] = $qqUserInfo["city"];
$updateData['year'] = $qqUserInfo["year"];
$updateData['figureurl_qq_1'] = $qqUserInfo["figureurl_qq_1"];
$updateData['figureurl_qq_2'] = $qqUserInfo["figureurl_qq_2"];
$updateData['figureurl'] = $qqUserInfo["figureurl"];
$updateData['figureurl_1'] = $qqUserInfo["figureurl_1"];
$updateData['figureurl_2'] = $qqUserInfo["figureurl_2"];
$updateData['vip'] = $qqUserInfo["vip"];
$updateData['level'] = $qqUserInfo["level"];
$updateData['is_yellow_year_vip'] = $qqUserInfo["is_yellow_year_vip"];
$updateData['yellow_vip_level'] = $qqUserInfo["yellow_vip_level"];
Sql::update('syweb_users_qq')->setArgs($updateData)->where('uid=? and openid=?', $qqUserInfo["uid"], $qqUserInfo["openid"])->exec($pdo);
return $uid_exist["id"];
}
}
// 更新聚开心用户信息
function updateJkxUserInfo($userInfo, $db, $pdo)
{
$uid_exist = Sql::select('a.id')
->from('syweb_users_jkx a')
->where('a.uid=? and a.username=?', $userInfo["uid"], $userInfo["username"])
->get($db, null);
if (empty($uid_exist) || count($uid_exist) <= 0)
{
// 假如当前uid不存在
$insertData = array();
$insertData['uid'] = $userInfo["uid"];
$insertData['level'] = $userInfo["level"];
$insertData['enum'] = $userInfo["enum"];
$insertData['realname'] = $userInfo["realname"];
$insertData['tel'] = $userInfo["tel"];
$insertData['headimgurl'] = $userInfo["headimgurl"];
$insertData['username'] = $userInfo["username"];
$insertData['integral'] = $userInfo["integral"];
$id = Sql::insertInto('syweb_users_jkx')->values($insertData)->exec($pdo)->lastInsertId();
if (!$id)
{
return -1;
}
return $id;
}
else
{
$updateData = array();
$updateData['level'] = $userInfo["level"];
$updateData['enum'] = $userInfo["enum"];
$updateData['realname'] = $userInfo["realname"];
$updateData['tel'] = $userInfo["tel"];
$updateData['headimgurl'] = $userInfo["headimgurl"];
$updateData['integral'] = $userInfo["integral"];
Sql::update('syweb_users_jkx')->setArgs($updateData)->where('uid=? and username=?', $userInfo["uid"], $userInfo["username"])->exec($pdo);
return $uid_exist["id"];
}
}
// 更新友乐牛牛用户信息
function updateYlnnUserInfo($userInfo, $db, $pdo)
{
$uid_exist = Sql::select('a.id')
->from('syweb_users_ylnn a')
->where('a.uid=? and a.user_key=?', $userInfo["uid"], $userInfo["user_key"])
->get($db, null);
if (empty($uid_exist) || count($uid_exist) <= 0)
{
// 假如当前uid不存在
$insertData = array();
$insertData['uid'] = $userInfo["uid"];
$insertData['user_key'] = $userInfo["user_key"];
$insertData['agent_key'] = $userInfo["agent_key"];
$insertData['game_key'] = $userInfo["game_key"];
$insertData['player_key'] = $userInfo["player_key"];
$insertData['headimgurl'] = $userInfo["headimgurl"];
$insertData['nickname'] = $userInfo["nickname"];
$id = Sql::insertInto('syweb_users_ylnn')->values($insertData)->exec($pdo)->lastInsertId();
if (!$id)
{
return -1;
}
return $id;
}
else
{
$updateData = array();
$updateData['agent_key'] = $userInfo["agent_key"];
$updateData['game_key'] = $userInfo["game_key"];
$updateData['player_key'] = $userInfo["player_key"];
$updateData['headimgurl'] = $userInfo["headimgurl"];
$updateData['nickname'] = $userInfo["nickname"];
Sql::update('syweb_users_ylnn')->setArgs($updateData)->where('uid=? and user_key=?', $userInfo["uid"], $userInfo["user_key"])->exec($pdo);
return $uid_exist["id"];
}
}

View File

@@ -0,0 +1,439 @@
<?php
defined('IN_IA') or exit('Access Denied');
use phprs\ezsql\Sql;
define('AUTHTYPE_WECHAT', 0);
define('AUTHTYPE_QQ', 1);
define('AUTHTYPE_JKX', 2);
define('AUTHTYPE_MEMBER', 3);
define('AUTHTYPE_NIUNIUGAME', 4);
// 查询指定的openId和门店Key查询是否存在全局用户信息
function getUserByOpenId($market_key, $UId, $type, $db)
{
$userInfo = array();
switch ($type)
{
case AUTHTYPE_WECHAT: // 微信用户信息查询
$userInfo = Sql::select('a.*')
->from('syweb_users a,syweb_users_weixin b')
->where('b.uid=a.id and b.openid=? and a.market_key=?', $UId, $market_key)
->get($db, null);
break;
case AUTHTYPE_QQ: // QQ用户信息查询
$userInfo = Sql::select('a.*')
->from('syweb_users a,syweb_users_qq b')
->where('b.uid=a.id and b.openid=? and a.market_key=?', $UId, $market_key)
->get($db, null);
break;
case AUTHTYPE_JKX: // 聚开心会员信息查询
$userInfo = Sql::select('a.*')
->from('syweb_users a,syweb_users_jkx b')
->where('b.uid=a.id and b.username=? and a.market_key=?', $UId, $market_key)
->get($db, null);
break;
case AUTHTYPE_MEMBER: // 会员注册登录
$userInfo = Sql::select('a.*')
->from('syweb_users a,syweb_users_normal b')
->where('b.uid=a.id and b.username=? and a.market_key=?', $UId, $market_key)
->get($db, null);
break;
case AUTHTYPE_NIUNIUGAME: // 友乐牛牛注册登录
$userInfo = Sql::select('a.*')
->from('syweb_users a,syweb_users_ylnn b')
->where('b.uid=a.id and b.user_key=? and a.market_key=?', $UId, $market_key)
->get($db, null);
break;
default:
break;
}
if (!empty($userInfo) && count($userInfo) > 0)
{
return $userInfo[0];
}
return null;
}
// 查询指定的openId微信用户是否存在
function getUserById($id, $db)
{
$userInfo = Sql::select('a.*')
->from('syweb_users a')
->where('a.id=?', $id)
->get($db, null);
if (count($userInfo) > 0)
{
return $userInfo[0];
}
return null;
}
// 根据UID查询微信粉丝详细信息
function getWeixinUserByUId($uid, $db)
{
$weixinUserInfo = Sql::select('a.*')
->from('syweb_users_weixin a')
->where('a.uid=?', $uid)
->get($db, null);
if (count($weixinUserInfo) > 0)
{
return $weixinUserInfo[0];
}
return null;
}
// 根据UID查询聚开心粉丝详细信息
function getJkxUserByUId($uid, $db)
{
$weixinUserInfo = Sql::select('a.*')
->from('syweb_users_jkx a')
->where('a.uid=?', $uid)
->get($db, null);
if (count($weixinUserInfo) > 0)
{
return $weixinUserInfo[0];
}
return null;
}
// 根据UID查询友乐牛牛粉丝详细信息
function getYlnnUserByUId($uid, $db)
{
$userInfo = Sql::select('a.*')
->from('syweb_users_ylnn a')
->where('a.uid=?', $uid)
->get($db, null);
if (count($userInfo) > 0)
{
return $userInfo[0];
}
return null;
}
// 根据UID查询微信粉丝详细信息
function getQqUserByUId($uid, $db)
{
$qqUserInfo = Sql::select('syweb_users_qq.*')
->from('syweb_users_qq')
->where('syweb_users_qq.uid=?', $uid)
->get($db, null);
if (!empty($qqUserInfo) > 0 && count($qqUserInfo) > 0)
{
return $qqUserInfo[0];
}
return null;
}
// 增加/更新用户信息
function updateUserInfo($scode, $auth_type, $username, $market_key, $db, $pdo)
{
// 首先验证指定的账号在全局用户信息中是否存在对应的记录
$user_exist = Sql::select('a.id')
->from('syweb_users a')
->where('a.openid=? and a.market_key=? and a.auth_type=?', $username, $market_key, $auth_type)
->get($db, null);
// 循环创建用户全局唯一ID(临时绑定20分钟有效)
$sid = random(32, false);
while (true)
{
$sid_exist = Sql::select('a.sid')
->from('syweb_users a')
->where('a.sid=?', $sid)
->get($db, null);
if ($sid_exist)
{
$sid = random(32, false);
}
else
{
break;
}
}
// 循环创建access_id(长时间绑定30天有效)
$access_id = "gm_" . random(13, false);
while (true)
{
$access_id_exist = Sql::select('a.sid')
->from('syweb_users a')
->where('a.access_id=?', $access_id)
->get($db, null);
if ($access_id_exist)
{
$access_id_exist = "gm_" . random(13, false);
}
else
{
break;
}
}
$access_key = random(36, false);
while (true)
{
$access_key_exist = Sql::select('a.sid')
->from('syweb_users a')
->where('a.access_key=?', $access_key)
->get($db, null);
if ($access_key_exist)
{
$access_key = random(36, false);
}
else
{
break;
}
}
//SID过期时间(默认2天内有效)
$sid_expire_time = time() + (2 * 24 * 60 * 60);
//AccessToken过期时间(默认两个月内有效)
$access_expire_time = time() + (60 * 24 * 60 * 60);
// 假如当前username不存在则新增一条对应的全局用户记录
if (empty($user_exist) || count($user_exist) <= 0)
{
$insertData = array();
$insertData['main_account_id'] = ""; // 默认没有绑定主账户
$insertData['sid'] = $sid;
$insertData['scode'] = $scode;
$insertData['sid_expire_time'] = $sid_expire_time;
$insertData['access_id'] = $access_id;
$insertData['access_key'] = $access_key;
$insertData['access_expire_time'] = $access_expire_time;
$insertData['market_key'] = $market_key;
$insertData['auth_type'] = $auth_type;
$insertData['openid'] = $username;
$insertData['market_jifen'] = 0;
$insertData['create_time'] = TIMESTAMP;
$id = Sql::insertInto('syweb_users')->values($insertData)->exec($pdo)->lastInsertId();
if (!$id)
{
return -1;
}
return $id;
}
else
{
// 假如当前username存在则修改一条对应的全局用户记录
$updateData = array();
$updateData['sid'] = $sid;
$updateData['scode'] = $scode;
$updateData['sid_expire_time'] = $sid_expire_time;
$updateData['access_id'] = $access_id;
$updateData['access_key'] = $access_key;
$updateData['access_expire_time'] = $access_expire_time;
$updateData['auth_type'] = $auth_type;
Sql::update('syweb_users')->setArgs($updateData)->where('openid=? and market_key=? and auth_type=?', $username, $market_key, $auth_type)->exec($pdo);
return $user_exist[0]["id"];
}
}
// 更新微信用户信息
function updateWeixinUserInfo($weixinUserInfo, $db, $pdo)
{
$uid_exist = Sql::select('a.id')
->from('syweb_users_weixin a')
->where('a.uid=? and a.openid=?', $weixinUserInfo["uid"], $weixinUserInfo["openid"])
->get($db, null);
if (empty($uid_exist) || count($uid_exist) <= 0)
{
// 假如当前uid不存在
$insertData = array();
$insertData['uid'] = $weixinUserInfo["uid"];
$insertData['nickname'] = $weixinUserInfo["nickname"];
$insertData['sex'] = $weixinUserInfo["sex"];
$insertData['province'] = $weixinUserInfo["province"];
$insertData['city'] = $weixinUserInfo["city"];
$insertData['country'] = $weixinUserInfo["country"];
$insertData['headimgurl'] = $weixinUserInfo["headimgurl"];
$insertData['privilege'] = $weixinUserInfo["privilege"];
$insertData['subscribe'] = $weixinUserInfo["subscribe"];
$insertData['subscribe_time'] = $weixinUserInfo["subscribe_time"];
$insertData['openid'] = $weixinUserInfo["openid"];
$insertData['unionid'] = $weixinUserInfo["unionid"];
$id = Sql::insertInto('syweb_users_weixin')->values($insertData)->exec($pdo)->lastInsertId();
if (!$id)
{
return -1;
}
return $id;
}
else
{
$updateData = array();
$updateData['nickname'] = $weixinUserInfo["nickname"];
$updateData['sex'] = $weixinUserInfo["sex"];
$updateData['province'] = $weixinUserInfo["province"];
$updateData['city'] = $weixinUserInfo["city"];
$updateData['country'] = $weixinUserInfo["country"];
$updateData['headimgurl'] = $weixinUserInfo["headimgurl"];
$updateData['privilege'] = $weixinUserInfo["privilege"];
$updateData['subscribe'] = $weixinUserInfo["subscribe"];
$updateData['subscribe_time'] = $weixinUserInfo["subscribe_time"];
$updateData['unionid'] = $weixinUserInfo["unionid"];
Sql::update('syweb_users_weixin')->setArgs($updateData)->where('uid=? and openid=?', $weixinUserInfo["uid"], $weixinUserInfo["openid"])->exec($pdo);
return $uid_exist["id"];
}
}
// 更新QQ用户信息
function updateQqUserInfo($qqUserInfo, $db, $pdo)
{
$uid_exist = Sql::select('syweb_users_qq.id')
->from('syweb_users_qq')
->where('syweb_users_qq.uid=? and syweb_users_qq.openid=?', $qqUserInfo["uid"], $qqUserInfo["openid"])
->get($db, null);
if (empty($uid_exist))
{
// 假如当前uid不存在
$insertData = array();
$insertData['uid'] = $qqUserInfo["uid"];
$insertData['gender'] = $qqUserInfo["gender"];
$insertData['nickname'] = $qqUserInfo["nickname"];
$insertData['province'] = $qqUserInfo["province"];
$insertData['city'] = $qqUserInfo["city"];
$insertData['year'] = $qqUserInfo["year"];
$insertData['figureurl_qq_1'] = $qqUserInfo["figureurl_qq_1"];
$insertData['figureurl_qq_2'] = $qqUserInfo["figureurl_qq_2"];
$insertData['figureurl'] = $qqUserInfo["figureurl"];
$insertData['figureurl_1'] = $qqUserInfo["figureurl_1"];
$insertData['figureurl_2'] = $qqUserInfo["figureurl_2"];
$insertData['vip'] = $qqUserInfo["vip"];
$insertData['level'] = $qqUserInfo["level"];
$insertData['is_yellow_year_vip'] = $qqUserInfo["is_yellow_year_vip"];
$insertData['yellow_vip_level'] = $qqUserInfo["yellow_vip_level"];
$insertData['openid'] = $qqUserInfo["openid"];
$id = Sql::insertInto('syweb_users_qq')->values($insertData)->exec($pdo)->lastInsertId();
if (!$id)
{
return -1;
}
return $id;
}
else
{
$updateData = array();
$updateData['gender'] = $qqUserInfo["gender"];
$updateData['nickname'] = $qqUserInfo["nickname"];
$updateData['province'] = $qqUserInfo["province"];
$updateData['city'] = $qqUserInfo["city"];
$updateData['year'] = $qqUserInfo["year"];
$updateData['figureurl_qq_1'] = $qqUserInfo["figureurl_qq_1"];
$updateData['figureurl_qq_2'] = $qqUserInfo["figureurl_qq_2"];
$updateData['figureurl'] = $qqUserInfo["figureurl"];
$updateData['figureurl_1'] = $qqUserInfo["figureurl_1"];
$updateData['figureurl_2'] = $qqUserInfo["figureurl_2"];
$updateData['vip'] = $qqUserInfo["vip"];
$updateData['level'] = $qqUserInfo["level"];
$updateData['is_yellow_year_vip'] = $qqUserInfo["is_yellow_year_vip"];
$updateData['yellow_vip_level'] = $qqUserInfo["yellow_vip_level"];
Sql::update('syweb_users_qq')->setArgs($updateData)->where('uid=? and openid=?', $qqUserInfo["uid"], $qqUserInfo["openid"])->exec($pdo);
return $uid_exist["id"];
}
}
// 更新聚开心用户信息
function updateJkxUserInfo($userInfo, $db, $pdo)
{
$uid_exist = Sql::select('a.id')
->from('syweb_users_jkx a')
->where('a.uid=? and a.username=?', $userInfo["uid"], $userInfo["username"])
->get($db, null);
if (empty($uid_exist) || count($uid_exist) <= 0)
{
// 假如当前uid不存在
$insertData = array();
$insertData['uid'] = $userInfo["uid"];
$insertData['level'] = $userInfo["level"];
$insertData['enum'] = $userInfo["enum"];
$insertData['realname'] = $userInfo["realname"];
$insertData['tel'] = $userInfo["tel"];
$insertData['headimgurl'] = $userInfo["headimgurl"];
$insertData['username'] = $userInfo["username"];
$insertData['integral'] = $userInfo["integral"];
$id = Sql::insertInto('syweb_users_jkx')->values($insertData)->exec($pdo)->lastInsertId();
if (!$id)
{
return -1;
}
return $id;
}
else
{
$updateData = array();
$updateData['level'] = $userInfo["level"];
$updateData['enum'] = $userInfo["enum"];
$updateData['realname'] = $userInfo["realname"];
$updateData['tel'] = $userInfo["tel"];
$updateData['headimgurl'] = $userInfo["headimgurl"];
$updateData['integral'] = $userInfo["integral"];
Sql::update('syweb_users_jkx')->setArgs($updateData)->where('uid=? and username=?', $userInfo["uid"], $userInfo["username"])->exec($pdo);
return $uid_exist["id"];
}
}
// 更新友乐牛牛用户信息
function updateYlnnUserInfo($userInfo, $db, $pdo)
{
$uid_exist = Sql::select('a.id')
->from('syweb_users_ylnn a')
->where('a.uid=? and a.user_key=?', $userInfo["uid"], $userInfo["user_key"])
->get($db, null);
if (empty($uid_exist) || count($uid_exist) <= 0)
{
// 假如当前uid不存在
$insertData = array();
$insertData['uid'] = $userInfo["uid"];
$insertData['user_key'] = $userInfo["user_key"];
$insertData['agent_key'] = $userInfo["agent_key"];
$insertData['game_key'] = $userInfo["game_key"];
$insertData['player_key'] = $userInfo["player_key"];
$insertData['headimgurl'] = $userInfo["headimgurl"];
$insertData['nickname'] = $userInfo["nickname"];
$id = Sql::insertInto('syweb_users_ylnn')->values($insertData)->exec($pdo)->lastInsertId();
if (!$id)
{
return -1;
}
return $id;
}
else
{
$updateData = array();
$updateData['agent_key'] = $userInfo["agent_key"];
$updateData['game_key'] = $userInfo["game_key"];
$updateData['player_key'] = $userInfo["player_key"];
$updateData['headimgurl'] = $userInfo["headimgurl"];
$updateData['nickname'] = $userInfo["nickname"];
Sql::update('syweb_users_ylnn')->setArgs($updateData)->where('uid=? and user_key=?', $userInfo["uid"], $userInfo["user_key"])->exec($pdo);
return $uid_exist["id"];
}
}