androlua吧 关注:1,177贴子:1,855
  • 5回复贴,共1

用androlua实现快递查询

只看楼主收藏回复

require "import"
require "http"
import "android.widget.*"
import "android.view.*"
import "android.app.*"
import "android.view.View_*"
import "android.content.*"
local kd={
['AAE快递']='aae',
['安捷快递']='anjie',
['安信达快递']='anxinda',
['Aramex国际快递']='aramex',
['CCES快递']='cces',
['长通物流']='changtong',
['程光快递']='chengguang',
['传喜快递']='chuanxi',
['传志快递']='chuanzhi',
['CityLinkExpress']='citylink',
['东方快递']='coe',
['城市之星']='cszx',
['大田物流']='datian',
['德邦物流']='debang',
['DHL快递']='dhl',
['递四方速递']='disifang',
['DPEX快递']='dpex',
['D速快递']='dsu',
['百福东方物流']='ees',
['国际Fedex']='fedex',
['Fedex国内']='fedexcn',
['飞邦物流']='feibang',
['飞豹快递']='feibao',
['原飞航物流']='feihang',
['飞远物流']='feiyuan',
['丰达快递']='fengda',
['飞康达快递']='fkd',
['飞快达快递']='fkdex',
['广东邮政物流']='gdyz',
['共速达物流|快递']='gongsuda',
['国通快递']='guotong',
['天地华宇物流']='huayu',
['汇通快递']='huitong',
['佳吉快运']='jiaji',
['佳怡物流']='jiayi',
['加运美快递']='jiayunmei',
['京广快递']='jingguang',
['晋越快递']='jinyue',
['嘉里大通物流']='jldt',
['快捷快递']='kuaijie',
['蓝镖快递']='lanbiao',
['乐捷递快递']='lejiedi',
['联昊通快递']='lianhaotong',
['龙邦快递']='longbang',
['民航快递']='minhang',
['港中能达快递']='nengda',
['OCS快递']='ocs',
['平安达']='pinganda',
['全晨快递']='quanchen',
['全峰快递']='quanfeng',
['全际通快递']='quanjitong',
['全日通快递']='quanritong',
['全一快递']='quanyi',
['RPX保时达']='rpx',
['如风达快递']='rufeng',
['三态速递']='santai',
['伟邦(SCS)快递']='scs',
['盛丰物流']='shengfeng',
['盛辉物流']='shenghui',
['申通快递']='shentong',
['速尔快递']='sure',
['天天快递']='tiantian',
['TNT快递']='tnt',
['通成物流']='tongcheng',
['UPS']='ups',
['USPS快递']='usps',
['万家物流']='wanjia',
['新邦物流']='xinbang',
['信丰快递']='xinfeng',
['源安达快递']='yad',
['亚风快递']='yafeng',
['一邦快递']='yibang',
['银捷快递']='yinjie',
['优速快递']='yousu',
['北京一统飞鸿快递']='ytfh',
['远成物流']='yuancheng',
['圆通快递']='yuantong',
['元智捷诚']='yuanzhi',
['越丰快递']='yuefeng',
['韵达快递']='yunda',
['运通中港快递']='yuntong',
['源伟丰']='ywfex',
['宅急送快递']='zhaijisong',
['中铁快运']='zhongtie',
['中通快递']='zhongtong',
['忠信达快递']='zhongxinda',
['中邮物流']='zhongyou',
['EMS快递']='ems',
['顺丰快递']='shunfeng',
}
local key={}
local kdgs --快递公司
local kddh --快递单号
for k,v in pairs(kd) do
table.insert(key,k)
end
--json变成表
function json2table(json)
local j=tostring(json)
j=string.gsub(j,'%[','{')
j=string.gsub(j,'%]','}')
j=string.gsub(j,'\"([^\"]-)\":','[\'%1\']=')
j='local t='..j..'\r\nreturn t'
return loadstring(j)()
end
function onClick1()
ad= AlertDialog.Builder(activity)
ad.setTitle("选择快递公司")
ad.setItems(String(key) --将表转换成String数组
,DialogInterface.OnClickListener{
onClick=function(dialog,which)
kdgs=key[which+1] --lua是从1开始的
tv1.setText(string.format("快递公司(%s)",kdgs))
end
})
ad.setNegativeButton( "取消", nil)
ad.show()
end
function onClick2()
kddh=tb1.getText().toString()
if(kdgs==nil or kddh=="") then
print("快递单号和快递公司都不能为空")
return
end
str=http.get("http://api.ickd.cn/?id=E232DC317A582FA7BFBFE6CE2AF8E282&com="..kd[kdgs].."&nu="..kddh)
str=String(byte{string.byte(str,1,-1)},"gbk")
--str=luajava.coding(str,"gbk")
t=json2table(str)
data=t.data
n=1
sb =StringBuilder()
while data[n] do
sb.append(data[n].time..'\t')
sb.append(data[n].context..'\r\n')
n=n+1
end
--如果有花括号把它替换成【】
str= sb.toString();
str=string.gsub(str,'{','【')
str=string.gsub(str,'}','】')
tv2.setText(str)
end
layout={
LinearLayout,
layout_width="fill",
orientation="1",
{
TextView,
text="快递公司(未选择)",
layout_width="fill",
singleLine=true,
id="tv1"
} , {
Button,
text="选择……",
onClick="onClick1",
layout_width="fill",
singleLine=true,
id="bn1"
} ,
{
EditText,
hint="请输入快递单号",
layout_width="fill",
singleLine=true,
-- text="",
id="tb1"
} ,
{
Button,
text="查询",
layout_width="fill",
onClick="onClick2",
id="bn2"
} ,{
TextView,
text="",
layout_width="fill",
id="tv2"
}
}
--loadlayout(layout)
activity.setContentView(loadlayout(layout))
   --整天发帖,TMD就你事多→_→


IP属地:浙江来自Android客户端1楼2015-08-06 00:52回复
    支持下


    IP属地:河北来自Android客户端2楼2015-08-06 18:24
    回复
      134行把"改成双引号


      IP属地:广东来自手机贴吧3楼2015-08-20 09:37
      收起回复
        测试可以用


        IP属地:江西来自Android客户端5楼2019-02-22 10:14
        回复
          求代码文件


          来自Android客户端6楼2020-06-20 14:23
          回复