怎么做网站调研,商城网站建设运营协议书,淄博网站,wordpress+编辑器+空格实现原理#xff1a;
1、web登录页面#xff0c;利用jquery.qrcode展示一个随机生成的登录码的二维码#xff1b;
2、手机App扫描二维码取得登录码#xff1b;
3、手机App将本地用户id登录码通过api提交服务器#xff1b;
4、服务器api#xff0c;收到手机App请求
1、web登录页面利用jquery.qrcode展示一个随机生成的登录码的二维码
2、手机App扫描二维码取得登录码
3、手机App将本地用户id登录码通过api提交服务器
4、服务器api收到手机App请求根据用户id登录码修改用户信息同时将用户id登录码广播
5、web登录页面收到用户id登录码先本地验证登录码是否一致然后向服务器验证用户id登录码验证成功跳转到指定页面。
6、完成扫码登录。 模拟web登录页面代码
!doctype html
html langenheadmeta charsetUTF-8meta nameGenerator contentEditPlus®meta nameAuthor contentmeta nameKeywords contentmeta nameDescription contenttitle扫码登录测试/title/headbodyscript srchttp://***/Scripts/jquery-1.10.2.min.js/scriptscript srchttp://***/Scripts/jquery.signalR-2.4.1.min.js/scriptscript srchttp://***/Scripts/jquery.qrcode.min.js/scriptscript srchttp://***/Signalr/hubs/scriptdiv idqrcodecanvas width256 height256/canvas/divscript typetext/javascriptjQuery.support.corstrue;var SignalrHub$.connection.hub;$(function(){var loginCodeguid();//生成登录码二维码jQuery(#qrcode).qrcode(loginCode);console.log(loginCode);SignalrHub.urlhttp://***/Signalr/hubs;//服务器端Singnalr hub 路径var hubClient$.connection.messageHub.client;hubClient.ShowMessagefunction(msg){var jsonMsg $.parseJSON(msg);if(jsonMsg jsonMsg.loginCodeloginCode){//向服务器验证用户id登录码if(server.CheckLoginCode(jsonMsg.UserId,jsonMsg.loginCode)){alert(登录成功);top.location.reload();//跳转到需要的页面}}}SignalrHub.start();//SignalrHub.stop()});//生成仿Guid字符串function guid() {return ecbxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx.replace(/[xy]/g, function(c) {var r Math.random()*16|0, v c x ? r : (r0x3|0x8);return v.toString(16);});}/script/body
/html模拟服务器代码
//app设置用户登录码接口
public string SetLoginCode(string userIdstring loginCode)
{ //todo 设置登录码//广播消息var hub GlobalHost.ConnectionManager.GetHubContextMessageHub();hub.Clients.All.ShowMessage(userIdloginCode);//也可以定向广播
//web验证登录码接口
public bool CheckLoginCode(string userIdstring loginCode)
{ //todo 验证登录码//todo 验证成功 清除或者更改登录码return true服务器如何使用Signalr 请参阅相关文档 https://blog.csdn.net/admans/article/details/89309761。