|
@@ -71,7 +71,7 @@
|
|
|
|
|
|
<li data-id="8">预约看现场</li>
|
|
<li data-id="8">预约看现场</li>
|
|
|
|
|
|
- <li data-id="9">二维码</li>
|
|
|
|
|
|
+ <li data-id="9">项目分享</li>
|
|
|
|
|
|
</ul>
|
|
</ul>
|
|
|
|
|
|
@@ -1178,60 +1178,6 @@
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
- //扫描二维码后验证
|
|
|
|
- // 使用Express等框架
|
|
|
|
- const express = require('express');
|
|
|
|
- const axios = require('axios');
|
|
|
|
- const app = express();
|
|
|
|
-
|
|
|
|
- // 公众号配置
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- // 处理微信授权回调,判断用户是否关注
|
|
|
|
- app.get('/wechat/callback', async (req, res) => {
|
|
|
|
- const { code } = req.query;
|
|
|
|
-
|
|
|
|
- // 获取access_token
|
|
|
|
- try {
|
|
|
|
- const tokenResponse = await axios.get(`https://api.weixin.qq.com/sns/oauth2/access_token?appid=${WECHAT_APPID}&secret=${WECHAT_SECRET}&code=${code}&grant_type=authorization_code`);
|
|
|
|
- const { access_token, openid } = tokenResponse.data;
|
|
|
|
-
|
|
|
|
- // 获取用户信息,判断是否关注公众号
|
|
|
|
- const userResponse = await axios.get(`https://api.weixin.qq.com/cgi-bin/user/info?access_token=${access_token}&openid=${openid}&lang=zh_CN`);
|
|
|
|
- const { subscribe } = userResponse.data;
|
|
|
|
-
|
|
|
|
- if (subscribe === 1) {
|
|
|
|
- // 已关注公众号,跳转到目标链接
|
|
|
|
- res.redirect('fullUrl');
|
|
|
|
- } else {
|
|
|
|
- // 未关注公众号,跳转到关注页面
|
|
|
|
- res.redirect('https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=your_biz_id#wechat_redirect');
|
|
|
|
- }
|
|
|
|
- } catch (error) {
|
|
|
|
- res.send('Error occurred: ' + error.message);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- // 监听端口
|
|
|
|
- app.listen(3000, () => {
|
|
|
|
- console.log('Server is running on port 3000');
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- // 引导用户进行微信OAuth授权
|
|
|
|
- function redirectToWeChatAuth() {
|
|
|
|
- const appId = 'wx60064e1cac4296e6';
|
|
|
|
- const redirectUri = encodeURIComponent('https://yourdomain.com/wechat/callback'); // 你的回调地址
|
|
|
|
- const wechatAuthUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`;
|
|
|
|
-
|
|
|
|
- // 跳转到微信的OAuth2.0授权页面
|
|
|
|
- window.location.href = wechatAuthUrl;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 当用户扫描二维码时,调用这个函数
|
|
|
|
- document.getElementById('qrcode').addEventListener('click', function() {
|
|
|
|
- redirectToWeChatAuth();
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
</html>
|
|
</html>
|