提交 18b66357 编写于 作者: huangwensu's avatar huangwensu

获取短信验证码加密

上级 549a95bb
此差异已折叠。
......@@ -14,13 +14,14 @@
"dependencies": {
"cookie-universal": "^2.0.16",
"cross-env": "^5.2.0",
"js-base64": "^2.5.1",
"jsencrypt": "^3.0.0-rc.1",
"koa": "^2.6.2",
"nuxt": "^2.0.0",
"pica-call-app": "^1.0.42",
"vant": "^2.0.9",
"vconsole": "^3.3.4",
"web-buried-point": "^v2.1.0",
"pica-call-app": "^1.0.42",
"js-base64": "^2.5.1"
"web-buried-point": "^v2.1.0"
},
"devDependencies": {
"@nuxtjs/axios": "^5.5.4",
......
......@@ -26,7 +26,8 @@
</div>
</template>
<script>
import { getCaptchaGet, getAuthCode, pointResult } from '@/service';
import { getCaptchaGet, getAuthCode, pointResult, getPublicKey } from '@/service';
import { CryptoJS } from '../../utils/aes';
const TIMEALL = 60000; // 倒计时常量 60 秒
export default {
data() {
......@@ -46,7 +47,8 @@ export default {
captchaImg: '',
captchaToken: '',
flag: 0,
time: TIMEALL
time: TIMEALL,
pubKey: ''
}
},
created() {
......@@ -59,8 +61,17 @@ export default {
this.name = this.$route.query.name;
this.avatarl = this.$route.query.avatar;
this.getCaptchaGet();
this.getPublicKey();
},
methods: {
// 获取公钥
getPublicKey() {
getPublicKey().then(res => {
if(res.code == '000000') {
this.pubKey = res.data;
}
})
},
// 获取图形验证码
getCaptchaGet() {
getCaptchaGet().then(res => {
......@@ -94,8 +105,9 @@ export default {
this.$toast('请输入图形验证码');
return;
}
getAuthCode({mobilePhone, flag, captchaToken, captchaAnswer}).then(res=>{
let data = {mobile: mobilePhone, flag, captchaToken, captchaAnswer};
let req = this.formatContent(JSON.stringify(data), this.pubKey);
getAuthCode(req).then(res=>{
// 发送成功
if(res.code === '000000'){
this.notSend = false;
......@@ -105,6 +117,38 @@ export default {
}
})
},
formatContent(content, pubKey) { // obj为具体的json传参
let aesKey = this.getAesKey(16);
let params = {
key: '',
content: ''
};
params.content = this.aesEncrypt(content, aesKey);
params.key = this.rsaEncrypt(aesKey, pubKey);
return params;
},
aesEncrypt(content, aesKey) {
let sKey = CryptoJS.enc.Utf8.parse(aesKey);
let sContent = CryptoJS.enc.Utf8.parse(content);
let encrypted = CryptoJS.AES.encrypt(sContent, sKey, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
return encrypted.toString();
},
rsaEncrypt(aesKey, pubKey){
let _encrypt = new JSEncrypt();
let boss_public_key = pubKey;
_encrypt.setPublicKey(boss_public_key);
let encrypted = _encrypt.encrypt(aesKey);
return encrypted;
},
getAesKey(len) {
let aesKey = "";
let strList = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
let strLen = strList.length;
for(let i=0; i < len; i++){
aesKey += strList.charAt( Math.floor( Math.random()*strLen ) );
};
return aesKey;
},
// 倒计时结束
finishCount(){
this.time = TIMEALL;
......
......@@ -4,6 +4,7 @@ import rocNative from '@/utils/jsbridge';
import WebBuriedPoint, { sendBuriedData } from 'web-buried-point';
import { callApp } from 'pica-call-app'; // H5唤起APP组件
import VConsole from 'vconsole/dist/vconsole.min.js';
import jsencrypt from 'jsencrypt';
import {
CountDown,
......@@ -38,6 +39,7 @@ Vue.prototype.$cookies = cookies;
Vue.prototype.$rocNative = new rocNative();
Vue.prototype.$sendBuriedData = sendBuriedData;
Vue.prototype.$callApp = callApp;
Vue.prototype.$jsencrypt = jsencrypt;
// Vue.use(PicaCallApp);
Vue.use(CountDown).use(Field).use(Cell).use(CellGroup).use(Button).use(Popup).use(Checkbox).use(CheckboxGroup).use(RadioGroup).use(Radio).use(Progress).use(ImagePreview).use(Uploader).use(Overlay).use(Loading);
......
......@@ -74,14 +74,20 @@ export const getCaptchaGet = async () => {
})
}
// 获取公钥
export const getPublicKey = async () => {
return request({
url: `account/cipher/key`,
method: 'get'
})
}
// 获取短信验证码
export const getAuthCode = ({ mobilePhone, flag, captchaToken, captchaAnswer }) => {
export const getAuthCode = (data) => {
return request({
url: `account/account/authCode`,
method: 'get',
params: {
mobilePhone, flag, captchaToken, captchaAnswer
},
method: 'post',
data: data,
})
}
......
此差异已折叠。
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册