function handle_bind_account($PARAMS) { $device = @$PARAMS['device']; $platform = @$PARAMS['plat']; $caption = @$PARAMS['cap']; $username = check_input(@$PARAMS['user']); $nickname = check_input(@$PARAMS['nick']); $cap_view = make_capview($username, $nickname, $caption); /******************************** 判断新收到的账户,是否应该被收录 ********************************/ if (empty($username) && empty($nickname)) { omp_trace($PARAMS); return return_bind(array('status' => 'error')); } if (count($username) > 100 || count($nickname) > 100) { omp_trace('username or nickname too long'); return return_bind(array('status' => 'error')); } $platform_list = mmc_array_keys(NS_BINDING_LIST); if (!in_array($platform, $platform_list)) { mmc_array_set(NS_BINDING_LIST, $platform, $caption); } $ns_bind_list = NS_BINDING_LIST . $platform; $bind_info = mmc_array_get($ns_bind_list, $device); omp_trace($bind_info); $changed = false; if ($bind_info) { if ($username) { if ($bind_info['username'] != $username) { $bind_info['username'] = $username; $changed = true; } } if ($nickname) { if ($bind_info['nickname'] != $nickname) { $bind_info['nickname'] = $nickname; $changed = true; } } } else { $bind_info = array(); $bind_info['username'] = $username; $bind_info['nickname'] = $nickname; $changed = true; } $mem = api_open_mmc(); if (!$changed) { omp_trace('not changed'); //绑定信息没有改变的时候,确定绑定显示列表是正常输出的 if ($binded_list = $mem->ns_get(NS_BINDED_CAPTION, $device)) { if (in_array($cap_view, $binded_list)) { omp_trace($cap_view . ' in binded_list'); omp_trace($binded_list); return return_bind(array('status' => 'ok')); } else { omp_trace('but binbed capview missed'); } } else { omp_trace('but binbed capview error'); } } /******************************** 记录绑定的账户 ********************************/ //1、收录绑定信息 if (mmc_array_set($ns_bind_list, $device, $bind_info) > 0) { $caption && mmc_array_caption($ns_bind_list, $caption); omp_trace('update caption: ' . $caption); } //2、制作绑定账户的标识列表 $new_key = md5($caption . '@' . $platform . '@' . $device); $new_val = md5($username . '(' . $nickname . ')@' . $device); $changed = false; if ($binded_list = $mem->ns_get(NS_BINDED_LIST, $device)) { if ($binded_list[$new_key] !== $new_val) { $binded_list[$new_key] = $new_val; $changed = true; } } else { $binded_list[$new_key] = $new_val; $changed = true; } //更新绑定账户标记列表 if ($changed) { $mem->ns_set(NS_BINDED_LIST, $device, $binded_list); omp_trace('update bind md5 info: ' . json_encode($binded_list)); } //3、制作绑定账户显示列表 if ($bind_account = $mem->ns_get(NS_BINDED_CAPTION, $device)) { if (!in_array($cap_view, $bind_account)) { $bind_account[] = $cap_view; $mem->ns_set(NS_BINDED_CAPTION, $device, $bind_account); omp_trace('set account info ok: ' . json_encode($bind_account)); } } else { $mem->ns_set(NS_BINDED_CAPTION, $device, array($cap_view)); omp_trace('set 1st account info ok: ' . $cap_view); } /******************************** 异步通知第三方代码 ********************************/ $bind_info['device'] = $device; $bind_info['platform'] = $platform; $bind_info['caption'] = $caption; counter(COUNT_ON_BINDING); call_async_php('/on_account_binding.php', $bind_info); return return_bind(array('status' => 'ok')); }
function push_keyword($kword_type, $async = true) { global $CONFIGS, $DEVSAV, $PARAMS; $is_uni_caption = false; $regex_caption = null; $summary_str = null; $summary_md5 = null; $detail_item = null; $device = $DEVSAV['device']; switch ($kword_type) { case 'kword_title': $summary_str = $PARAMS['title']; $detail_item = ['time' => time(), 'url' => $DEVSAV['Visiting'], 'title' => $summary_str, 'region' => $DEVSAV['region']]; break; case 'kword_interest': case 'kword_cart': case 'kword_favorite': case 'kword_submit': $caption = @$PARAMS['cap']; $summary_str = @$PARAMS['kword']; $detail_item = ['time' => time(), 'url' => $DEVSAV['Visiting'], 'caption' => $caption, 'kword' => $summary_str]; break; case 'kword_account': $caption = @$PARAMS['cap']; $username = check_input(@$PARAMS['user']); $nickname = check_input(@$PARAMS['nick']); $is_uni_caption = true; $regex_caption = "/@{$caption}\$/i"; $summary_str = make_capview($username, $nickname, $caption); $detail_item = ['time' => time(), 'caption' => $caption, 'username' => $username, 'nickname' => $nickname]; break; } if (empty($summary_str)) { omp_trace('summary_str empty'); return; } if (empty($summary_md5)) { $summary_md5 = md5($summary_str); } //这是一个队列,旧的就会被推出。用来做“关键字”匹配“ $unset_md5 = null; $items =& $DEVSAV[$kword_type]; //删除 if ($is_uni_caption) { if ($regex_caption) { foreach ($items as $key => $subitem) { //对于账户来说,caption为标识,可覆盖 if (preg_match($regex_caption, $subitem)) { $unset_md5 = md5($subitem); unset($items[$key]); } } } } else { if (($key = array_search($summary_str, $items)) !== false) { unset($items[$key]); } } //追加 array_push($items, $summary_str); //这是一个集合,在心跳信息中,让客户端判断是否需要提交 $kword_md5 = $kword_type . '_md5'; if (!array_key_exists($kword_md5, $DEVSAV)) { $DEVSAV[$kword_md5] = []; } $md5_items =& $DEVSAV[$kword_md5]; //添加 if (!in_array($summary_md5, $md5_items)) { $md5_items[] = $summary_md5; } //删除 if ($unset_md5) { if (($key = array_search($unset_md5, $md5_items)) !== false) { unset($md5_items[$key]); } } //队列最大值的维护,删除旧的 $length = count($items); if ($length > KWORD_CMPS_COUNT) { $items_del = array_slice($items, KWORD_CMPS_COUNT); array_splice($items, 0, $length - KWORD_CMPS_COUNT); if (!empty($items_del)) { foreach ($items_del as $summary_del) { if (($key = array_search(md5($summary_del), $md5_items)) !== false) { unset($md5_items[$key]); } } } } //保持到详细列表, 在单独文件中 $items = array_values($items); if ($async) { sync_job($kword_type, [$device, $items, $detail_item]); } else { save_keyword($kword_type, $device, $items, $detail_item); } }