chore(mini): 上传描述标注PineBot,新增设为体验版脚本
- upload 脚本描述改为 'PineBot 自动上传' - 新增 scripts/set-experience.js:调用微信 API 将最新开发版设为体验版(需 WX_APPSECRET 环境变量) - package.json 新增 set-experience script
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* 将最新上传的开发版设为体验版
|
||||
* 用法:WX_APPSECRET=你的AppSecret node scripts/set-experience.js
|
||||
* 或在 package.json 里配置后:npm run set-experience
|
||||
*/
|
||||
const https = require('https');
|
||||
|
||||
const APPID = 'wx349f46ac71770777';
|
||||
const APPSECRET = process.env.WX_APPSECRET;
|
||||
|
||||
if (!APPSECRET) {
|
||||
console.error('错误:请设置环境变量 WX_APPSECRET(微信公众平台 -> 开发 -> 开发管理 -> 开发设置 -> AppSecret)');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function request(method, path, body) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const data = body ? JSON.stringify(body) : null;
|
||||
const req = https.request({
|
||||
hostname: 'api.weixin.qq.com',
|
||||
path,
|
||||
method,
|
||||
headers: data ? { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(data) } : {},
|
||||
}, (res) => {
|
||||
let raw = '';
|
||||
res.on('data', (c) => (raw += c));
|
||||
res.on('end', () => {
|
||||
try { resolve(JSON.parse(raw)); } catch { resolve(raw); }
|
||||
});
|
||||
});
|
||||
req.on('error', reject);
|
||||
if (data) req.write(data);
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
// 1. 获取 access_token
|
||||
const tokenRes = await request('GET', `/cgi-bin/token?grant_type=client_credential&appid=${APPID}&secret=${APPSECRET}`);
|
||||
if (!tokenRes.access_token) {
|
||||
console.error('获取 access_token 失败:', JSON.stringify(tokenRes));
|
||||
process.exit(1);
|
||||
}
|
||||
console.log('access_token 获取成功');
|
||||
|
||||
// 2. 设为体验版
|
||||
const result = await request('POST', `/wxa/version_control/release?access_token=${tokenRes.access_token}`, {
|
||||
action: 'set_experience',
|
||||
});
|
||||
console.log('设置体验版结果:', JSON.stringify(result));
|
||||
if (result.errcode === 0) {
|
||||
console.log('✓ 已成功设为体验版');
|
||||
} else {
|
||||
console.log('提示:若 errcode 表示接口不支持,请在微信公众平台 -> 管理 -> 版本管理 -> 开发版本 中手动点击「选为体验版」');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('执行失败:', e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user