Skip to content

Commit

Permalink
监听模式支持多位置尝试签到(暂不支持从Web启用监听的情况);手动签到添加位置列表;
Browse files Browse the repository at this point in the history
  • Loading branch information
cxOrz committed May 25, 2023
1 parent 14502ea commit e213913
Show file tree
Hide file tree
Showing 4 changed files with 274 additions and 148 deletions.
120 changes: 120 additions & 0 deletions apps/server/src/configs/prompts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { red } from 'kolorist';
import prompts from 'prompts';

export const PromptsOptions = {
onCancel: () => {
console.log(red('✖') + ' 操作取消');
process.exit(0);
},
};

// 最多保存10个位置,签到失败则轮流尝试
export const addressPrompts = async () => {
const presetAddress = [];
for (let i = 0; i < 10; i++) {
let { lon_lat_address } = await prompts({
type: 'text',
name: 'lon_lat_address',
message: `位置参数预设#${i + 1}(经纬度/地址)`,
initial: '113.516288,34.817038/河南省郑州市万科城大学软件楼',
}, PromptsOptions);
lon_lat_address = lon_lat_address.match(/([\d.]*),([\d.]*)\/(\S*)/);
console.log(`#${i + 1} 经度: ${lon_lat_address?.[1]} 纬度: ${lon_lat_address?.[2]} 地址: ${lon_lat_address?.[3]}`);
presetAddress.push({
lon: lon_lat_address?.[1],
lat: lon_lat_address?.[2],
address: lon_lat_address?.[3]
});
// 到10个就不再询问继续
if (i < 9) {
const { next } = await prompts({
type: () => i === 9 ? null : 'confirm',
name: 'next',
message: '是否继续添加',
initial: true,
}, PromptsOptions);
if (!next) break;
}
}
return presetAddress;
};

/**
* 监听模式问题数组
*/
export const monitorPromptsQuestions: Array<prompts.PromptObject> = [
{
type: 'number',
name: 'delay',
message: '签到延时(单位:秒)',
initial: 0,
},
{
type: 'confirm',
name: 'mail',
message: '是否启用邮件通知?',
initial: false,
},
{
type: (prev) => (prev ? 'text' : null),
name: 'host',
message: 'SMTP服务器',
initial: 'smtp.qq.com',
},
{
type: (prev) => (prev ? 'confirm' : null),
name: 'ssl',
message: '是否启用SSL',
initial: true,
},
{
type: (prev) => (prev ? 'number' : null),
name: 'port',
message: '端口号',
initial: 465,
},
{
type: (prev) => (prev ? 'text' : null),
name: 'user',
message: '邮件账号',
initial: 'xxxxxxxxx@qq.com',
},
{
type: (prev) => (prev ? 'text' : null),
name: 'pass',
message: '授权码(密码)',
},
{
type: (prev) => (prev ? 'text' : null),
name: 'to',
message: '接收邮箱',
},
{
type: 'confirm',
name: 'cq_enabled',
message: '是否连接到go-cqhttp服务?',
initial: false,
},
{
type: (prev) => (prev ? 'text' : null),
name: 'ws_url',
message: 'Websocket 地址',
initial: 'ws://127.0.0.1:8080',
},
{
type: (prev) => (prev ? 'select' : null),
name: 'target_type',
message: '选择消息的推送目标',
choices: [
{ title: '群组', value: 'group' },
{ title: '私聊', value: 'private' }
],
},
{
type: (prev) => (prev ? 'number' : null),
name: 'target_id',
message: '接收号码',
initial: 10001,
},
];

134 changes: 104 additions & 30 deletions apps/server/src/functions/location.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,118 @@
import { CHAT_GROUP, PPTSIGN } from '../configs/api';
import { delay } from '../utils/helper';
import { cookieSerialize, request } from '../utils/request';

