背景:微信的 jsapi_ticket,有7200秒的有效期,官方文档说要第三方自定义中控服务器,在一定的时间去刷新 jsapi_ticket。
问题描述:定义了一个 Timer 定时器,提前 200 秒去获取 jsapi_ticket。但是每次刷新后获取到的jsapi_ticket都是同一个值,不会改变。
测试如下:
测试时调用了两个方法:获取 access_token 和 获取 jsapi_ticket,两次获取的 access_token 不一样,但是 jsapi_ticket 却是一样。
You don’t care whether it’s the same or not, as long as it works
How good is it that you made it a passive trigger? Check the expiration time every time you use it. If it expires, refresh it. This is how it is used in the official php example
The answer above is from PHP. You can learn from it. For the front-end which is a static resource, you can only let the front-end check it. If it is found to be expired, send a request to update the ticket to the server and let the server update it. Active brushing feels unreliable, 7200s, the card is not that accurate