App-Android(使用App+htnl5框架,解决消息推送兼容SignalR问题)
loulijun2021
2022-10-19 d75b0b71c2feed580bf765c0d6007b3c1f17ca74
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="utf-8"/>
        <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
        <meta name="HandheldFriendly" content="true"/>
        <!--<meta name="MobileOptimized" content="320"/>-->
        <title>Hello H5+</title>
        <script type="text/javascript" src="../js/common.js"></script>
        <script type="text/javascript">
var auths={};
function plusReady(){
    // 获取登录认证通道
    plus.oauth.getServices(function(services){
        var content=document.getElementById('dcontent');
        var info=document.getElementById("info");
        var txt="登录认证通道信息:";
        for(var i in services){
            var service=services[i];
            console.log(service.id+": "+service.authResult+", "+service.userInfo);
            auths[service.id]=service;
            txt += "id:"+service.id+", ";
            txt += "description:"+service.description+", ";
            var de=document.createElement('div');
            de.setAttribute('class','button');
            de.setAttribute('onclick','login(this.id)');
            de.id=service.id;
            de.innerText=service.description+"登录";
            oauth.appendChild(de);
        }
        info.innerText=txt;
    },function(e){
        outLine("获取登录认证失败:"+e.message);
    });
}
document.addEventListener('plusready',plusReady,false);
// 登录认证
function login(id){
    outSet("----- 登录认证 -----");
    var auth=auths[id];
    if(auth){
        var w=null;
        if(plus.os.name=="Android"){
            w=plus.nativeUI.showWaiting();
        }
        document.addEventListener("pause",function(){
            setTimeout(function(){
                w&&w.close();w=null;
            },2000);
        }, false );
        auth.login(function(){
            w&&w.close();w=null;
            outLine("登录认证成功:");
            outLine(JSON.stringify(auth.authResult));
            userinfo(auth);
        },function(e){
            w&&w.close();w=null;
            outLine("登录认证失败:");
            outLine("["+e.code+"]:"+e.message);
            plus.nativeUI.alert("详情错误信息请参考授权登录(OAuth)规范文档:http://www.html5plus.org/#specification#/specification/OAuth.html",null,"登录失败["+e.code+"]:"+e.message);
        });
    }else{
        outLine("无效的登录认证通道!");
        plus.nativeUI.alert("无效的登录认证通道!",null,"登录");
    }
}
// 获取用户信息
function userinfo(a){
    outLine("----- 获取用户信息 -----");
    a.getUserInfo(function(){
        outLine("获取用户信息成功:");
        outLine(JSON.stringify(a.userInfo));
        var nickname=a.userInfo.nickname||a.userInfo.name||a.userInfo.miliaoNick;
        plus.nativeUI.alert("欢迎“"+nickname+"”登录!");
    },function(e){
        outLine("获取用户信息失败:");
        outLine("["+e.code+"]:"+e.message);
        plus.nativeUI.alert("获取用户信息失败!",null,"登录");
    });
}
// 注销登录
function logoutAll(){
    outSet("----- 注销登录认证 -----");
    for(var i in auths){
        logout(auths[i]);
    }
}
function logout(auth){
    auth.logout(function(){
        outLine("注销\""+auth.description+"\"成功");
    },function(e){
        outLine("注销\""+auth.description+"\"失败:"+e.message);
    });
}
        </script>
        <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8"/>
        <style type="text/css">
#total{
    -webkit-user-select:text;
    text-align:right;
    padding:0 1em;
    border: 0px;
    border-bottom:1px solid #ECB100;
    border-radius: 0;
    font-size:16px;
    width:30%;
    outline:none;
}
        </style>
    </head>
    <body>
        <br/>
        <p id="info" style="padding: 0 1em;text-align:left;">登录认证通道信息:</p>
        <div style="padding: 0.5em 1em;"><hr color="#EEE"/></div>
        <br/>
        <div id="oauth"></div>
        <br/>
        <div class="button button-waring" onclick="logoutAll()">注销登录</div>
        <div id="outpos"/>
        <div id="output">
OAuth模块管理客户端的用户授权登录验证功能,允许应用访问第三方平台的资源。
        </div>
    </body>
</html>