Commit f304dea745ec599dbb2a4b42b3fa8ca9dae74bac
1 parent
1d350d22
农行支付
Showing
4 changed files
with
53 additions
and
11 deletions
package.json
... | ... | @@ -12,6 +12,7 @@ |
12 | 12 | "dependencies": { |
13 | 13 | "axios": "^0.21.1", |
14 | 14 | "css-loader": "^3.6.0", |
15 | + "js-base64": "^3.6.0", | |
15 | 16 | "less-loader": "^4.1.0", |
16 | 17 | "sass-loader": "^7.3.1", |
17 | 18 | "vue": "^2.5.2", |
... | ... | @@ -30,6 +31,7 @@ |
30 | 31 | "babel-preset-stage-2": "^6.22.0", |
31 | 32 | "chalk": "^2.0.1", |
32 | 33 | "copy-webpack-plugin": "^4.0.1", |
34 | + "crypto-js": "^4.0.0", | |
33 | 35 | "css-loader": "^0.28.0", |
34 | 36 | "extract-text-webpack-plugin": "^3.0.0", |
35 | 37 | "file-loader": "^1.1.4", | ... | ... |
src/components/orderPay.vue
... | ... | @@ -40,6 +40,9 @@ |
40 | 40 | </template> |
41 | 41 | |
42 | 42 | <script> |
43 | +import CryptoJS from '../utils/AES.js' | |
44 | +let Base64 = require('js-base64').Base64 | |
45 | + | |
43 | 46 | import { aliPay, getOpenId, vxPayQuery, bankH5Pay } from '@/api/orderPay/orderPay' |
44 | 47 | |
45 | 48 | export default { |
... | ... | @@ -144,15 +147,16 @@ export default { |
144 | 147 | |
145 | 148 | bankH5Pay(aliParams).then(response => { |
146 | 149 | let res = response.data |
147 | - console.log(response.data) | |
148 | - if (response.code == 0) {// | |
149 | - window.open(response.data) | |
150 | - // document.write(response.data);//打开支付表单 | |
151 | - } else {//其他情况如【该卡号场内已存在】 | |
152 | - alert(response.message) | |
153 | - console.log(response.message); | |
154 | - } | |
155 | - | |
150 | + let _token = res.split('TOKEN=')[1] | |
151 | + console.log(_token) | |
152 | + let _data = 'method=invokePayFromBrowser&tokenID='+_token | |
153 | + let cryData = CryptoJS.encrypt(_data, 'G9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvM3', 'EkpTEA3FbZFGGq8Y') | |
154 | + | |
155 | + let baseCRY = Base64.encode(cryData) | |
156 | + console.log(baseCRY) | |
157 | + window.location.href='bankabc:' + encodeURIComponent('{"method":"invokePayFromBrowser","param":'+baseCRY+'}') | |
158 | + // 即为加密后的数据。其中paramsEncode是需要加密的数据、 | |
159 | + // keyStr是加密时使用的key,与服务端一致、hash是偏移量,是一个随机生成的16位字符串。 | |
156 | 160 | }) |
157 | 161 | } |
158 | 162 | ... | ... |
src/utils/AES.js
0 → 100644
1 | +import CryptoJS from "crypto-js"; | |
2 | + | |
3 | +/** | |
4 | + * | |
5 | + * 第一个参数word是待加密或者解密的字符串; | |
6 | + * 第二个参数keyStr是aes加密需要用到的16位字符串的key; | |
7 | + * 第三个参数是初始化向量 iv。 | |
8 | + */ | |
9 | + | |
10 | +export default { | |
11 | + // 加密 | |
12 | + encrypt(word, keyStr, ivStr) { | |
13 | + const key = CryptoJS.enc.Latin1.parse(keyStr); | |
14 | + const iv = CryptoJS.enc.Latin1.parse(ivStr); | |
15 | + const encoded = CryptoJS.AES.encrypt(word, key, { | |
16 | + iv: iv, | |
17 | + mode: CryptoJS.mode.CBC, | |
18 | + adding: CryptoJS.pad.ZeroPadding | |
19 | + }).toString() | |
20 | + return encoded; | |
21 | + }, | |
22 | + // 解密 | |
23 | + decrypt(word, keyStr, ivStr) { | |
24 | + keyStr = keyStr; | |
25 | + ivStr = ivStr; | |
26 | + var key = CryptoJS.enc.Utf8.parse(keyStr); | |
27 | + let iv = CryptoJS.enc.Utf8.parse(ivStr); | |
28 | + | |
29 | + var decrypt = CryptoJS.AES.decrypt(word, key, { | |
30 | + iv, | |
31 | + mode: CryptoJS.mode.CBC, | |
32 | + padding: CryptoJS.pad.ZeroPadding | |
33 | + }); | |
34 | + return decrypt.toString(CryptoJS.enc.Utf8); | |
35 | + } | |
36 | +}; | ... | ... |
src/utils/utils.js
... | ... | @@ -79,7 +79,7 @@ export default { |
79 | 79 | return '微信' |
80 | 80 | } else if (/AlipayClient/.test(window.navigator.userAgent)) { |
81 | 81 | console.log("支付宝客户端"); |
82 | - return '农行' | |
82 | + return '支付宝' | |
83 | 83 | } else if (/BankabciPhone/.test(window.navigator.userAgent)) { |
84 | 84 | console.log("农行客户端"); |
85 | 85 | return '农行' |
... | ... | @@ -88,7 +88,7 @@ export default { |
88 | 88 | return '农行' |
89 | 89 | }else { |
90 | 90 | console.log("其他浏览器"); |
91 | - return '农行' | |
91 | + return '支付宝' | |
92 | 92 | } |
93 | 93 | }, |
94 | 94 | // 0eca8f5373ca4866aec2f8e9d9367104 老的id | ... | ... |