feat(mobile-h5): add local follow-confirm helpers for WeChat notify steps

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-08-14 12:12:56 +08:00
1 parent 16fba5e9b4
commit 239998ec44
2 files changed
+72

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
// mobile-h5/utils/mp-follow-confirm.js
export function followStorageKey(userId) {
const id = String(userId || '').trim() || 'anonymous'
return 'mp_follow_confirmed:' + id
}
export function isFollowConfirmed(userId, storage) {
const s = storage || (typeof uni !== 'undefined' ? uni : null)
if (!s || typeof s.getStorageSync !== 'function') return false
try {
return String(s.getStorageSync(followStorageKey(userId)) || '') === '1'
} catch (_) {
return false
}
}
export function setFollowConfirmed(userId, confirmed, storage) {
const s = storage || (typeof uni !== 'undefined' ? uni : null)
if (!s || typeof s.setStorageSync !== 'function') return
try {
s.setStorageSync(followStorageKey(userId), confirmed ? '1' : '0')
} catch (_) {
/* ignore */
}
}
/** @returns {{ step1Done: boolean, step2Done: boolean }} */
export function resolveStepDone({ bound, followConfirmed }) {
if (bound) return { step1Done: true, step2Done: true }
return {
step1Done: !!followConfirmed,
step2Done: false
}
}
+38
View File
@@ -0,0 +1,38 @@
// mobile-h5/utils/mp-follow-confirm.test.js
import assert from 'node:assert/strict'
import {
followStorageKey,
isFollowConfirmed,
setFollowConfirmed,
resolveStepDone
} from './mp-follow-confirm.js'
assert.equal(followStorageKey('u1'), 'mp_follow_confirmed:u1')
assert.equal(followStorageKey(''), 'mp_follow_confirmed:anonymous')
const store = new Map()
const api = {
getStorageSync: (k) => store.get(k),
setStorageSync: (k, v) => {
store.set(k, v)
}
}
assert.equal(isFollowConfirmed('u1', api), false)
setFollowConfirmed('u1', true, api)
assert.equal(isFollowConfirmed('u1', api), true)
assert.equal(isFollowConfirmed('u2', api), false)
assert.deepEqual(resolveStepDone({ bound: true, followConfirmed: false }), {
step1Done: true,
step2Done: true
})
assert.deepEqual(resolveStepDone({ bound: false, followConfirmed: true }), {
step1Done: true,
step2Done: false
})
assert.deepEqual(resolveStepDone({ bound: false, followConfirmed: false }), {
step1Done: false,
step2Done: false
})
console.log('mp-follow-confirm: ok')