验证码
# 验证码
# 图片验证码
# 后台 ArrayBuffer 转 Base64
transformArrayBufferToBase64(buffer) {
return (
"data:image/png;base64," +
btoa(
new Uint8Array(buffer).reduce(
(data, byte) => data + String.fromCharCode(byte),
""
)
)
);
}
// 后台api接口
getGraphical({ randomStr: Math.random().toString().slice(-6) }).then((res) => {
this.transformArrayBufferToBase64(res.data)
});
/**
* 获取图形验证码接口
*/
export function getGraphical(data) {
return axios({
url: `${PREFIX}/sms/getPicValidateCode`,
method: 'POST',
responseType: 'arraybuffer',
data,
});
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
更新时间: 8/31/2021, 6:18:50 PM