diff --git a/apps/h5-shop/package.json b/apps/h5-shop/package.json
index ea6033a..62b7619 100644
--- a/apps/h5-shop/package.json
+++ b/apps/h5-shop/package.json
@@ -11,6 +11,7 @@
"dependencies": {
"@dukang/shared-ui": "workspace:*",
"@dukang/shared-types": "workspace:*",
+ "@dukang/weixin-sdk": "workspace:*",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.26.0"
diff --git a/apps/h5-shop/src/lib/weixin.ts b/apps/h5-shop/src/lib/weixin.ts
new file mode 100644
index 0000000..48349a4
--- /dev/null
+++ b/apps/h5-shop/src/lib/weixin.ts
@@ -0,0 +1,9 @@
+import { createWeixinSdk, isWechatEnv } from '@dukang/weixin-sdk';
+
+export const weixinSdk = createWeixinSdk({
+ apiBase: '/api/v1',
+ clientApp: 'SHOP_H5',
+ getAccessToken: () => localStorage.getItem('accessToken'),
+});
+
+export { isWechatEnv };
diff --git a/apps/h5-shop/src/pages/HomePage.tsx b/apps/h5-shop/src/pages/HomePage.tsx
index 2e6dc85..4ec2df6 100644
--- a/apps/h5-shop/src/pages/HomePage.tsx
+++ b/apps/h5-shop/src/pages/HomePage.tsx
@@ -1,6 +1,7 @@
import { useEffect, useState } from 'react';
import { Link, useNavigate } from 'react-router-dom';
import { isLoggedIn, request } from '../lib/api';
+import { isWechatEnv, weixinSdk } from '../lib/weixin';
function formatMoney(n: number) {
return n.toLocaleString('zh-CN', { minimumFractionDigits: 0, maximumFractionDigits: 2 });
@@ -27,6 +28,22 @@ export default function HomePage() {
const openTime = String(store?.openTime || '10:00');
const closeTime = String(store?.closeTime || '22:00');
+ async function handleScan() {
+ if (isWechatEnv()) {
+ try {
+ await weixinSdk.init();
+ const token = await weixinSdk.scanQrCode();
+ if (token) {
+ navigate(`/redeem?token=${encodeURIComponent(token)}`);
+ return;
+ }
+ } catch {
+ /* fall through to manual redeem page */
+ }
+ }
+ navigate('/redeem');
+ }
+
return (
@@ -55,7 +72,7 @@ export default function HomePage() {
-