Files
dukang/packages/weixin-sdk/src/index.ts
T
jacy e4e9eb2169 fix(h5-shop): harden iOS WeChat scan after login with hard nav and recover UI
Root cause is JSSDK entry-URL mismatch after SPA post-OAuth, not camera permission. Hard-navigate on iOS, keep OAuth query in sign URL, skip redundant bind OAuth, and prompt refresh/re-auth on failure.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-07 13:08:13 +08:00

90 lines
3.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export { isWechatBrowser, isMiniProgram, getRuntimePlatform, isIosDevice, isWechatDevTools } from './env';
export { getRouterBasename, toAppPath, isOnAppPath } from './app-path';
export {
initWechatJssdk,
ensureJssdkReady,
isJssdkReady,
normalizeJssdkPageUrl,
jssdkUrlWithoutHash,
getJssdkSignUrl,
captureIosJssdkEntryUrl,
resetJssdkConfig,
stripOAuthParamsFromLocation,
hardNavigateInWechat,
shouldHardNavigateForJssdk,
} from './jssdk';
export { formatScanFailMessage, isScanPermissionWarmupError } from './scan';
export {
getWechatLocation,
getWechatLocationDetailed,
canUseWechatLocation,
isWechatEnv,
} from './location';
export type { WechatLocationOutcome } from './location';
export { scanQrCode } from './scan';
export { invokeWechatPay } from './pay';
export { chooseWechatImages, canUseWechatChooseImage, formatChooseImageFailMessage } from './chooseImage';
export type { ChooseWechatImageOptions } from './chooseImage';
export {
setWechatShareData,
canUseWechatShare,
getWechatShareLink,
shareViaWechatSdk,
tryInvokeSharePanel,
} from './share';
export type { WechatShareData } from './share';
export {
getWechatOAuthUrl,
startWechatOAuthLogin,
getMiniProgramLoginCode,
loginWithWechatCode,
handleWechatOAuthCallback,
bindWechatPhone,
getWechatPhoneNumber,
wechatLogin,
WECHAT_INAPP_REQUIRED_MSG,
} from './auth';
export type { WeixinSdkConfig, WxApi, MiniProgramWx } from './types';
export { DEFAULT_JS_API_LIST } from './types';
import type { WeixinSdkConfig } from './types';
import { initWechatJssdk, resetJssdkConfig } from './jssdk';
import { getWechatLocation, getWechatLocationDetailed } from './location';
import { scanQrCode } from './scan';
import { invokeWechatPay } from './pay';
import { chooseWechatImages } from './chooseImage';
import { setWechatShareData, shareViaWechatSdk } from './share';
import {
wechatLogin,
handleWechatOAuthCallback,
bindWechatPhone,
getWechatPhoneNumber,
} from './auth';
/** 微信 SDK 门面(按端注入 apiBase / clientApp */
export function createWeixinSdk(config: WeixinSdkConfig) {
return {
init: () => initWechatJssdk({ ...config, apiBase: config.apiBase ?? '/api/v1' }),
reset: () => resetJssdkConfig(),
login: () => wechatLogin(config),
handleOAuthCallback: (params?: URLSearchParams) => handleWechatOAuthCallback(config, params),
bindPhone: (payload: { wxSessionKey: string; phone: string; code: string }) =>
bindWechatPhone(config, payload),
getPhoneNumber: () => getWechatPhoneNumber(config),
getLocation: () => getWechatLocation(config),
getLocationDetailed: () => getWechatLocationDetailed(config),
scanQrCode: (options?: Parameters<typeof scanQrCode>[1]) => scanQrCode(config, options),
chooseImages: (options?: Parameters<typeof chooseWechatImages>[1]) =>
chooseWechatImages(config, options),
pay: (prepay: Parameters<typeof invokeWechatPay>[0]) =>
invokeWechatPay(prepay, {
apiBase: config.apiBase ?? '/api/v1',
clientApp: config.clientApp,
getAccessToken: config.getAccessToken,
}),
setShare: (data: Parameters<typeof setWechatShareData>[1]) =>
setWechatShareData(config, data),
share: (data: Parameters<typeof shareViaWechatSdk>[1]) => shareViaWechatSdk(config, data),
};
}