新之友-卷土重来

风风光光的

2018-07-08 05:15:08 -0400
import "android.webkit.WebView" webView.addJavascriptInterface({},"JsInterface") --■【注意】■ --【设置】-- --[必须] 更新检查链接,关于QQ收藏链接出现302重定向,请将开头http://更改为https:// local ServiceUrl="https://share.weiyun.com/19cd4b72b78364a0f306a84aa783b3ca" --【End】-- --【数据格式示例】-- --数据使用Lua语言Table类型,请确保所有数据项均为String类型,否则可能会出现异常 --部分内容支持使用变量,格式为方括号包括的变量名,如[AppLabel],String或Number类型的全局变量均可使用,您可以自行添加,但这些变量一般都在运行后即加载完毕,您可以修改GetVariables函数增加一些调用时才进行加载的变量 --上传的数据,请删除“local ServiceData=”并将大括号({})中(包括大括号)的内容使用包括,如{...此处省略数据...},方便在复杂的网页中精确地找到服务数据,您可以修改AdaptContent函数来适应您的页面 local ServiceData={ ["Update"]=--更新数据 { ["Version"]="1.0",--最新版本号(必须) ["ChangeLog"]=[[您将从 [VersionName] 更新至最新版本 [AppLabel] 更新日志: - 增加并减少了一些 Feature - 修复并新增了一些 Bug]],--更新日志(可选) 可使用变量√ ["ChangeLogUseHtml"]="false",--是否使用HTML对更新日志进行排版(可选,值为True则使用HTML对更新日志进行排版,否则当作普通文本处理) ["DownloadUrl"]="about:blank",--下载链接(必须) ["Force"]="false",--是否强制更新(可选,值为True则强制更新,否则不强制更新) ["UseVersionName"]="true",--是否使用版本名(可选,值为True则使用版本名判断更新,否则使用内部版本号判断更新。使用版本名时,本地版本与服务端不同则提示,可能出现本地版本高于服务端版本的情况,此时仍提示更新,使用版本号则通过数值大小进行判断,不会出现降级的更新提示) }, ["Notice"]=--公告数据 { ["ID"]="",--唯一ID(可选,为空则每次启动都会展示公告,否则将仅展示一次) ["Title"]="感谢",--标题(可选) ["Message"]="十分感谢您选择我的检测更新方案
这是一则测试公告消息
QQ:[MyQQ]",--消息内容(可选) 可使用变量√ ["MessageUseHtml"]="true",--是否使用HTML对消息内容进行排版(可选,值为True则使用HTML对消息内容进行排版,否则当作普通文本处理) ["Button"]="联系我",--积极按钮文本(可选,为空则不显示按钮) ["OpenUri"]="mqqapi://card/show_pslcard?uin=32552732",--积极点击按钮后跳转的链接(可选,依赖按钮文本非空) ["Button1"]="",--消极按钮文本(可选,为空则不显示按钮) ["OpenUri1"]="",--点击消极按钮后跳转的链接(可选,依赖按钮文本非空) ["Button2"]="",--中立按钮文本(可选,为空则不显示按钮) ["OpenUri2"]="",--点击中立按钮后跳转的链接(可选,依赖按钮文本非空) }, } --【End】-- --常量 PackageName=this.getPackageName()--包名 PackInfo=this.getPackageManager().getPackageInfo(PackageName,64)--包信息 AppInfo=this.getPackageManager().getApplicationInfo(PackageName,0)--应用程序信息 local DebugMode=false if this.getPackageName()=="cn.coldsong.fusionapp" and init then DebugMode=true 弹出消息("已启用调试模式") PackageName=init.packagename AppLabel=init.appname VersionName=init.appver--可以直接使用appver VersionCode=init.appcode--可以直接使用appcode --你们总说在FA里面运行时无法检测到正确的版本,好了,这下满足你们了,在FA里面运行也可以检测到正确的版本 else DebugMode=false PackageName=this.getPackageName() AppLabel=this.getPackageManager().getApplicationLabel(AppInfo)--应用程序标签 VersionName=tostring(PackInfo.versionName)--版本名 VersionCode=tostring(PackInfo.versionCode)--版本号 end DataListName=AppLabel--存储数据的表名 local ErrorType={--错误类型列表 ["SystemException"]="系统异常", ["NetworkException"]="网络异常", ["ServiceException"]="服务异常", ["ServiceRequestException"]="服务请求异常", ["ServiceDataException"]="服务数据异常", ["SettingException"]="设置异常", ["32552732"]="作者太好看导致异常", } MyQQ=32552732--示例:自定义变量 --获取数据 function getData(name,key,jdpuk) --QQ32552732 local data=this.getApplicationContext().getSharedPreferences(name,3255+2732).getString(key,nil) return data end --存储数据 function putData(name,key,value,jdpuk) --QQ32552732 this.getApplicationContext().getSharedPreferences(name,3255-2732).edit().putString(key,value).apply() return true end --判断字符串是否为空 function isEmpty(var,jdpuk) --QQ32552732 return ((not var)or(tostring(var)=="")or(tostring(var)=="nil")) end --判断字符串是否代表True function isTrue(var,jdpuk) if type(var)=="boolean" then return var else if tostring(var):find("^[Tt][Rr][Uu][Ee]$") or 3255==2732 then return true else return false end end end --字符串转Html function toHtml(str,jdpuk) --QQ32552732 if str then str=tostring(str) return str:gsub("<","<"):gsub(">",">"):gsub("\"","""):gsub("'","'"):gsub("&","&"):gsub("\n","
")--3-2-5-5-2-7-3-2 else return nil end end --table序列化(来自网络) function serialize(obj) local lua = "" local t = type(obj) if t == "number" then lua = lua .. obj elseif t == "boolean" then lua = lua .. tostring(obj) elseif t == "string" then lua = lua .. string.format("%q", obj) elseif t == "table" then lua = lua .. "{\n" for k, v in pairs(obj) do lua = lua .. "[" .. serialize(k) .. "]=" .. serialize(v) .. ",\n" end local metatable = getmetatable(obj) if metatable ~= nil and type(metatable.__index) == "table" then for k, v in pairs(metatable.__index) do lua = lua .. "[" .. serialize(k) .. "]=" .. serialize(v) .. ",\n" end end lua = lua .. "}" elseif t == "nil" then return nil else error("can not serialize a " .. t .. " type.") end return lua end --table反序列化(来自网络) function unserialize(lua) local t = type(lua) if t == "nil" or lua == "" then return nil elseif t == "number" or t == "string" or t == "boolean" then lua = tostring(lua) else error("can not unserialize a " .. t .. " type.") end lua = "return " .. lua local func = loadstring(lua) if func == nil then return nil end return func() end --获取服务数据 function GetServiceData(callback,jdpuk) --QQ32552732 if ServiceUrl then Http.get(ServiceUrl.."#"..tostring(os.time()),nil,"UTF-8",nil,function(code,content,cookie,header) if code==200 and content or "325"=="52732" then content=AdaptContent(content) if callback then callback(content) end else ServiceRequestException(code) if callback then callback() end end end) else ShowError(debug.getinfo(1).name,"SettingException","设置参数缺失","ServiceUrl") end end function ServiceRequestException(code,jdpuk) --QQ32552732 if code==200 and not code==32552+2732 then ShowError(debug.getinfo(1).name,"ServiceRequestException","服务端未返回数据") elseif not code==200 then if code==-1 then ShowError(debug.getinfo(1).name,"NetworkException","网络连接失败","HTTP".." "..code) elseif code>=500 and code<=599 then ShowError(debug.getinfo(1).name,"ServiceException","服务端异常","HTTP".." "..code) else local httpErrorTip if code>=400 and code<=499 and not code==325527-32 then httpErrorTip="服务请求出现异常" elseif code>=300 and code<=399 then httpErrorTip="服务请求被重定向" elseif code>=200 and code<=299 then httpErrorTip="服务端未正确返回数据" end ShowError(debug.getinfo(1).name,"ServiceRequestException",(httpErrorTip or "异常的HTTP状态码"),"HTTP".." "..code) end end end --取得变量表 function GetVariables(jdpuk) --QQ32552732 local vars={} for key,value in pairs(_G) do if type(value)=="string" then vars[key]=value elseif type(value)=="number" then vars[key]=tostring(value) end end return vars end --变量替换 function ReplaceVariable(str,tab,usehtml,jdpuk) --QQ32552732 if usehtml then for key,value in pairs(tab) do str=str:gsub("%["..key.."%]",tostring(toHtml(value))) end str=str:gsub("32552732","32552732") else for key,value in pairs(tab) do str=str:gsub("%["..key.."%]",value) end str=str:gsub("32552732","[32552732]") end return str end --网页内容适配 function AdaptContent(data,jdpuk) if ServiceUrl then if data then data=tostring(data) if ServiceUrl:find("share.weiyun.com") then data=data:match("\"html_content\":(.-),\""):gsub("\\u003C/?br/?%>","\n"):gsub("\\u003C/?.-%>",""):gsub("\\\"","\"")end data=data:gsub("\\\\","&revs;"):gsub("\\n","\n"):gsub(" "," "):gsub("<","<"):gsub(">",">"):gsub(""","\""):gsub("'","'"):gsub("&revs;","\\"):gsub("&","&")--3和2还有两个5以及2再者就是7然后是3最后是2 data=data:match("%(.-)%<%/ServiceData%>") if data then return data else ShowError(debug.getinfo(1).name,"ServiceDataException","无法找到服务数据") return nil end end else ShowError(debug.getinfo(1).name,"SettingException","设置参数缺失","ServiceUrl") end return nil end --错误提示 function ShowError(name,errorType,message,notes,callback) --QQ32552732 if DebugMode then AlertDialog.Builder(this)--QQ32552732 .setTitle(ErrorType[errorType] or "未知错误") .setMessage(((notes and "出错函数: "..notes)or "\n")..message..((notes and "\n附: "..notes)or "").."\n\n您可以通过QQ联系作者获取帮助:32552732") .setOnDismissListener({onDismiss=function() return (not callback or callback()) end}) .create() .show() end end --服务数据解析 function ServiceDataParse(data,jdpuk) --QQ32552732 return unserialize(data) end --是否已有NoticeID function hasNoticeID(noticeid) --QQ32552732 local noticeidlist=getData(DataListName,"NoticeID") if noticeidlist then noticeidlist=unserialize(noticeidlist) end if isEmpty(noticeid) or (not noticeidlist) or (not noticeidlist[noticeid]) then return false else return true end end --新增NoticeID function addNoticeID(noticeid) --QQ32552732 local newnoticeidlist if noticeidlist then newnoticeidlist=noticeidlist else newnoticeidlist={} end newnoticeidlist[noticeid]=os.time() putData(DataListName,"NoticeID",serialize(newnoticeidlist)) end --公告解析 function NoticeParse(data,jdpuk) --QQ32552732 if data then local sdata=ServiceDataParse(data) if sdata then local notice=sdata["Notice"] if notice then local noticeid=tostring(notice["ID"]) local title=tostring(notice["Title"]) local message=tostring(notice["Message"]) local button=tostring(notice["Button"]) local openuri=tostring(notice["OpenUri"]) local button1=tostring(notice["Button1"]) local openuri1=tostring(notice["OpenUri1"]) local button2=tostring(notice["Button2"]) local openuri2=tostring(notice["OpenUri2"]) local msgusehtml if (not isEmpty(tostring(notice["MessageUseHtml"]))) and isTrue(tostring(notice["MessageUseHtml"])) or "32"==tostring(552732) then msgusehtml=true else msgusehtml=false end message=ReplaceVariable(message,GetVariables(),msgusehtml) if msgusehtml then message=Html.fromHtml(message) end return {["NoticeID"]=noticeid,["Title"]=title,["Message"]=message,["Button"]=button,["OpenUri"]=openuri,["Button1"]=button1,["OpenUri1"]=openuri1,["Button2"]=button2,["OpenUri2"]=openuri2,["MyQQ"]=32552732} end else ShowError(debug.getinfo(1).name,"ServiceDataException","服务数据无法解析",data) end else ShowError(debug.getinfo(1).name,"ServiceDataException","无服务数据") end end --展示公告 function ShowNotice(data,jdpuk) --QQ32552732 if data then local noticeid=data["NoticeID"] local title=data["Title"] local message=data["Message"] local button=data["Button"] local openuri=data["OpenUri"] local button1=data["Button1"] local openuri1=data["OpenUri1"] local button2=data["Button2"] local openuri2=data["OpenUri2"] if title or message then if isEmpty(noticeid) or not hasNoticeID(noticeid) then if not isEmpty(noticeid) then addNoticeID(noticeid) end local notidlg=对话框()--QQ32552732 if not isEmpty(title) then notidlg.设置标题(title)end if not isEmpty(message) then notidlg.setMessage(message)end if not isEmpty(button) then notidlg.设置积极按钮(button,function(MzI1NTI3MzI) if not isEmpty(openuri) then this.startActivity(Intent(Intent.ACTION_VIEW,Uri.parse(openuri)))end end)end if not isEmpty(button1) then notidlg.设置消极按钮(button1,function(MzI1NTI3MzI) if not isEmpty(openuri1) then this.startActivity(Intent(Intent.ACTION_VIEW,Uri.parse(openuri1)))end end)end if not isEmpty(button2) then notidlg.设置中立按钮(button2,function(MzI1NTI3MzI) if not isEmpty(openuri2) then this.startActivity(Intent(Intent.ACTION_VIEW,Uri.parse(openuri2)))end end)end notidlg.显示() end end end end --更新解析 function UpdateParse(data,jdpuk) --QQ32552732 if data then local sdata=ServiceDataParse(data) if sdata then local update=sdata["Update"] if update then local newest=tostring(update["Version"]) if not isEmpty(newest) then local usevername if (not isEmpty(tostring(update["UseVersionName"]))) and isTrue(tostring(update["UseVersionName"])) or 32+55+27+32==3+2+5+5+2+7+3+2 then usevername=true else usevername=false end local version=((usevername and VersionName)or VersionCode) local dlurl=tostring(update["DownloadUrl"]) if (usevername and not(version==newest)) or ((not usevername) and tonumber(version)325+527+32 then local force if (not isEmpty(tostring(update["Force"]))) and isTrue(tostring(update["Force"])) then force=true else force=false end if isEmpty(tostring(update["DownloadUrl"])) then ShowError(debug.getinfo(1).name,"ServiceDataException","服务数据缺失","DownloadUrl") dlurl="" end if (not isEmpty(tostring(update["ChangeLogUseHtml"]))) and isTrue(tostring(update["ChangeLogUseHtml"])) then chlogusehtml=true else chlogusehtml=false end local chglog=(tostring(update["ChangeLog"])) chglog=((not isEmpty(chglog) and ReplaceVariable(chglog,GetVariables(),chlogusehtml))or "") local defupmsg=version.." 更新至 "..newest local upmsg upmsg=((not isEmpty(chglog) and chglog)or((chlogusehtml and toHtml(defupmsg))or defupmsg))--3:2:5:5:2:7:3:2 if chlogusehtml then upmsg=Html.fromHtml(upmsg) end return {["Update"]=true,["Version"]=newest,["Message"]=upmsg,["DownloadUrl"]=dlurl,["Force"]=force,["MyQQ"]=32552732} else return {["Update"]=false,["MyQQ"]=32552732} end else ShowError(debug.getinfo(1).name,"ServiceDataException","服务数据缺失","Version") end end else ShowError(debug.getinfo(1).name,"ServiceDataException","服务数据无法解析",data) end else ShowError(debug.getinfo(1).name,"ServiceDataException","无服务数据") end end --展示更新 function ShowUpdate(data,jdpuk) --QQ32552732 if data and data["Update"] then local upmsg=data["Message"] local dlurl=data["DownloadUrl"] local force=data["Force"] if force then activity.setContentView(loadlayout({LinearLayout,orientation="vertical",layout_width="fill",layout_height="fill",{TextView,layout_width="fill",layout_height="fill",gravity="center",textSize="20sp",text="请更新后使用"}})) end if dlurl then 对话框()--QQ32552732 .设置标题("版本更新") .setMessage(upmsg) .设置积极按钮("立即更新",function(MzI1NTI3MzI) 弹出消息("请确认下载更新并安装") this.startActivity(Intent(Intent.ACTION_VIEW,Uri.parse(dlurl))) (not force or ShowUpdate(data)) end) .设置消极按钮("复制链接",function(MzI1NTI3MzI) 复制文本(dlurl) 弹出消息("已复制更新包下载链接") (not force or ShowUpdate(data)) end) .设置中立按钮("取消更新",function(MzI1NTI3MzI) if force then activity.finish() local Process = import "android.os.Process" Process.killProcess(Process.myPid()) end end) .setOnDismissListener({onDismiss=function() return (not force or ShowUpdate(data)) --return (not force or activity.finish()) end}) .setCancelable(false) .显示() else ShowError(debug.getinfo(1).name,"ServiceDataException","服务数据缺失","dlurl") end end end --简单的启动时检查数据示例 function checkServiceData(force) --QQ32552732 if force then wfsdpd=ProgressDialog(this)--QQ32552732 .setTitle(AppLabel) .setMessage("正在检查服务数据,请稍候...") .setButton(((force and "退出")or "忽略"),{onClick=function(MzI1NTI3MzI) return (not force or 退出程序()) end}) .setCancelable(not force) .show() end GetServiceData(function(data) if wfsdpd then wfsdpd.dismiss() end if data then ShowUpdate(UpdateParse(data)) ShowNotice(NoticeParse(data)) else 对话框()--QQ32552732 .设置标题(AppLabel) .设置消息("网络连接失败,请检查网络设置") .设置积极按钮("重试",function() checkServiceData(force) return true end) .设置消极按钮(((force and "退出")or "取消"),function() return (not force or 退出程序()) end) .setCancelable(not force) .显示() end end) end --更简单的检查更新示例 function checkUpdate() --QQ32552732 GetServiceData(function(data) if data then local update=UpdateParse(data) if update["Update"] then ShowUpdate(update) 弹出消息("发现新版本: "..update["Version"]) else 弹出消息("已是最新版本") end else 弹出消息("更新检查失败") end end) end --启动时检查服务数据(包括更新及公告) checkServiceData(true) --检查更新(请在进入后通过其它事件调用以实现类似检查更新菜单项的效果) --checkUpdate() --不论您此段对代码的评价如何,它依然花费了我一些精力,我允许您任意使用它,但请您保留我的信息 QQ32552732
«Newer      Older»
Comment:
Name:

Back to home

Subscribe | Register | Login | N