關於android引用js問題 其實全部版本的rhino均可以用,只需設置一句話就不會報錯了php
Context.setOptimizationLevel(-1);android
主要緣由是android端的loadClass 被閹割了,估計是出於安全考慮。安全
由於程序的全部邏輯都是寫在js上的,那咱們其實能夠把js放到網上隨時更新js就能夠實現android程序的更新,我沒有服務器,但是我有網盤,吼吼。服務器
把文件上傳到360網盤,而後點分享,得到了一個地址相似於「http://yunpan.cn/QUcUHNdtEirst」app
這個關鍵不是js的實際地址 點擊下載後我又獲得了一個新的地址ide
相似於這樣「http://wsdl10.yunpan.cn/share.php?method=Share.download&fhash=2588b2ca564b112143bd78a63f50db5b30e3edd1post
&xqid=29888319&fname=main.js&fsize=2049&nid=13851296172171637url
&cqid=6a80b4215085d2a23ed1e42ff18c5934spa
&st=e5ea00745daf984b49876c2e49797b76&e=1385621477&dt=10.7b270785893ffc2e3fa5a64b051dffe8」code
這個是實際地址,js文件也能夠下載下來,可是仍是有個問題
這個地址只能維持一天的使用時間 坑爹啊!
因此返回上一步 我本身解析一下第一個地址獲取js文件地址不就能夠了
代碼下面這樣
public static String getloadURL(String shorturl,String nid) throws Exception{ String postData="shorturl="+shorturl+"&nid="+nid; final MyClient client = new MyClient("awlpx8qetr.l6.yunpan.cn", 80); client.sendMessage("POST /share/downloadfile/ HTTP/1.1\r\n"); client.sendMessage("Accept:*/*\r\n"); client.sendMessage("X-Requested-With:XMLHttpRequest\r\n"); client.sendMessage("Content-Type:application/x-www-form-urlencoded UTF-8\r\n"); client.sendMessage("Referer:http://awlpx8qetr.l6.yunpan.cn/lk/"+shorturl+"\r\n"); client.sendMessage("Content-Length:"+postData.getBytes().length+"\r\n"); client.sendMessage("Host:awlpx8qetr.l6.yunpan.cn\r\n"); client.sendMessage("User-Agent:Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)\r\n"); client.sendMessage("DNT:1\r\n"); client.sendMessage("Connection:Keep-Alive\r\n\r\n"+postData+"\r\n"); client.flush(); while(true){ Matcher m = Pattern.compile("(http:){1}[\\s\\S]+(?=\",\")").matcher(client.getMessage()); while(m.find()){ client.close(); return m.group(); } } } public static String getloadNid(String shorturl) throws Exception{ final MyClient client = new MyClient("awlpx8qetr.l6.yunpan.cn", 80); client.sendMessage("GET /lk/"+shorturl+" HTTP/1.1\r\n"); client.sendMessage("Accept:*/*\r\n"); client.sendMessage("Host:awlpx8qetr.l6.yunpan.cn\r\n"); client.sendMessage("User-Agent:Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)\r\n"); client.sendMessage("DNT:1\r\n"); client.sendMessage("Connection:Keep-Alive\r\n\r\n"); client.flush(); while(true){ Matcher m = Pattern.compile("(?<=nid : \'){1}[\\s\\S]+(?=\',)").matcher(client.getMessage()); while(m.find()){ client.close(); return m.group(); } } } public static String get360Url(String shorturl) throws Exception{ String nid=getloadNid(shorturl); return getloadURL(shorturl,nid); } public static void main(String[] args) throws Exception { String url=get360Url("QUcUHNdtEirst"); System.out.println(url); }
只要傳一個url就能夠獲取到js地址了,只有一個小問題就是 慢要等上10-30秒左右,對於更新來講仍是能夠接受的