60%
This commit is contained in:
@@ -135,7 +135,7 @@ export default {
|
||||
return {
|
||||
generation: 0,
|
||||
tac: null,
|
||||
context: null,
|
||||
requestContext: null,
|
||||
challenge: null,
|
||||
activeXhr: null,
|
||||
fatalSent: false,
|
||||
@@ -148,7 +148,7 @@ export default {
|
||||
this.generation += 1;
|
||||
const generation = this.generation;
|
||||
this.destroyTac();
|
||||
this.context = nextContext || null;
|
||||
this.requestContext = nextContext || null;
|
||||
this.challenge = null;
|
||||
this.fatalSent = false;
|
||||
this.completionSent = false;
|
||||
@@ -160,10 +160,10 @@ export default {
|
||||
loadScript(TAC_SCRIPT_URL, () => Boolean(window.TAC && window.CaptchaConfig)),
|
||||
]);
|
||||
await loadScript(TAC_ADAPTER_URL, () => Boolean(window.JiapuTacAdapter));
|
||||
if (generation !== this.generation || !this.context || this.context.visible !== true) return;
|
||||
if (generation !== this.generation || !this.requestContext || this.requestContext.visible !== true) return;
|
||||
this.createTac();
|
||||
} catch (error) {
|
||||
if (generation !== this.generation || !this.context || this.context.visible !== true) return;
|
||||
if (generation !== this.generation || !this.requestContext || this.requestContext.visible !== true) return;
|
||||
this.notifyFatal(error);
|
||||
}
|
||||
},
|
||||
@@ -173,17 +173,17 @@ export default {
|
||||
}
|
||||
this.completionSent = false;
|
||||
const generation = this.generation;
|
||||
const requestContext = this.context;
|
||||
const requestContext = this.requestContext;
|
||||
const isCurrent = () =>
|
||||
generation === this.generation &&
|
||||
this.context === requestContext &&
|
||||
this.requestContext === requestContext &&
|
||||
requestContext.visible === true;
|
||||
const config = new window.CaptchaConfig({
|
||||
bindEl: "#jiapu-tac-host",
|
||||
requestCaptchaDataUrl: this.context.challengeUrl,
|
||||
validCaptchaUrl: this.context.verifyUrl,
|
||||
requestCaptchaDataUrl: this.requestContext.challengeUrl,
|
||||
validCaptchaUrl: this.requestContext.verifyUrl,
|
||||
requestHeaders: {
|
||||
clientid: this.context.clientId,
|
||||
clientid: this.requestContext.clientId,
|
||||
},
|
||||
validSuccess: (response, captcha, tac) => {
|
||||
if (!isCurrent() || this.completionSent) return;
|
||||
@@ -238,17 +238,17 @@ export default {
|
||||
beforeRequest(type, request) {
|
||||
if (type === "requestCaptchaData") {
|
||||
request.data = {
|
||||
tenantId: this.context.tenantId,
|
||||
clientId: this.context.clientId,
|
||||
sceneCode: this.context.sceneCode,
|
||||
subject: this.context.subject,
|
||||
tenantId: this.requestContext.tenantId,
|
||||
clientId: this.requestContext.clientId,
|
||||
sceneCode: this.requestContext.sceneCode,
|
||||
subject: this.requestContext.subject,
|
||||
};
|
||||
return true;
|
||||
}
|
||||
if (type === "validCaptcha") {
|
||||
request.data = window.JiapuTacAdapter.buildVerifyBody(
|
||||
request.data,
|
||||
this.context,
|
||||
this.requestContext,
|
||||
this.challenge,
|
||||
);
|
||||
}
|
||||
@@ -257,7 +257,7 @@ export default {
|
||||
afterRequest(type, response) {
|
||||
try {
|
||||
if (type === "requestCaptchaData") {
|
||||
const mapped = window.JiapuTacAdapter.normalizeChallengeResponse(response, this.context);
|
||||
const mapped = window.JiapuTacAdapter.normalizeChallengeResponse(response, this.requestContext);
|
||||
this.challenge = mapped.challenge;
|
||||
this.replaceResponse(response, mapped.sdkResponse);
|
||||
} else if (type === "validCaptcha") {
|
||||
@@ -326,7 +326,7 @@ export default {
|
||||
if (this.fatalSent) return;
|
||||
this.fatalSent = true;
|
||||
this.$ownerInstance.callMethod("handleTacError", {
|
||||
requestId: this.context && this.context.requestId,
|
||||
requestId: this.requestContext && this.requestContext.requestId,
|
||||
message: (error && error.message) || "安全验证暂不可用",
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user