今天我们聊聊,当我们没有服务器的时候是如何进行远程登录调试.这种方法只适合开发调试,并不适合生产环境,当然不注重安全信息的项目当我没说.(其实这种想法是来自于微信小程序的云开发,微信小程序云开发使用的就是json数据库)
gitee登录注册和创建仓库我就不说了,不会的请自信百度哈.
<其他我就不详细说明了,自己看例子吧>
先看看json数据结构(嗯就是这么简单)
{
"message": "ok",
"collection": [{
"appname": "登录app测试",
"version": "2",
"use":true,
"data": {
"broadcast":"更多精彩内容清关注微信公众号:VB小源码",
"update": false,
"update_address": "",
"update_info": "无",
"user_info": [{
"user": "21232f297a57a5a743894a0e4a801fc3",
"password": "e10adc3949ba59abbe56e057f20f883e",
"login":true
}, {
"user": "098f6bcd4621d373cade4e832627b4f6",
"password": "e10adc3949ba59abbe56e057f20f883e",
"login":false
}
]
}
}
]
}
B4A源代码
#Region Project Attributes
#ApplicationLabel: 登录示例(gitee配置)
#VersionCode: 1
#VersionName:
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Public user As String
End Sub
Sub Globals
Private url As String="https://gitee.com/wxvbee/app/raw/master/config"
Private md As md5
Private usermap As Map
Private txt_pws As EditText
Private txt_user As EditText
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
Wait For (get_login_data) Complete (mp As Map)
Dim ver As Int=mp.Get("version")
Dim use As Boolean=mp.Get("use")
Dim login_data As Map=mp.Get("data")
If use=False Then
MsgboxAsync("该应用禁止使用","")
End If
If ver> Application.VersionCode Then
MsgboxAsync("发现新版本!","")
End If
''------------
Dim bc As String=login_data.Get("broadcast")
If bc<>"" Then
MsgboxAsync(bc,"广播内容")
End If
''--------------
Dim lit As List
lit.Initialize2(login_data.Get("user_info"))
usermap.Initialize
For Each m As Map In lit
usermap.Put( m.Get("user"),CreateMap("pwd":m.Get("password"),"login":m.Get("login")))
Next
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
If txt_user.Text<>"" Or txt_pws.Text<>"" Then
user=txt_user.Text
If usermap.Get(md.getMD5(txt_user.Text))<>Null Then
Dim mp As Map=usermap.Get(md.getMD5(txt_user.Text))
Dim pwd As String=mp.Get("pwd")
Dim login As String=mp.Get("login")
If login Then
If pwd=md.getMD5(txt_pws.Text) Then
StartActivity(home)
Activity.Finish
End If
Else
MsgboxAsync("该用户禁止登录","")
End If
Else
ToastMessageShow("该用户尚未注册",False)
End If
Else
ToastMessageShow("用户名或密码不能为空!",False)
End If
End Sub
Sub get_login_data() As ResumableSub
Dim j As HttpJob
j.Initialize("", Me)
j.Download(url)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim jsobj As JSONParser,mp As Map,lst As List,resmap As Map
jsobj.Initialize(j.GetString)
mp=jsobj.NextObject
lst.Initialize2(mp.Get("collection"))
For Each m As Map In lst
If m.Get("appname")="登录app测试" Then
resmap=m
Exit
End If
Next
Return resmap
Else
Return Null
End If
End Sub
案例下载
https://vbee.lanzous.com/ib1joldtr4j