This commit is contained in:
hero920103 committed 2026-11-03 09:02:24 +08:00
commit 843d7164f6
66 files changed
+6976 -864

No files matched your search

+13
View File
@@ -122,6 +122,19 @@ export function loginByMiniapp({ code, phoneCode = '' } = {}) {
})
}
/**
* 小程序端确认注册:网页注册页展示的小程序码扫码进入本页,
* 用户点确认后由服务端把 openid 绑定到该注册会话,网页端即可继续注册。
* @param {{ scene: string, code: string, phoneCode?: string, appid?: string }} params
*/
export function confirmMiniappRegister({ scene, code, phoneCode = '', appid = '' } = {}) {
return request({
url: '/auth/register/mini/confirm',
method: 'POST',
data: { scene, code, phone_code: phoneCode, appid }
})
}
/**
* 已登录态下把当前微信 openid 绑定到该账号(静默调用,失败不提示)。
* 小程序认证中 / 未开通手机号能力时,一键登录靠这条绑定按 openid 认人。
+19
View File
@@ -11,6 +11,20 @@ const DEFAULT_PROD_API = 'https://api.yunzer.cn'
/**
* @returns {string} 去掉末尾斜杠的 baseURL
*/
/**
* 小程序端 baseURL 兜底:微信要求 request 必须走「已配置的 https 合法域名」,
* localhost / 127.0.0.1 / 相对路径 / http 明文在体验版与正式版都会直接报
* "url not in domain list"。出现这类取值一律回退生产 API(本地调试请用 H5 端,
* 或在开发者工具勾选「不校验合法域名」时用真机调试)。
*/
function sanitizeMiniProgramBase(base) {
const b = String(base || '')
if (!b || b.startsWith('/') || !/^https:\/\//i.test(b) || /(localhost|127\.0\.0\.1)/i.test(b)) {
return DEFAULT_PROD_API
}
return b
}
export function resolveBaseURL() {
let fromEnv = ''
try {
@@ -24,7 +38,12 @@ export function resolveBaseURL() {
}
if (fromEnv && fromEnv !== 'undefined' && fromEnv !== 'null') {
// #ifdef MP
return sanitizeMiniProgramBase(String(fromEnv))
// #endif
// #ifndef MP
return String(fromEnv).replace(/\/$/, '')
// #endif
}
// #ifdef H5
+41
View File
@@ -0,0 +1,41 @@
/**
* 小程序订阅消息(对应后端 go/controllers/api_mini_subscribe.go)
*
* 订阅消息是「用户授权 → 服务器主动推给用户」的通道:
* 1. getSubscribeTemplates() 取当前可订阅的模板
* 2. 用户在微信弹窗里同意后,authorizeSubscribe() 上报,服务器记一次发送机会
* 3. 之后业务侧发站内信/审批待办,服务器自动推送到用户微信
*/
import { request } from '@/api/request.js'
/** 取可订阅的模板列表(含模板 ID、跳转页面、剩余可发送次数) */
export function getSubscribeTemplates() {
return request({
url: '/api/mini/subscribe/templates',
method: 'get'
})
}
/**
* 上报授权结果:每授权一次,服务器记一次可发送机会
* @param {string[]} templateIds 用户同意的模板 ID 列表
*/
export function authorizeSubscribe(templateIds) {
return request({
url: '/api/mini/subscribe/authorize',
method: 'post',
data: { template_ids: templateIds }
})
}
/**
* 发一条测试订阅消息(验证模板配置是否正确)
* @param {{title?: string, content?: string}} payload
*/
export function sendTestSubscribeNotice(payload = {}) {
return request({
url: '/api/mini/subscribe/test',
method: 'post',
data: payload
})
}