Skip to content

Commit

Permalink
🧪 -3001,参数错误☹
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Jul 25, 2024
1 parent 20ad79f commit 2896209
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
44 changes: 43 additions & 1 deletion src/pages/common/Test.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,46 @@
</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></script>
<script lang="ts" setup>
import showConfirm from "../../components/func/confirm.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 captchaResp = await Mys.User.getCaptcha(phone);
console.log("[captchaResp]", captchaResp);
if ("retcode" in captchaResp) {
showSnackbar({
text: `[${captchaResp.retcode}] ${captchaResp.message}`,
color: "error",
});
return;
}
const action_type = captchaResp.action_type;
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);
}
</script>
<style lang="css" scoped>
.test-box {
display: flex;
Expand All @@ -36,6 +73,11 @@
}
.test-btn {
display: flex;
align-items: center;
justify-content: center;
padding: 10px;
border-radius: 5px;
background: var(--tgc-btn-1);
color: var(--btn-text);
}
Expand Down
26 changes: 17 additions & 9 deletions src/plugins/Mys/request/doCaptchaLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import { getDeviceInfo } from "../../../utils/toolFunc.js";
import TGConstant from "../../../web/constant/TGConstant.js";

const PUB_KEY = `-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDvekdPMHN3AYhm/vktJT+YJr7cI5DcsNK
qdsx5DZX0gDuWFuIjzdwButrIYPNmRJ1G8ybDIF7oDW2eEpm5sMbL9zs9ExXCdvqrn51qELb
qj0XxtMTIpaCHFSI50PfPpTFV9Xt/hmyVwokoOXFlAEgCn+QCgGs52bFoYMtyi+xEQIDAQAB
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDvekdPMHN3AYhm/vktJT+YJr7cI5DcsNKqdsx5DZX0gDuWFuIjzdwButrIYPNmRJ1G8ybDIF7oDW2eEpm5sMbL9zs
9ExXCdvqrn51qELbqj0XxtMTIpaCHFSI50PfPpTFV9Xt/hmyVwokoOXFlAEgCn+Q
CgGs52bFoYMtyi+xEQIDAQAB
-----END PUBLIC KEY-----`;
const EncryptAreaCode = rsaEncrypt("+86");

/**
* @description rsa 加密
Expand Down Expand Up @@ -43,7 +42,7 @@ export async function getCaptcha(
const device_name = getDeviceInfo("device_name");
const device_id = getDeviceInfo("device_id");
const device_model = getDeviceInfo("product");
const body = { area: EncryptAreaCode, phone: rsaEncrypt(phone) };
const body = { area_code: rsaEncrypt("+86"), mobile: rsaEncrypt(phone) };
const header = {
"x-rpc-aigis": "",
"x-rpc-app_version": TGConstant.BBS.VERSION,
Expand All @@ -53,7 +52,13 @@ export async function getCaptcha(
"x-rpc-device_name": device_name,
"x-rpc-device_id": device_id,
"x-rpc-device_model": device_model,
"user-agent": TGConstant.BBS.UA_MOBILE,
"content-type": "application/json",
referer: "https://user.miyoushe.com/",
"x-rpc-game_biz": TGConstant.Utils.GAME_BIZ,
};
console.log("getCaptcha header: ", header);
console.log("getCaptcha body: ", body);
const resp = await TGHttp<
TGApp.Plugins.Mys.CaptchaLogin.CaptchaResponse | TGApp.BBS.Response.Base
>(url, {
Expand All @@ -69,23 +74,23 @@ export async function getCaptcha(
* @description 通过短信验证码登录
* @since Beta v0.5.1
* @param {string} phone - 手机号
* @param {string} action_type - 操作类型
* @param {string} captcha - 验证码
* @param {string} action_type - 操作类型
* @returns {Promise<TGApp.Plugins.Mys.CaptchaLogin.LoginData | TGApp.BBS.Response.Base>}
*/
export async function doCaptchaLogin(
phone: string,
action_type: string,
captcha: string,
action_type: string,
): Promise<TGApp.Plugins.Mys.CaptchaLogin.LoginData | TGApp.BBS.Response.Base> {
const url = "https://passport-api.mihoyo.com/account/ma-cn-passport/app/loginByMobileCaptcha";
const device_fp = getDeviceInfo("device_fp");
const device_name = getDeviceInfo("device_name");
const device_id = getDeviceInfo("device_id");
const device_model = getDeviceInfo("product");
const body = {
area: EncryptAreaCode,
phone: rsaEncrypt(phone),
area_code: rsaEncrypt("+86"),
mobile: rsaEncrypt(phone),
action_type,
captcha,
};
Expand All @@ -98,7 +103,10 @@ export async function doCaptchaLogin(
"x-rpc-device_name": device_name,
"x-rpc-device_id": device_id,
"x-rpc-device_model": device_model,
"user-agent": TGConstant.BBS.UA_MOBILE,
};
console.log("doCaptchaLogin header: ", header);
console.log("doCaptchaLogin body: ", body);
const resp = await TGHttp<TGApp.Plugins.Mys.CaptchaLogin.LoginResponse | TGApp.BBS.Response.Base>(
url,
{
Expand Down

0 comments on commit 2896209

Please sign in to comment.