原创地址: (泥沙砖瓦浆木匠),需要转载的,保留下! Thanks
"沉下心,你不再是小孩子了.多看书,学做人"-JeffLi告诉自己
Written In The Font
花了一个天一夜,搞了这个小东西-安卓手机令牌.其实,我这边分享,看网上东西也没多少.这就分享了.因为这个会给公司用.有些东西就不方便透露了.希望大家体谅.还有如果需要找我沟通,加群吧!在页面中会有三处出现.
Android手机令牌
- 界面
- java 与 C#服务端交互
- 倒计时和顺计时技术
- 口令生成
Content
android 也不难学,承认花了时间1/2 花在界面上.界面需要经验的积累.和大哥有说有笑搞着界面,我们浩二有木有.要吐槽的可以吐槽,要啥的说啥.
界面
代码:
java 与 C#服务端交互
这种东西 一抓一大把,我这边简单就用了下ksoap2-android-assembly-2.4-jar-with-dependencies.jar,发现交互很简单,url call下然后 调用方法返回值.所以这边代码:
private String getDateTime() throws Exception { // UIHelper.ToastMessage(MainActivity.this, "进去"); SoapObject rpc = new SoapObject(NAMESPACE, GET_TIME_METHOD_NAME); AndroidHttpTransport ht = new AndroidHttpTransport(URL); ht.debug = true; SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.bodyOut = rpc; envelope.dotNet = true; envelope.setOutputSoapObject(rpc); try { ht.call(GET_TIME_SOAP_ACTION, envelope); } catch (Exception e) { // 校准时间网络错误 UIHelper.ToastMessage(MainActivity.this, "未连接网络或网络异常"); } SoapObject result = (SoapObject) envelope.bodyIn; SoapPrimitive detail = (SoapPrimitive) result .getProperty("GetDateTimeResult"); System.out.println("result" + result); System.out.println("detail" + detail); // UIHelper.ToastMessage(MainActivity.this, detail.toString()); return detail.toString(); }
倒计时和顺计时技术
android端倒计时:
// 倒计时 Handler handler = new Handler() { public void handleMessage(Message msg) { // handle message switch (msg.what) { case 1: recLen--; if (recLen < 10) { txtTextTimeBack.setText("0" + recLen); }else{ txtTextTimeBack.setText("" + recLen); }if (recLen > 0) { Message message = handler.obtainMessage(1); handler.sendMessageDelayed(message, 1000); // send message } else { // 重新获取序列号 Message message = handler.obtainMessage(1); handler.sendMessageDelayed(message, 1000); // send message String dateTime; try { dateTime = DateFormate.getDateTime(); txtDateTime.setText(dateTime); } catch (Exception e) { UIHelper.ToastMessage(MainActivity.this, "未知错误"); e.printStackTrace(); } turnTimeBack(); try { showTheNumber(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } super.handleMessage(msg); } };
顺时采用上面倒计时的方法里面,加起来合为60
String ss = DateFormate.getStringFromDate(DateFormate.getDateFormString(txtDateTime.getText().toString())); if (recLen > 50) { ss += "0" + (60-recLen); } else { ss += "" + (60-recLen); } txtDateTime.setText(ss);
口令生成
这是核心关键.所以我这边生成的算法就不方便透露了.像沟通的话,加我的群讨论.口令可以根据 序列号 时间 特定字符串生成.这边我提供下 有关算法,像MD5...等都是常用的
String key = String.valueOf((dateTimeLong ^ serialNumberLong)); String result = null; MessageDigest mad5 =null; try { mad5 = MessageDigest.getInstance("MD5"); } catch (Exception e) { e.printStackTrace(); }
Editor's Note
加油 英语六级,只有自己强大了,人家才会找你,更好的平台给你.