8
8
<template slot="append">%</template >
9
9
</el-input >
10
10
</el-form-item >
11
- <el-form-item label-width =" 180px" label =" 公众号APPID " prop =" weChatConfig.appId" >
12
- <el-input v-model =" form.weChatConfig.appId" placeholder =" 请输入公众号APPID " clearable :style =" {width: '100%'}" >
11
+ <el-form-item label-width =" 180px" label =" 公众号 APPID " prop =" weChatConfig.appId" >
12
+ <el-input v-model =" form.weChatConfig.appId" placeholder =" 请输入公众号 APPID " clearable :style =" {width: '100%'}" >
13
13
</el-input >
14
14
</el-form-item >
15
15
<el-form-item label-width =" 180px" label =" 商户号" prop =" weChatConfig.mchId" >
29
29
</el-radio >
30
30
</el-radio-group >
31
31
</el-form-item >
32
- <el-form-item label-width =" 180px" label =" 商户密钥" prop =" weChatConfig.mchKey"
33
- v-if =" form.weChatConfig.apiVersion === 'v2'" >
34
- <el-input v-model =" form.weChatConfig.mchKey" placeholder =" 请输入商户密钥" clearable
35
- :style =" {width: '100%'}" type =" textarea" :autosize =" {minRows: 8, maxRows: 8}" ></el-input >
36
- </el-form-item >
32
+ <div v-if =" form.weChatConfig.apiVersion === 'v2'" >
33
+ <el-form-item label-width =" 180px" label =" 商户密钥" prop =" weChatConfig.mchKey" >
34
+ <el-input v-model =" form.weChatConfig.mchKey" placeholder =" 请输入商户密钥" clearable
35
+ :style =" {width: '100%'}" type =" textarea" :autosize =" {minRows: 8, maxRows: 8}" ></el-input >
36
+ </el-form-item >
37
+ <el-form-item label-width =" 180px" label =" apiclient_cert.p12 证书" prop =" weChatConfig.keyContent" >
38
+ <el-input v-model =" form.weChatConfig.keyContent" type =" textarea"
39
+ placeholder =" 请上传 apiclient_cert.p12 证书"
40
+ readonly :autosize =" {minRows: 8, maxRows: 8}" :style =" {width: '100%'}" ></el-input >
41
+ </el-form-item >
42
+ <el-form-item label-width =" 180px" label =" " >
43
+ <el-upload :limit =" 1" accept =" .p12" action =" "
44
+ :before-upload =" p12FileBeforeUpload"
45
+ :http-request =" keyContentUpload" >
46
+ <el-button size =" small" type =" primary" icon =" el-icon-upload" >点击上传</el-button >
47
+ </el-upload >
48
+ </el-form-item >
49
+ </div >
37
50
<div v-if =" form.weChatConfig.apiVersion === 'v3'" >
38
- <el-form-item label-width =" 180px" label =" API V3密钥 " prop =" weChatConfig.apiV3Key" >
39
- <el-input v-model =" form.weChatConfig.apiV3Key" placeholder =" 请输入API V3密钥 " clearable
51
+ <el-form-item label-width =" 180px" label =" API V3 密钥 " prop =" weChatConfig.apiV3Key" >
52
+ <el-input v-model =" form.weChatConfig.apiV3Key" placeholder =" 请输入 API V3 密钥 " clearable
40
53
:style =" {width: '100%'}" type =" textarea" :autosize =" {minRows: 8, maxRows: 8}" ></el-input >
41
54
</el-form-item >
42
- <el-form-item label-width =" 180px" label =" apiclient_key.perm证书 " prop =" weChatConfig.privateKeyContent" >
55
+ <el-form-item label-width =" 180px" label =" apiclient_key.perm 证书 " prop =" weChatConfig.privateKeyContent" >
43
56
<el-input v-model =" form.weChatConfig.privateKeyContent" type =" textarea"
44
- placeholder =" 请上传apiclient_key.perm证书 "
57
+ placeholder =" 请上传 apiclient_key.perm 证书 "
45
58
readonly :autosize =" {minRows: 8, maxRows: 8}" :style =" {width: '100%'}" ></el-input >
46
59
</el-form-item >
47
60
<el-form-item label-width =" 180px" label =" " prop =" privateKeyContentFile" >
48
61
<el-upload ref =" privateKeyContentFile"
49
62
:limit =" 1"
50
- :accept =" fileAccept"
51
- :headers =" header"
63
+ accept =" .pem"
52
64
action =" "
53
65
:before-upload =" pemFileBeforeUpload"
54
- :http-request =" privateKeyUpload "
66
+ :http-request =" privateKeyContentUpload "
55
67
>
56
68
<el-button size =" small" type =" primary" icon =" el-icon-upload" >点击上传</el-button >
57
69
</el-upload >
64
76
<el-form-item label-width =" 180px" label =" " prop =" privateCertContentFile" >
65
77
<el-upload ref =" privateCertContentFile"
66
78
:limit =" 1"
67
- :accept =" fileAccept"
68
- :headers =" header"
79
+ accept =" .pem"
69
80
action =" "
70
81
:before-upload =" pemFileBeforeUpload"
71
- :http-request =" privateCertUpload "
82
+ :http-request =" privateCertContentUpload "
72
83
>
73
84
<el-button size =" small" type =" primary" icon =" el-icon-upload" >点击上传</el-button >
74
85
</el-upload >
75
86
</el-form-item >
76
87
</div >
77
88
<el-form-item label-width =" 180px" label =" 备注" prop =" remark" >
78
- <el-input v-model =" form.remark" :style =" {width: '100%'}" ></ el-input >
89
+ <el-input v-model =" form.remark" :style =" {width: '100%'}" / >
79
90
</el-form-item >
80
91
</el-form >
81
92
<div slot =" footer" class =" dialog-footer" >
@@ -100,6 +111,7 @@ const defaultForm = {
100
111
mchId: ' ' ,
101
112
apiVersion: ' ' ,
102
113
mchKey: ' ' ,
114
+ keyContent: ' ' ,
103
115
privateKeyContent: ' ' ,
104
116
privateCertContent: ' ' ,
105
117
apiV3Key: ' ' ,
@@ -159,27 +171,27 @@ export default {
159
171
message: ' 请输入商户密钥' ,
160
172
trigger: ' blur'
161
173
}],
174
+ ' weChatConfig.keyContent' : [{
175
+ required: true ,
176
+ message: ' 请上传 apiclient_cert.p12 证书' ,
177
+ trigger: ' blur'
178
+ }],
162
179
' weChatConfig.privateKeyContent' : [{
163
180
required: true ,
164
- message: ' 请上传apiclient_key.perm证书 ' ,
181
+ message: ' 请上传 apiclient_key.perm 证书 ' ,
165
182
trigger: ' blur'
166
183
}],
167
184
' weChatConfig.privateCertContent' : [{
168
185
required: true ,
169
- message: ' 请上传apiclient_cert.perm证书 ' ,
186
+ message: ' 请上传 apiclient_cert.perm证 书 ' ,
170
187
trigger: ' blur'
171
188
}],
172
189
' weChatConfig.apiV3Key' : [{
173
190
required: true ,
174
- message: ' 请上传apiV3密钥值 ' ,
191
+ message: ' 请上传 api V3 密钥值 ' ,
175
192
trigger: ' blur'
176
193
}],
177
194
},
178
- // 文件上传的header
179
- header: {
180
- " Authorization" : null
181
- },
182
- fileAccept: " .pem" ,
183
195
// 渠道状态 数据字典
184
196
statusDictDatas: getDictDatas (DICT_TYPE .COMMON_STATUS ),
185
197
versionDictDatas: getDictDatas (DICT_TYPE .PAY_CHANNEL_WECHAT_VERSION ),
@@ -218,6 +230,7 @@ export default {
218
230
this .form .weChatConfig .apiVersion = config .apiVersion ;
219
231
this .form .weChatConfig .mchId = config .mchId ;
220
232
this .form .weChatConfig .mchKey = config .mchKey ;
233
+ this .form .weChatConfig .keyContent = config .keyContent ;
221
234
this .form .weChatConfig .privateKeyContent = config .privateKeyContent ;
222
235
this .form .weChatConfig .privateCertContent = config .privateCertContent ;
223
236
this .form .weChatConfig .apiV3Key = config .apiV3Key ;
@@ -241,7 +254,6 @@ export default {
241
254
this .$modal .msgSuccess (" 修改成功" );
242
255
this .close ();
243
256
}
244
-
245
257
})
246
258
} else {
247
259
@@ -255,10 +267,14 @@ export default {
255
267
}
256
268
});
257
269
},
258
- pemFileBeforeUpload (file ) {
270
+ /**
271
+ * apiclient_cert.p12、apiclient_cert.pem、apiclient_key.pem 上传前的校验
272
+ */
273
+ fileBeforeUpload (file , fileAccept ) {
259
274
let format = ' .' + file .name .split (" ." )[1 ];
260
- if (format !== this .fileAccept ) {
261
- this .$message .error (' 请上传指定格式"' + this .fileAccept + ' "文件' );
275
+ if (format !== fileAccept) {
276
+ debugger
277
+ this .$message .error (' 请上传指定格式"' + fileAccept + ' "文件' );
262
278
return false ;
263
279
}
264
280
let isRightSize = file .size / 1024 / 1024 < 2
@@ -267,19 +283,41 @@ export default {
267
283
}
268
284
return isRightSize
269
285
},
270
- privateKeyUpload (event ) {
286
+ p12FileBeforeUpload (file ) {
287
+ this .fileBeforeUpload (file, ' .p12' )
288
+ },
289
+ pemFileBeforeUpload (file ) {
290
+ this .fileBeforeUpload (file, ' .pem' )
291
+ },
292
+ /**
293
+ * 读取 apiclient_key.pem 到 privateKeyContent 字段
294
+ */
295
+ privateKeyContentUpload (event ) {
271
296
const readFile = new FileReader ()
272
297
readFile .onload = (e ) => {
273
298
this .form .weChatConfig .privateKeyContent = e .target .result
274
299
}
275
300
readFile .readAsText (event .file );
276
301
},
277
- privateCertUpload (event ) {
302
+ /**
303
+ * 读取 apiclient_cert.pem 到 privateCertContent 字段
304
+ */
305
+ privateCertContentUpload (event ) {
278
306
const readFile = new FileReader ()
279
307
readFile .onload = (e ) => {
280
308
this .form .weChatConfig .privateCertContent = e .target .result
281
309
}
282
310
readFile .readAsText (event .file );
311
+ },
312
+ /**
313
+ * 读取 apiclient_cert.p12 到 keyContent 字段
314
+ */
315
+ keyContentUpload (event ) {
316
+ const readFile = new FileReader ()
317
+ readFile .onload = (e ) => {
318
+ this .form .weChatConfig .keyContent = e .target .result .split (' ,' )[1 ]
319
+ }
320
+ readFile .readAsDataURL (event .file ); // 读成 base64
283
321
}
284
322
}
285
323
}
0 commit comments