Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions wxapp/guyu.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
@Date: 2024.06.07 19:15
@Description:
cron: 30 9 * * 1
------------------------------------------
[更新日志]

2026.09.21
1.增加缓存机制
2.修复签到报错问题


------------------------------------------
#Notice:
谷雨 微信小程序 签到得积分
Expand All @@ -25,12 +33,15 @@ WeChatCodeServer 填写wx_server_url wx_auth 用于获取code
const {
Env
} = require("../tools/env")
const $ = new Env("谷雨小程序");
const $ = new Env("谷雨小程序", {
bucket: "guyu_token_cache.json"
});
const WeChatServer = require("./wcs.js");
let ckName = `guyu`;
const strSplitor = "#";
const axios = require("axios");
const defaultUserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.31(0x18001e31) NetType/WIFI Language/zh_CN miniProgram"

let wechat = new WeChatServer({
url: process.env.wx_server_url || 'https://xxx',
appid: 'wxda948f3be0afc375',
Expand All @@ -43,7 +54,6 @@ class Task {
constructor(env) {
this.index = $.userIdx++
this.user = env.split(strSplitor);
this.token = null
this.wcsid = this.user[0]
this.isSign = false
this.shopId = '100186753'
Expand All @@ -53,11 +63,24 @@ class Task {

async run() {
//随机延迟5-30s 模拟人工操作
await $.wait(Math.floor(Math.random() * 20 + 5) * 1000);
let { data: codeRes } = await wechat.getCode(this.wcsid)
if (codeRes.status) {
await this.getUserToken(codeRes.data.code)
// await $.wait(Math.floor(Math.random() * 20 + 5) * 1000);

const userData = await $.get(this.wcsid)
if (userData) {
$.log('使用缓存')
this.token = userData.mobileToken
}

if (this.token && await this.getUserPoints()) {

} else {
$.log('缓存已失效,重新登录')
let { data: codeRes } = await wechat.getCode(this.wcsid)
if (codeRes.status) {
await this.getUserToken(codeRes.data.code)
}
}

if (!this.token) {
$.log(`账号[${this.index}] 获取用户Token失败❌`)
return
Expand Down Expand Up @@ -94,6 +117,8 @@ class Task {
let info = result.result || {}
this.token = info.mobileToken
if (info.shopId) this.shopId = "" + info.shopId

$.set(this.wcsid, info)
$.log(`🌸账号[${this.index}] 获取用户Token成功 门店:${info.shopName || this.shopId}`)
} else {
$.log(`🌸账号[${this.index}] 获取用户Token-失败:${result?.msg || result?.message}❌`)
Expand Down Expand Up @@ -157,7 +182,7 @@ class Task {
// 这里用两个只读查询接口动态拿当前可参与的签到活动(activityType=3)
async findSignActivity() {
try {
let { data: sys } = await this.request({
let { data: sys } = await this.request({
method: 'GET',
url: `https://mall-mobile-v6.vecrp.com/mobile/activity/common/queryIntegralSystemList`,
params: { shopId: this.shopId, earnSpendType: 1 },
Expand Down Expand Up @@ -260,9 +285,11 @@ class Task {
} = await this.request(options);
if (result?.success) {
$.log(`账号[${this.index}]` + `积分:${result.result[0].score}`);
return Promise.resolve(true)
} else {
$.log(`账号[${this.index}] 获取积分-失败:${result.msg}❌`)
}
return Promise.resolve(false)
}


Expand Down
27 changes: 16 additions & 11 deletions wxapp/qqhyjlb.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ class Task {
if (res.status !== 200 || String(d.status) !== "0") throw new Error(`upms登录失败: ${d.msg || `HTTP ${res.status}`}`);
const payload = (d.data && d.data.data) || d.data || {};
this.session.token = payload.token || this.session.token || "";
this.session.userId = String(payload.loginId || (payload.account || {}).loginId || "");
if (!this.session.userId) throw new Error(`upms未返回 loginId: ${short(d)}`);
this.session.loginId = String(payload.loginId || (payload.account || {}).loginId || "");
this.session.userId = String(payload.userId || (payload.account || {}).userId || "c10cff02123a9e2697d875262612399d");
if (!this.session.loginId) throw new Error(`upms未返回 loginId: ${short(d)}`);
}
async loginMobile() {
const code = await this.getCode();
const res = await axios.post(`${MOBILE_BASE}/wechat/login`,
formBody({ code, userId: this.session.userId }),
formBody({ code, userId: "c10cff02123a9e2697d875262612399d" }),
{ headers: this.commonHeaders({ from_env: "app" }), timeout: 20000, validateStatus: () => true });
const d = res.data || {};
if (String(d.status) !== "0") {
Expand All @@ -138,32 +139,36 @@ class Task {
if (sid) this.session.sessionId = sid;
const cust = (d.data || {}).customer || {};
if (!this.session.sessionId) throw new Error(`mobile登录未拿到 SESSION: ${short(d)}`);

this.log(`登录成功${cust.nickName ? `(${cust.nickName})` : ""}`);
}
async login() {
await this.loginUpms();
await this.loginMobile();
await this.loginUpms();

const cache = readCache();
cache[this.account.openid] = { ...this.session, updatedAt: new Date().toISOString() };
writeCache(cache);
}
async mobilePost(apiPath, data = {}) {
if (!this.session.sessionId) throw new Error("缺少SESSION");
const res = await axios.post(`${MOBILE_BASE}${apiPath}`,
formBody({ ...(data || {}), userId: this.session.userId }),
const res = await axios.post(`${VIP_BASE}${apiPath}`,
formBody({ ...(data || {}), uid: this.session.userId }),
{ headers: this.commonHeaders({ Cookie: `SESSION=${this.session.sessionId}`, Authorization: this.session.token || "", from_env: "app" }), timeout: 20000, validateStatus: () => true });
const sid = getSessionId(res.headers);
if (sid) this.session.sessionId = sid;
return res.data;
}
async sign() {
const list = (await this.mobilePost("/promotion/sign/list"))?.data || [];
const signedToday = Array.isArray(list) && list.some((it) => String(it?.signTime || "").slice(0, 10) === today());
var yearMonth = $.time("yyyy-MM")
var dayMonth = $.time("d");
const list = (await this.mobilePost("/vip/member/listUserSignLog", { "yearMonth": yearMonth, "tenantId": "1" }))?.data || [];
const signedToday = Array.isArray(list) && list.some((it) => it.dayMonth === dayMonth);
if (signedToday) {
const last = list[list.length - 1] || {};
return this.log(`✅ 今日已签到,连续 ${last.signContinuousDay || 0} 天`);
return this.log(`✅ 今日已签到,连续 ${last.continueDays || 0} 天`);
}
const res = await this.mobilePost("/promotion/sign/sign");
const res = await this.mobilePost("/vip/member/sign", { "channel": "", "tenantId": "1" });
if (String(res?.status) === "0") {
const point = (res.data || {}).point;
return this.log(`✅ 签到成功${point ? `,积分+${point}` : ""}`);
Expand All @@ -174,7 +179,7 @@ class Task {
}
async checkSession() {
try {
const r = await this.mobilePost("/promotion/sign/list");
const r = await this.mobilePost("/vip/member/getVipExtInfo", { "tenantId": "1" });
return String(r?.status) === "0" || Array.isArray(r?.data);
} catch (e) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion wxapp/youzan.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class Task {

async checkSession() {
const res = await this.h5Get("/wscaccount/api/authorize/data.json");
return isOk(res);
return res && res.data && res.data.userInfo && res.data.userInfo.hasLogin;
}

async ensureLogin() {
Expand Down