Commit 607807d2997f00455827215cf1390c9e5904b811

Authored by tianwu
1 parent 62689239

替换weixinjssdk

apps/web-payment/index.html
... ... @@ -17,7 +17,6 @@
17 17 </head>
18 18 <body>
19 19 <div id="app"></div>
20   - <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js" ></script>
21 20 <script type="module" src="/src/main.ts"></script>
22 21 </body>
23 22 </html>
... ...
apps/web-payment/package.json
... ... @@ -48,7 +48,8 @@
48 48 "qs": "catalog:",
49 49 "vconsole": "^3.15.1",
50 50 "vue": "catalog:",
51   - "vue-router": "catalog:"
  51 + "vue-router": "catalog:",
  52 + "weixin-js-sdk": "^1.6.5"
52 53 },
53 54 "devDependencies": {
54 55 "unplugin-element-plus": "catalog:"
... ...
apps/web-payment/src/views/payment/index.vue
... ... @@ -14,6 +14,7 @@ import {
14 14 import { ElButton, ElDialog, ElIcon, ElMessage, ElRadio } from 'element-plus';
15 15 import qs from 'qs';
16 16 import VConsole from 'vconsole';
  17 +import wx from 'weixin-js-sdk';
17 18  
18 19 import {
19 20 getOpenId,
... ... @@ -280,12 +281,14 @@ const queryPayment = async () =&gt; {
280 281 payee: orderInfoData.value.mchName,
281 282 };
282 283 const queryString = qs.stringify(params);
283   - console.log(wx);
284   - if (typeof wx !== 'undefined' && wx.miniProgram) {
  284 + console.log('微信sdk', wx);
  285 + if (wx !== undefined && wx.miniProgram) {
285 286 wx.miniProgram.redirectTo({
286 287 url: `/packageA/pages/wxPay/index?${queryString}`,
287 288 });
288 289 loading.value = false;
  290 + } else {
  291 + console.log('wx.miniProgram is not available');
289 292 }
290 293 } catch (error) {
291 294 console.log(error);
... ... @@ -311,7 +314,7 @@ const queryPayment = async () =&gt; {
311 314 const queryString = qs.stringify(pramsData);
312 315  
313 316 // 跳转到微信支付页面
314   - if (typeof wx !== 'undefined' && wx.miniProgram) {
  317 + if (wx !== undefined && wx.miniProgram) {
315 318 wx.miniProgram.navigateTo({
316 319 url: `/packageA/pages/wxPay/index?${queryString}`,
317 320 });
... ...
apps/web-payment/src/views/payment/paySuccess.vue
... ... @@ -3,6 +3,7 @@ import { onMounted, ref } from &#39;vue&#39;;
3 3 import { useRoute } from 'vue-router';
4 4  
5 5 import { ElButton } from 'element-plus';
  6 +import wx from 'weixin-js-sdk';
6 7  
7 8 import EnvironmentDetector from '#/composables/environmentDetector';
8 9  
... ... @@ -19,23 +20,14 @@ const handleBack = () =&gt; {
19 20 if (queryData.value.redirectUrl) {
20 21 window.location.href = queryData.value.redirectUrl;
21 22 } else if (
22   - typeof jWeixin !== 'undefined' &&
23   - jWeixin.miniProgram &&
  23 + wx !== undefined &&
  24 + wx.miniProgram &&
24 25 detector.value?.env.isMiniProgram
25 26 ) {
26   - jWeixin.miniProgram.switchTab({
  27 + wx.miniProgram.switchTab({
27 28 url: `/pages/newhome/newhome`,
28 29 });
29 30 }
30   - // if (
31   - // typeof jWeixin !== 'undefined' &&
32   - // jWeixin.miniProgram &&
33   - // detector.value?.env.isMiniProgram
34   - // ) {
35   - // jWeixin.miniProgram.switchTab({
36   - // url: `/pages/newhome/newhome`,
37   - // });
38   - // }
39 31 };
40 32  
41 33 onMounted(() => {
... ...
pnpm-lock.yaml
... ... @@ -892,6 +892,9 @@ importers:
892 892 vue-router:
893 893 specifier: 'catalog:'
894 894 version: 4.6.3(vue@3.5.24(typescript@5.9.3))
  895 + weixin-js-sdk:
  896 + specifier: ^1.6.5
  897 + version: 1.6.5
895 898 devDependencies:
896 899 unplugin-element-plus:
897 900 specifier: 'catalog:'
... ... @@ -10612,6 +10615,9 @@ packages:
10612 10615 webpack-virtual-modules@0.6.2:
10613 10616 resolution: {integrity: sha512-66/V2i5hQanC51vBQKPH4aI8NMAcBW59FVBs+rC7eGHupMyfn34q7rZIE+ETlJ+XTevqfUhVVBgSUNSW2flEUQ==}
10614 10617  
  10618 + weixin-js-sdk@1.6.5:
  10619 + resolution: {integrity: sha512-Gph1WAWB2YN/lMOFB/ymb+hbU/wYazzJgu6PMMktCy9cSCeW5wA6Zwt0dpahJbJ+RJEwtTv2x9iIu0U4enuVSQ==}
  10620 +
10615 10621 whatwg-encoding@3.1.1:
10616 10622 resolution: {integrity: sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==}
10617 10623 engines: {node: '>=18'}
... ... @@ -20349,6 +20355,8 @@ snapshots:
20349 20355  
20350 20356 webpack-virtual-modules@0.6.2: {}
20351 20357  
  20358 + weixin-js-sdk@1.6.5: {}
  20359 +
20352 20360 whatwg-encoding@3.1.1:
20353 20361 dependencies:
20354 20362 iconv-lite: 0.6.3
... ...