android通过php判断用户是否注册,android - 判断Token是否有效

伊谢尔伦2017-04-17 13:32:322楼

1.

所有 修改系统时间的问题都可以通过添加 nanoTime 验证来解决.

System.nanoTime();

/**

* Returns the current timestamp of the most precise timer available on the

* local system, in nanoseconds. Equivalent to Linux's {@code CLOCK_MONOTONIC}.

*

*

This timestamp should only be used to measure a duration by comparing it

* against another timestamp on the same device.

* Values returned by this method do not have a defined correspondence to

* wall clock times; the zero value is typically whenever the device last booted.

* Use {@link #currentTimeMillis} if you want to know what time it is.

*/

public static native long nanoTime();

注意nanoTime返回的不是UTC时间,是开机以后经过的时间.不受系统时间影响.

2.

在实际项目中,我现在的处理方案是,根本就不记录expires.

在网络层会封装各种错误,token失效会触发一个401错误

在错误分发器上,我主动拦截该错误并发起一个事件(REFRESH_TOKEN)

用Event Dispatch框架(EventBus,otto之类的)在上层接受该事件,并把用户直接导向登录界面或弹出Alert确认框

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值