好友
阅读权限10
听众
最后登录1970-1-1
|
本帖最后由 niustark 于 2026-10-29 09:11 编辑
最近发现pushplus支持免费5G短信通知了(中国移动用户),想起来之前论坛里有过几个版本的挪车二维码页面,
加上我自己用vibe coding加上了自己的一些想法,感觉挺好用的,就把代码分享出来供大家参考.
这是部署完的页面预览
利用Cloudflare Workers部署挪车页面
代码粘贴到workers里就行了,在设置里面增加这3个变量,填自己的
手机号
车牌号
pushplus的token就行了
代码打包了.
move-car-worker.zip
(4.06 KB, 下载次数: 197)
收到短信提醒是这样的
[JavaScript] 纯文本查看 复制代码 // ===== 使用 ES Module 语法(Cloudflare Workers 当前标准写法)=====
// 环境变量通过 fetch 的第二个参数 env 传入,确保能读到配置
export default {
async fetch(request, env, ctx) {
return handleRequest(request, env)
}
}
async function handleRequest(request, env) {
// 防御:个别部署环境不传 env 时,退化为空对象,避免报 undefined 错误
env = env || globalThis.env || {}
// ===== 敏感信息全部从环境变量读取(在 Cloudflare 控制台或 wrangler 中配置)=====
// 必须配置的环境变量:
// PHONE 车主手机号,如 15888888888
// PUSHPLUS_TOKEN pushplus 的 token
// PLATE 车牌号,如 豫C99999
const phone = env.PHONE
const pushplusToken = env.PUSHPLUS_TOKEN
const plate = env.PLATE
// 校验环境变量是否已配置
if (!phone || !pushplusToken || !plate) {
return new Response(
'缺少环境变量:请在 Cloudflare 中配置 PHONE、PUSHPLUS_TOKEN、PLATE(Settings → Variables → Environment Variables / Secrets)',
{ status: 500, headers: { 'Content-Type': 'text/plain;charset=UTF-8' } }
)
}
// 从车牌号中拆出省份简称、发牌机关字母、序号(如 豫C99999 -> 豫 / C / 99999)
const plateProvince = plate.slice(0, 1)
const plateLetter = plate.slice(1, 2)
const plateNumbers = plate.slice(2)
const htmlContent = `
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>通知车主挪车</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🚗</text></svg>">
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--primary-color: #4776E6;
--secondary-color: #8E54E9;
--text-color: #2c3e50;
--shadow-color: rgba(0, 0, 0, 0.1);
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
color: var(--text-color);
padding: 20px;
line-height: 1.6;
}
.container {
text-align: center;
padding: 30px;
width: 100%;
max-width: 450px;
border-radius: 24px;
box-shadow: 0 10px 40px var(--shadow-color);
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
transform: translateY(0);
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.container:hover {
transform: translateY(-8px);
box-shadow: 0 15px 50px rgba(0, 0, 0, 0.15);
}
h1 {
font-size: 32px;
margin-bottom: 25px;
background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
font-weight: 700;
}
.car-icon {
font-size: 64px;
margin-bottom: 20px;
display: inline-block;
animation: float 6s ease-in-out infinite;
}
p {
margin-bottom: 20px;
font-size: 12px;
color: #546e7a;
line-height: 1.3;
}
.button-group {
display: flex;
flex-direction: column;
gap: 15px;
}
button {
width: 100%;
padding: 16px 24px;
font-size: 18px;
font-weight: 600;
color: #fff;
border: none;
border-radius: 16px;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
}
button:active {
transform: scale(0.98);
}
.notify-btn {
background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
box-shadow: 0 4px 15px rgba(71, 118, 230, 0.2);
}
.notify-btn:hover {
box-shadow: 0 6px 20px rgba(71, 118, 230, 0.3);
transform: translateY(-2px);
}
.call-btn {
background: linear-gradient(45deg, #00b09b, #96c93d);
box-shadow: 0 4px 15px rgba(0, 176, 155, 0.2);
}
.call-btn:hover {
box-shadow: 0 6px 20px rgba(0, 176, 155, 0.3);
transform: translateY(-2px);
}
@keyframes float {
0% { transform: translateY(0px) rotate(0deg); }
50% { transform: translateY(-20px) rotate(5deg); }
100% { transform: translateY(0px) rotate(0deg); }
}
.loading {
position: relative;
pointer-events: none;
}
.loading::after {
content: "";
position: absolute;
width: 20px;
height: 20px;
border: 3px solid #ffffff;
border-radius: 50%;
border-top-color: transparent;
animation: spin 0.8s linear infinite;
margin-left: 10px;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.toast {
position: fixed;
top: 30%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(0, 0, 0, 0.8);
color: white;
padding: 10px 24px;
border-radius: 20px;
font-size: 14px;
opacity: 0;
transition: opacity 0.3s;
z-index: 1000;
}
.toast.show {
opacity: 1;
}
/* 中国标准蓝牌样式 */
.license-plate-blue {
display: inline-flex;
align-items: center;
justify-content: center;
font-family: 'Arial', sans-serif;
background: linear-gradient(to bottom, #0c44c5, #1a65ff, #0c44c5);
border: 3px solid #fff;
border-radius: 8px;
padding: 10px 20px;
margin: 25px 0;
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3);
position: relative;
overflow: hidden;
}
.license-plate-blue::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
height: 5px;
background: rgba(255, 255, 255, 0.2);
}
.license-plate-blue::after {
content: "• 豫 •";
position: absolute;
bottom: 5px;
left: 0;
right: 0;
font-size: 8px;
color: rgba(255, 255, 255, 0.7);
letter-spacing: 2px;
}
.province {
font-size: 36px;
font-weight: bold;
color: #fff;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
margin-right: 4px;
}
.letter {
font-size: 36px;
font-weight: bold;
color: #fff;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
margin: 0 3px;
}
.numbers {
font-size: 36px;
font-weight: bold;
color: #FFDE59;
letter-spacing: 3px;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
/* 按钮图标动画 */
button span {
transition: transform 0.3s ease;
}
button:hover span {
transform: scale(1.05);
}
.plate-title {
color: #2c3e50;
font-size: 14px;
margin-bottom: 8px;
opacity: 0.8;
}
</style>
</head>
<body>
<div class="container">
<div class="license-plate-blue">
<span class="province">${plateProvince}</span>
<span class="letter">${plateLetter}</span>
<span class="numbers">${plateNumbers}</span>
</div>
<p>请通过以下方式联系车主,我会立即前来处理</p>
<div class="button-group">
<button class="notify-btn">
🚘️<span>通知挪车</span>
</button>
<button class="notify-btn">
🚐<span>提醒未关车窗</span>
</button>
<button class="notify-btn">
💡<span>提醒未关车灯</span>
</button>
<button class="call-btn">
📞<span>电话联系</span>
</button>
</div>
</div>
<div id="toast" class="toast"></div>
<script>
// 敏感信息不写死在前端代码中,由服务端渲染时注入
const PLATE = '${plate}';
function showToast(message, duration = 3000) {
const toast = document.getElementById('toast');
toast.textContent = message;
toast.classList.add('show');
setTimeout(() => toast.classList.remove('show'), duration);
}
function notifyOwner(type) {
const buttons = document.querySelectorAll('.notify-btn');
buttons.forEach(btn => {
btn.classList.add('loading');
btn.disabled = true;
});
const messages = {
moveCar: {
title: '挪车通知',
content: '您好,您的车牌号' + PLATE + '阻碍了他人通行,请尽快前往挪车',
toast: "通知已发送,车主很快就来!"
},
remindWindows: {
title: '车窗提醒',
content: '温馨提醒:您的车牌号' + PLATE + '车窗未关,请及时检查以防物品丢失',
toast: "车窗提醒已发送!"
},
remindLights: {
title: '车灯提醒',
content: '温馨提醒:您的车牌号' + PLATE + '车灯未关闭,请及时检查以防电瓶亏电',
toast: "车灯提醒已发送!"
}
};
const { title, content, toast: toastMessage } = messages[type];
// 使用pushplus发送通知(5G消息/新消息ClawBot渠道)
// token 由服务端渲染注入,不在源代码中明文出现
fetch('https://www.pushplus.plus/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
token: '${pushplusToken}',
title: title,
content: content,
channel: 'cmcc', // 5G消息(中国移动「新消息ClawBot」应用号)渠道
template: 'txt' // 5G消息渠道建议使用txt模板,正文完整展示
})
})
.then(response => response.json())
.then(data => {
buttons.forEach(btn => {
btn.classList.remove('loading');
btn.disabled = false;
});
// pushplus成功响应code为200
data.code === 200
? showToast(toastMessage)
: showToast("发送失败: " + (data.msg || '请电话联系'));
})
.catch(error => {
console.error("Error:", error);
buttons.forEach(btn => {
btn.classList.remove('loading');
btn.disabled = false;
});
showToast("网络错误,请电话联系");
});
}
function callOwner() {
window.location.href = "tel:${phone}";
}
</script>
</body>
</html>
`;
return new Response(htmlContent, {
headers: { 'Content-Type': 'text/html;charset=UTF-8' },
});
}
|
免费评分
-
查看全部评分
|