1.购买服务器阿里云:服务器购买地址https://t.aliyun.com/U/Bg6shY若失效,可用地址
阿里云:
服务器购买地址
https://t.aliyun.com/U/Bg6shY
若失效,可用地址
https://www.aliyun.com/daily-act/ecs/activity_selection?source=5176.29345612&userCode=49hts92d
腾讯云:
https://curl.qcloud.com/wJpWmSfU
若失效,可用地址
https://cloud.tencent.com/act/cps/redirect?redirect=2446&cps_key=ad201ee2ef3b771157f72ee5464b1fea&from=console
华为云
https://activity.huaweicloud.com/cps.html?fromacct=64b5cf7cc11b4840bb4ed2ea0b2f4468&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905
2.部署教程
3.代码如下
(function() {
'use strict';
// 检查当前页面是否是授权回调页面
function checkForAuthCode() {
const url = window.location.href;
const urlParams = new URLSearchParams(window.location.search);
// 检查是否在回调页面且包含授权码
if (url.includes('oauth20_desktop.srf') && urlParams.has('code')) {
const code = urlParams.get('code');
console.log('🎯 检测到授权码:', code.substring(0, 20) + '...');
// 显示处理状态
showProcessingUI();
// 获取刷新令牌
getRefreshTokenFromCode(code);
}
}
// 显示处理界面
function showProcessingUI() {
// 创建覆盖层
const overlay = document.createElement('div');
overlay.id = 'token-overlay';
overlay.style.cssText = `
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
z-index: 99999;
display: flex;
justify-content: center;
align-items: center;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
`;
// 创建内容容器
const container = document.createElement('div');
container.style.cssText = `
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
max-width: 600px;
width: 90%;
text-align: center;
`;
container.innerHTML = `
<h2 style="color: #0078d4; margin-bottom: 20px;">🔧 Bing Rewards 令牌获取工具</h2>
<div id="status-content">
<div style="margin: 20px 0;">
<div class="spinner" style="
border: 4px solid #f3f3f3;
border-top: 4px solid #0078d4;
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
margin: 0 auto 15px;
"></div>
<p style="color: #666; font-size: 16px;">🔄 正在获取刷新令牌...</p>
</div>
</div>
`;
// 添加旋转动画
const style = document.createElement('style');
style.textContent = `
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
`;
document.head.appendChild(style);
overlay.appendChild(container);
document.body.appendChild(overlay);
}
// 更新状态显示
function updateStatus(html) {
const statusContent = document.getElementById('status-content');
if (statusContent) {
statusContent.innerHTML = html;
}
}
// 通过授权码获取刷新令牌
async function getRefreshTokenFromCode(code) {
const tokenUrl = "https://login.live.com/oauth20_token.srf";
const data = new URLSearchParams({
'client_id': '0000000040170455',
'code': code,
'grant_type': 'authorization_code',
'redirect_uri': 'https://login.live.com/oauth20_desktop.srf',
'scope': 'service::prod.rewardsplatform.microsoft.com::MBI_SSL'
});
try {
const response = await fetch(tokenUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: data
});
if (response.ok) {
const tokenData = await response.json();
if (tokenData.refresh_token) {
const refreshToken = tokenData.refresh_token;
// 保存令牌到本地存储
GM_setValue('bing_refresh_token', refreshToken);
// 复制到剪贴板
GM_setClipboard(refreshToken);
// 显示成功信息
showSuccessUI(refreshToken);
// 发送通知
GM_notification({
text: '✅ 刷新令牌获取成功!已复制到剪贴板',
title: 'Bing Rewards',
timeout: 5000
});
console.log('✅ 刷新令牌获取成功:', refreshToken);
} else {
throw new Error('响应中未找到refresh_token');
}
} else {
throw new Error(`请求失败,状态码: ${response.status}`);
}
} catch (error) {
console.error('❌ 获取令牌失败:', error);
showErrorUI(error.message);
GM_notification({
text: '❌ 获取令牌失败: ' + error.message,
title: 'Bing Rewards',
timeout: 5000
});
}
}
// 显示成功界面
function showSuccessUI(refreshToken) {
const maskedToken = refreshToken.substring(0, 20) + '...';
updateStatus(`
<div style="text-align: center;">
<div style="font-size: 48px; color: #28a745; margin-bottom: 15px;">✅</div>
<h3 style="color: #28a745; margin-bottom: 20px;">刷新令牌获取成功!</h3>
<div style="background: #f8f9fa; padding: 15px; border-radius: 5px; margin: 20px 0; border-left: 4px solid #28a745;">
<p style="margin: 0; color: #666;">🎯 您的刷新令牌: ${maskedToken}</p>
</div>
<div style="text-align: left; background: #e8f4fd; padding: 15px; border-radius: 5px; margin: 20px 0;">
<h4 style="color: #0078d4; margin-top: 0;">📋 使用说明:</h4>
<ul style="color: #333; margin: 10px 0; padding-left: 20px;">
<li>✅ 令牌已自动复制到剪贴板</li>
<li>✅ 令牌已保存到浏览器本地存储</li>
<li>💡 可以通过控制台 GM_getValue('bing_refresh_token') 获取</li>
</ul>
</div>
<button onclick="document.getElementById('token-overlay').remove()"
style="
background: #0078d4;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
margin-top: 15px;
">
关闭
</button>
</div>
`);
}
// 显示错误界面
function showErrorUI(errorMessage) {
updateStatus(`
<div style="text-align: center;">
<div style="font-size: 48px; color: #dc3545; margin-bottom: 15px;">❌</div>
<h3 style="color: #dc3545; margin-bottom: 20px;">获取令牌失败</h3>
<div style="background: #f8d7da; padding: 15px; border-radius: 5px; margin: 20px 0; border-left: 4px solid #dc3545;">
<p style="margin: 0; color: #721c24;">错误信息: ${errorMessage}</p>
</div>
<div style="text-align: left; background: #fff3cd; padding: 15px; border-radius: 5px; margin: 20px 0;">
<h4 style="color: #856404; margin-top: 0;">💡 解决建议:</h4>
<ul style="color: #333; margin: 10px 0; padding-left: 20px;">
<li>检查网络连接是否正常</li>
<li>确认已正确完成Microsoft账号授权</li>
<li>尝试重新访问授权链接</li>
</ul>
</div>
<button onclick="document.getElementById('token-overlay').remove()"
style="
background: #dc3545;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
margin-top: 15px;
">
关闭
</button>
</div>
`);
}
// 在授权页面添加说明
function addAuthInstructions() {
if (window.location.href.includes('oauth20_authorize.srf')) {
// 等待页面加载完成
setTimeout(() => {
const body = document.body;
if (body) {
const notice = document.createElement('div');
notice.style.cssText = `
position: fixed;
top: 10px;
right: 10px;
background: #0078d4;
color: white;
padding: 15px;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
z-index: 10000;
font-family: 'Segoe UI', sans-serif;
font-size: 14px;
max-width: 300px;
`;
notice.innerHTML = `
<div style="font-weight: bold; margin-bottom: 8px;">🔧 Bing Rewards 令牌工具</div>
<div>完成授权后,页面会自动跳转并获取刷新令牌</div>
<div style="margin-top: 8px; font-size: 12px; opacity: 0.9;">油猴脚本已激活 ✓</div>
`;
body.appendChild(notice);
// 5秒后自动隐藏
setTimeout(() => {
notice.style.opacity = '0';
notice.style.transition = 'opacity 0.5s';
setTimeout(() => notice.remove(), 500);
}, 5000);
}
}, 1000);
}
}
// 添加控制台帮助函数
window.getBingRefreshToken = function() {
const token = GM_getValue('bing_refresh_token');
if (token) {
console.log('🎯 当前保存的刷新令牌:', token);
GM_setClipboard(token);
console.log('✅ 令牌已复制到剪贴板');
return token;
} else {
console.log('❌ 未找到保存的刷新令牌');
return null;
}
};
// 页面加载时执行
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
checkForAuthCode();
addAuthInstructions();
});
} else {
checkForAuthCode();
addAuthInstructions();
}
// 监听URL变化(用于单页应用)
let currentUrl = window.location.href;
const urlObserver = new MutationObserver(() => {
if (window.location.href !== currentUrl) {
currentUrl = window.location.href;
checkForAuthCode();
addAuthInstructions();
}
});
urlObserver.observe(document.body, {
childList: true,
subtree: true
});
console.log('🔧 Bing Rewards 自动获取刷新令牌脚本已加载');
console.log('💡 使用 getBingRefreshToken() 函数可以获取已保存的令牌');
})();
该脚本为自动刷新令牌脚本。
主要作用
在你访问微软登录授权页后,自动拦截授权回调中的
code
授权码,并立即向微软令牌接口交换得到refresh_token
(刷新令牌)。把刷新令牌:
保存存储(
GM_setValue('bing_refresh_token')
)复制到剪贴板(
GM_setClipboard
)通知提示成功(
GM_notification
)页面上弹出一个 覆盖层 UI 展示"正在处理 / 成功 / 失败"的状态与指引。
在授权页给出 使用说明小贴士。
提供一个 控制台函数
getBingRefreshToken()
,随时取回并复制已保存的令牌。
触发
@match
:https://login.live.com/oauth20_desktop.srf*
(授权回调/重定向目标)https://login.live.com/oauth20_authorize.srf*
(授权页)@run-at document-start
:尽可能早地启动逻辑。
工作流程
检测授权码:
checkForAuthCode()
当 URL 是
oauth20_desktop.srf
且带有?code=...
参数时,认为授权完成。显示"处理中"覆盖层 → 调用
getRefreshTokenFromCode(code)
。交换令牌:
getRefreshTokenFromCode(code)
GM_setValue('bing_refresh_token', token)
GM_setClipboard(token)
弹 成功 UI(
showSuccessUI
)+ 桌面通知固定
client_id: 0000000040170455
grant_type: authorization_code
redirect_uri: https://login.live.com/oauth20_desktop.srf
scope: service::prod.rewardsplatform.microsoft.com::MBI_SSL
向
https://login.live.com/oauth20_token.srf
POST
:成功后从响应 JSON 里取
refresh_token
:失败则弹 错误 UI(
showErrorUI
)+ 通知授权页提示:
addAuthInstructions()
在
oauth20_authorize.srf
页右上角浮出"完成授权后会自动获取令牌"的小提示。URL 变化监听:
MutationObserver
监视 SPA/重载导致的地址变化,变化时再次执行检测与提示。
主要方法
checkForAuthCode()
:判断当前 URL 是否为回调并含code
,是就开始令牌交换。showProcessingUI()
/updateStatus(html)
:生成并更新全屏覆盖的处理状态界面(加载、结果、指引)。getRefreshTokenFromCode(code)
:核心交换逻辑;成功存储+复制+通知,失败统一报错。showSuccessUI(refreshToken)
/showErrorUI(errorMessage)
:渲染成功/失败的结果卡片及说明。addAuthInstructions()
:在授权页给用户友好提示(5 秒后淡出)。window.getBingRefreshToken()
:控制台便捷函数,读取已保存的刷新令牌并复制到剪贴板。
注意:
本文部分变量已做脱敏处理,仅用于测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。技术层面需要提供帮助,可以通过打赏的方式进行探讨。
没有评论:
发表评论