验证码登录成功

close #118
This commit is contained in:
目棃
2024-07-27 20:41:39 +08:00
parent baf8c3f794
commit 942e63654e
2 changed files with 112 additions and 53 deletions

View File

@@ -13,58 +13,9 @@
</div>
</div>
</div>
<h1>验证码登录测试</h1>
<div class="test-item">
<div class="btn-list">
<button class="test-btn" @click="tryCaptchaLogin()">获取验证码</button>
</div>
</div>
</div>
</template>
<script lang="ts" setup>
import showConfirm from "../../components/func/confirm.js";
import showGeetest from "../../components/func/geetest.js";
import showSnackbar from "../../components/func/snackbar.js";
import Mys from "../../plugins/Mys/index.js";
async function tryCaptchaLogin(): Promise<void> {
const phone = await showConfirm({
mode: "input",
title: "请输入手机号",
text: "+86",
});
if (!phone) return;
const action_type = await tryGetCaptcha(phone);
if (!action_type) return;
const captcha = await showConfirm({
mode: "input",
title: "请输入验证码",
text: "验证码:",
});
if (!captcha) return;
const loginResp = await Mys.User.login(phone, captcha, action_type);
console.log("[loginResp]", loginResp);
}
async function tryGetCaptcha(phone: string, aigis?: string): Promise<string | false> {
const captchaResp = await Mys.User.getCaptcha(phone, aigis);
console.log("[captchaResp]", captchaResp);
if ("retcode" in captchaResp) {
if (!captchaResp.data || captchaResp.data === "") {
showSnackbar({
text: `[${captchaResp.retcode}] ${captchaResp.message}`,
color: "error",
});
return false;
}
const aigis: TGApp.Plugins.Mys.CaptchaLogin.CaptchaAigis = JSON.parse(captchaResp.data);
const resp = await showGeetest(aigis.data);
const aigisStr = btoa(`${aigis.session_id};${JSON.stringify(resp)}`);
return await tryGetCaptcha(phone, aigisStr);
}
return captchaResp.action_type;
}
</script>
<script lang="ts" setup></script>
<style lang="css" scoped>
.test-box {
display: flex;