Commit 607807d2997f00455827215cf1390c9e5904b811

Authored by tianwu
1 parent 62689239

替换weixinjssdk

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