123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <html>
- <head>
- <title></title>
- <script src="AFrontEnd/js/jquery/jquery-1.8.3.min.js"></script>
- <script src="apiurljs.js"></script>
- <script type="text/javascript">
- var challenge = "";
- function test() {
- $.ajax({
- type: "post",
- url: apiurljs.login + "g2app/certification/GeneratorChallenge",
- dataType: "json",
- ContentType: 'application/x-www-form-urlencoded',
- success: function (res) {
- if (res.success) {
- challenge = res.data;
- WebSocketTest()
- }
- },
- })
- }
- function WebSocketTest() {
- if ("WebSocket" in window) {
- //alert("WebSocket is supported by your Browser!");
- var ws = new WebSocket("ws://127.0.0.1:30318/");
- ws.onopen = function () {
- var str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><getsignandtokenreq version=\"1\"><challenge>" + challenge + "</challenge></getsignandtokenreq>";
- ws.send(str);
- };
- ws.onmessage = function (evt) {
- $.ajax({
- type: "post",
- url: apiurljs.login + "g2app/certification/VerifyIdentityTicket",
- dataType: "json",
- data: {
- challenge: challenge,
- tokeninfo: $(evt.data).find("tokeninfo").text()
- },
- ContentType: 'application/x-www-form-urlencoded',
- success: function (res) {
- if (res.data.SUCCESS) {
- $.ajax({
- //url: 'js/login/userData.txt',
- url: apiurljs.login + "connect/token",
- type: 'post',
- dataType: 'json',
- ContentType: 'application/x-www-form-urlencoded',
- data: {
- client_id: "androidclient",
- grant_type: "password",
- scope: "openid profile email RefineAPI",
- username: res.data.UINPUTNAME,
- password: res.data.PASSWORD
- },
- success: function (res) {
- console.log(res);
- var postAccessToken = res.access_token;
- localStorage.setItem("GlWorkPlatform-AccessToken", postAccessToken)
- var setArray = res.access_token.split(".");
- var base64 = new Base64(); //声明base解码和编码类
- let getBase = base64.decode(setArray[1]);
- getBase = getBase.substring(0, getBase.lastIndexOf("}") + 1);
- getBaseSet = JSON.parse(getBase);
- let get_userid = getBaseSet.sub;
- console.log(get_userid);
- /////存入userid、及英文名
- $.cookie("GlWorkPlatform-userid", get_userid, { path: '/', expires: 1 });
- $.cookie("GlWorkPlatform-username", get_userName, { path: '/', expires: 1 });
- $.cookie("CrossPage-ctime", sp.getLocalDate1(), { path: '/', expires: 1 });
- //对密码进行加密
- if (get_ischeck) {
- //对密码进行加密
- var encode_user = base64.encode(get_userName);
- var encode_pwd = base64.encode(get_password);
- localStorage.setItem("GlWorkPlatform-user", encode_user);
- localStorage.setItem("GlWorkPlatform-pwd", encode_pwd);
- localStorage.setItem("GlWorkPlatform-ischecked", get_ischeck);
- } else {
- localStorage.removeItem("GlWorkPlatform-user");
- localStorage.removeItem("GlWorkPlatform-pwd");
- localStorage.removeItem("GlWorkPlatform-ischecked");
- }
- $.ajax({
- url: apiurljs.login + "api/User/UserInfo",
- type: 'post',
- dataType: 'json',
- ContentType: 'application/json',
- headers: { Authorization: "Bearer " + postAccessToken }, ////请求头headers
- success: function (res2) {
- ///中文名
- $.cookie("GlWorkPlatform-chineseName", res2.data.ushowname, { path: '/', expires: 1 });
- //延时进行跳转
- timeout = setTimeout(function () {
- window.location.href = "index.html";
- sessionStorage.setItem("GlWorkPlatform-LoginFrom", "GlWorkPlatform-LoginHtml");
- }, 500);
- }, error: function (XMLHttpRequest, textStatus, errorThrown) {
- sp.dialog(JSON.stringify(errorThrown));
- }
- });
- }, error: function (XMLHttpRequest, textStatus, errorThrown) {
- sp.dialog("登录失败,用户名号或密码输入错误");
- }
- });
- }
- },
- })
- };
- ws.onclose = function () {
- console.log("Connection is closed...");
- };
- }
- else {
- var d = document.createElement('div');
- d.textContent == "" ? d.textContent = '\n浏览器不支持websocket' : d.innerText = '\n浏览器不支持websocket';
- document.getElementById("showResult").appendChild(d);
- }
- }
- </script>
- </head>
- <body>
- <button onclick="test(); WebSocketTest()">测试</button>
- <div id="result">
- <p>
- 测试结果:
- <div id="showResult">
- </div>
- </div>
- </body>
- </html>
|