-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
91 lines (80 loc) · 4.64 KB
/
index.html
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function setupWebViewJavascriptBridge(callback) {
if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
window.WVJBCallbacks = [callback];
var WVJBIframe = document.createElement('iframe');
WVJBIframe.style.display = 'none';
WVJBIframe.src = 'https://__bridge_loaded__';
document.documentElement.appendChild(WVJBIframe);
setTimeout(function () { document.documentElement.removeChild(WVJBIframe) }, 0)
}
function GetQueryName(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return decodeURI(r[2]);
}
return null;
}
window.onload = function() {
let issuer = GetQueryName('issuer');
alert(issuer)
}
/*与移动端交互的所有JS方法都要放在此处注册,才能调用通过JS调用移动端或者让移动端调用这里的JS*/
setupWebViewJavascriptBridge(function (bridge) {
var uniqueId = 1
/* Initialize your app here */
/*我们在这注册一个js调用移动端的方法,不带参数,且不用移动端反馈结果给JS/
bridge.registerHandler('setDefaultValue', function () {
document.getElementById('text').innerText = "Default"
})
/*JS给移动端提供公开的API,在移动端可以手动调用JS的这个API。接收ObjC传过来的参数,且可以回调ObjC*/
bridge.registerHandler('RequestOktaLogin', function (data, responseCallback) {
document.getElementById('text').innerText = GetQueryName('issuer');
responseCallback({ 'userId': '123456', 'blog': '标哥的技术博客' })
})
/*JS给移动端提供公开的API,移动端通过注册,就可以在JS端调用此API时,得到回调。移动端可以在处理完成后,反馈给JS */
document.getElementById('btn').onclick = function (e) {
let data = {
"token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjIzMTkwMiwiYWNjb3VudCI6ImZha2VfZmFrZV9mYWtlX2FsZXgubWFsZG9uYWRvQHNhbHRhbGsuY29tIiwidHlwZSI6IlVzZXIiLCJyb2xlcyI6WyJCMkJDdXN0b21lciIsIkN1c3RvbWVyIiwiRHJpdmVyIiwiTG9naXN0aWNzTWFuYWdlciJdLCJpZGVudGlmaWVyIjoiMjMwODE2Njc2NzcwNzciLCJleHAiOjE2OTIzNTIyNDgsImlhdCI6MTY5MjM0NTA0OCwianRpIjoiNjZlZGUyN2UtNmNhNy00NzQ0LWIyMGUtODE2M2VkNTc3NWM5In0=.jR38Nj4-aRBTaEv6LhbE08HrNd2Ux1Estt21Z5SGjGqunupeI0-V_AZeqDT6adH58nFbz0E4P2lzFJdfl2eb0VhVXx9AKR14Idw-vzf9S3bu-HB2jcXyo-znY7DUlHc-eQhadBflj7EfDek9cshAOPdCAOFyMg0A8tjM_EN3odQ=",
"user": {}
}
document.getElementById('text').innerText = GetQueryName('issuer');
console.log('--------');
bridge.callHandler('ResponseOktaLogin', data, function (response) {
alert(response)
document.getElementById('text').innerText = response;
})
}
})
function callFunction() {
setupWebViewJavascriptBridge(function (bridge) {
let data = {
"token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjIzMTkwMiwiYWNjb3VudCI6ImZha2VfZmFrZV9mYWtlX2FsZXgubWFsZG9uYWRvQHNhbHRhbGsuY29tIiwidHlwZSI6IlVzZXIiLCJyb2xlcyI6WyJCMkJDdXN0b21lciIsIkN1c3RvbWVyIiwiRHJpdmVyIiwiTG9naXN0aWNzTWFuYWdlciJdLCJpZGVudGlmaWVyIjoiMjMwODE2Njc2NzcwNzciLCJleHAiOjE2OTIzNTIyNDgsImlhdCI6MTY5MjM0NTA0OCwianRpIjoiNjZlZGUyN2UtNmNhNy00NzQ0LWIyMGUtODE2M2VkNTc3NWM5In0=.jR38Nj4-aRBTaEv6LhbE08HrNd2Ux1Estt21Z5SGjGqunupeI0-V_AZeqDT6adH58nFbz0E4P2lzFJdfl2eb0VhVXx9AKR14Idw-vzf9S3bu-HB2jcXyo-znY7DUlHc-eQhadBflj7EfDek9cshAOPdCAOFyMg0A8tjM_EN3odQ=",
"user": {}
}
bridge.callHandler(
'ResponseOktaLogin',
data,
function(responseData) {
document.getElementById("text").innerHTML = "send get responseData from java, data = " + responseData
}
);
})
}
</script>
</head>
<body>
<p>
<button id="btn" style="background-color: crimson;" onclick="callFunction()">点击</button>
<p id="text"></p>
</p>
</body>
</html>