export const LocationSign = async (
args: BasicCookie & { name: string; address: string; activeId: string; lat: string; lon: string; fid: string; }
): Promise<string> => {
const { name, address, activeId, lat, lon, fid, ...cookies } = args;
const url = `${PPTSIGN.URL}?name=${name}&address=${address}&activeId=${activeId}&uid=${cookies._uid}&clientip=&latitude=${lat}&longitude=${lon}&fid=${fid}&appType=15&ifTiJiao=1`;
const result = await request(url, {
secure: true,
headers: {
Cookie: cookieSerialize(cookies),
},
});
const msg = result.data === 'success' ? '[位置]签到成功' : `[位置]${result.data}`;
interface AddressItem {
lon: string;
lat: string;
address: string;
}
type PresetAddress = AddressItem[];
type CookieWithAddressItemArgs = BasicCookie & AddressItem & { name: string; activeId: string; fid: string; };
type CookieWithPresetAddressArgs = BasicCookie & { presetAddress: PresetAddress; name: string; activeId: string; fid: string; };

type LocationSignType = {
(arg1: CookieWithAddressItemArgs): Promise<string>;
(arg1: CookieWithPresetAddressArgs): Promise<string>;
};

export const LocationSign: LocationSignType = async (args): Promise<string> => {
let msg = '';
if ('address' in args) {
// 单个位置直接签
const { name, address, activeId, lat, lon, fid, ...cookies } = args;
const url = `${PPTSIGN.URL}?name=${name}&address=${address}&activeId=${activeId}&uid=${cookies._uid}&clientip=&latitude=${lat}&longitude=${lon}&fid=${fid}&appType=15&ifTiJiao=1`;
const result = await request(url, {
secure: true,
headers: {
Cookie: cookieSerialize(cookies),
},
});
msg = result.data === 'success' ? '[位置]签到成功' : `[位置]${result.data}`;
} else {
// 多个位置尝试
const { name, activeId, presetAddress, fid, ...cookies } = args;
for (let i = 0; i < presetAddress.length; i++) {
const url = `${PPTSIGN.URL}?name=${name}&address=${presetAddress[i].address}&activeId=${activeId}&uid=${cookies._uid}&clientip=&latitude=${presetAddress[i].lat}&longitude=${presetAddress[i].lon}&fid=${fid}&appType=15&ifTiJiao=1`;
const result = await request(url, {
secure: true,
headers: {
Cookie: cookieSerialize(cookies),
},
});
if (result.data === 'success') {
msg = '[位置]签到成功';
break;
} else {
msg = `[位置]${result.data}`;
await delay(1);
}
}
}
console.log(msg);
return msg;
};

/**
* 位置签到,无课程群聊版本
*/
export const LocationSign_2 = async (
args: BasicCookie & { name: string; address: string; activeId: string; lat: string; lon: string; fid: string; }
): Promise<string> => {
const { address, activeId, lat, lon, ...cookies } = args;
const formdata = `address=${encodeURIComponent(address)}&activeId=${activeId}&uid=${cookies._uid
}&clientip=&useragent=&latitude=${lat}&longitude=${lon}&fid=&ifTiJiao=1`;
const result = await request(
CHAT_GROUP.SIGN.URL,
{
secure: true,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
Cookie: cookieSerialize(cookies),
export const LocationSign_2: LocationSignType = async (args): Promise<string> => {
let msg = '';
if ('address' in args) {
// 单个位置直接签
const { address, activeId, lat, lon, ...cookies } = args;
const formdata = `address=${encodeURIComponent(address)}&activeId=${activeId}&uid=${cookies._uid}&clientip=&useragent=&latitude=${lat}&longitude=${lon}&fid=&ifTiJiao=1`;
const result = await request(
CHAT_GROUP.SIGN.URL,
{
secure: true,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
Cookie: cookieSerialize(cookies),
},
},
},
formdata
);
const msg = result.data === 'success' ? '[位置]签到成功' : `[位置]${result.data}`;
formdata
);
msg = result.data === 'success' ? '[位置]签到成功' : `[位置]${result.data}`;
} else {
// 多个位置尝试
const { activeId, presetAddress, ...cookies } = args;
for (let i = 0; i < presetAddress.length; i++) {
const formdata = `address=${encodeURIComponent(presetAddress[i].address)}&activeId=${activeId}&uid=${cookies._uid}&clientip=&useragent=&latitude=${presetAddress[i].lat}&longitude=${presetAddress[i].lon}&fid=&ifTiJiao=1`;
const result = await request(
CHAT_GROUP.SIGN.URL,
{
secure: true,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
Cookie: cookieSerialize(cookies),
},
},
formdata
);
if (result.data === 'success') {
msg = '[位置]签到成功';
break;
} else {
msg = `[位置]${result.data}`;
await delay(1);
}
}
}
console.log(msg);
return msg;
};

export const presetAddressChoices = (presetAddress: any[] = []) => {
const arr = [];
for (let i = 0; i < presetAddress.length; i++) {
arr.push({
title: `${presetAddress[i].lon},${presetAddress[i].lat}/${presetAddress[i].address}`,
value: i,
});
}
arr.push({ title: '手动添加', value: -1 });
return [...arr];
};
53 changes: 44 additions & 9 deletions apps/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import prompts from 'prompts';
import { blue, red } from 'kolorist';
import { getPPTActiveInfo, preSign, traverseCourseActivity } from './functions/activity';
import { GeneralSign } from './functions/general';
import { LocationSign } from './functions/location';
import { LocationSign, presetAddressChoices } from './functions/location';
import { getObjectIdFromcxPan, PhotoSign } from './functions/photo';
import { QRCodeSign } from './functions/qrcode';
import { getAccountInfo, getCourses, getLocalUsers, userLogin } from './functions/user';
Expand Down Expand Up @@ -72,14 +72,49 @@ const PromptsOptions = {
case 4: {
// 位置签到
console.log('[获取经纬度]https://api.map.baidu.com/lbsapi/getpoint/index.html');
const defaultLngLat = configs.monitor ? `${configs.monitor.lon},${configs.monitor.lat}` : '113.516288,34.817038';
const defaultAddress = configs.monitor ? configs.monitor.address : '';
const { lnglat } = await prompts({ type: 'text', name: 'lnglat', message: '经纬度', initial: defaultLngLat }, PromptsOptions);
const { address } = await prompts({ type: 'text', name: 'address', message: '详细地址', initial: defaultAddress });
const lat = lnglat.substring(lnglat.indexOf(',') + 1, lnglat.length);
const lon = lnglat.substring(0, lnglat.indexOf(','));
await LocationSign({ ...activity, ...params, address, lat, lon, name, });
configs.monitor = { lon, lat, address, delay: configs?.monitor?.delay || 0 };
const { presetItem } = await prompts({
type: 'select',
name: 'presetItem',
message: '详细地址',
choices: presetAddressChoices(configs.monitor.presetAddress),
initial: 0,
}, PromptsOptions);
let lon_lat_address: any;
if (presetItem === -1) {
// 手动添加
const { lon_lat_address: result } = await prompts({
type: 'text',
name: 'lon_lat_address',
message: '位置参数预设(经纬度/地址)',
initial: '113.516288,34.817038/河南省郑州市万科城大学软件楼',
}, PromptsOptions);
lon_lat_address = result.match(/([\d.]*),([\d.]*)\/(\S*)/);
configs.monitor.presetAddress.push({
lon: result?.[1],
lat: result?.[2],
address: result?.[3]
}
);
} else {
// 选取地址
lon_lat_address = [
'填充[0]',
configs.monitor.presetAddress[presetItem].lon,
configs.monitor.presetAddress[presetItem].lat,
configs.monitor.presetAddress[presetItem].address,
];
}

// 构成预设位置对象
const addressItem = {
lon: lon_lat_address?.[1],
lat: lon_lat_address?.[2],
address: lon_lat_address?.[3]
};
await LocationSign({ ...activity, ...params, ...addressItem, name });

// 更新本地数据
configs.monitor = { presetAddress: configs?.monitor.presetAddress, delay: configs?.monitor?.delay || 0 };
configs.mailing = configs.mailing ? configs.mailing : { enabled: false };
configs.cqserver = configs.cqserver ? configs.cqserver : { cq_enabled: false };
break;
Expand Down
Loading

0 comments on commit e213913

Please sign in to comment.