Connect to the WeChat third-party platform, repair within 1 day, there is a situation where the token is unavailable within 1 day. Re-adjusted rules, minimize the number of HTTP requests to get the tokens, while the token is absolutely permanently valid
1. At this stage, the realization of the third-party platform of WeChat is connected. In the interface of receiving verification tickets (receiving the WeChat server push), the token (component_access_token) will be judged in Redis Whether it exists, if not, get the token (HTTP request). It is equivalent to pushing the WeChat server every 10 minutes, which is used as a timing command. The specific situation is based on the chronological sequence as follows:
11:25 获取验证票据(component_verify_ticket)
11:25 获取并生成令牌(component_access_token),存储至 Redis,设置过期时间:13:20
13:15 获取验证票据,不会存储至 Redis
13:20 令牌过期
13:25 获取验证票据,存储至 Redis
结论:在 13:20 - 13:25 之间,这 5 分钟以内,微信的令牌不存在,则微信发布不可用。
2. After the re-adjusted rules, in the case of guaranteeing that the token is absolutely permanent, try to reduce the number of HTTP requests to obtain the token. The specific situation is based on the chronological sequence as follows:
11:25 获取验证票据(component_verify_ticket)
11:25 获取并生成令牌(component_access_token),添加字段:有效截止时间(13:25),存储至 Redis
13:05 判断规则:有效截止时间(13:25) - 20分钟 < 13:05。结果为假,不会获取令牌,不会存储至 Redis
13:15 判断规则:有效截止时间(13:25) - 20分钟 < 13:15。结果为真,获取令牌,添加字段:有效截止时间(15:15),存储至 Redis。备注:此时令牌数据已变化,只要执行获取令牌的 HTTP 请求,则会生成新的令牌
13:25 判断规则:有效截止时间(15:15) - 20分钟 < 13:25。结果为假,不会获取令牌,不会存储至 Redis
结论:
1、官方建议在 1小时50分 后重新获取令牌。渠道发布在 1小时40分 后就开始判断是否要重新获取令牌。即在2个小时内,以确保在 1小时50分 后重新获取令牌。
2、官方的验证票据(component_verify_ticket)的推送,平均间隔 10分钟,但是实际上存在 30秒 左右的误差。以下是官方的验证票据(component_verify_ticket)的推送的请求参数的时间戳与转换后普通时间:
1625109905 2021-07-01 11:25:05
1625196309 2021-07-02 11:25:09
1625205285 2021-07-02 13:54:45
1625222097 2021-07-02 18:34:57
3、在 13:05、13:15 的时间点,皆有可能重新获取令牌。
3. Check the specific time point of each HTTP request to get the token. as shown in Figure 1
-rw-r--r-- 1 nginx nginx 231 Jul 2 18:15 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625220904.5864-1284321044.txt
-rw-r--r-- 1 nginx nginx 231 Jul 2 20:05 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625227518.8292-2034263273.txt
-rw-r--r-- 1 nginx nginx 231 Jul 2 21:54 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625234060.9016-2037842134.txt
-rw-r--r-- 1 nginx nginx 231 Jul 2 23:34 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625240074.6086-129234930.txt
-rw-r--r-- 1 nginx nginx 231 Jul 3 01:24 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625246642.1858-1357575717.txt
-rw-r--r-- 1 nginx nginx 231 Jul 3 03:04 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625252663.3032-96333903.txt
-rw-r--r-- 1 nginx nginx 231 Jul 3 04:53 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625259239.382-1358398298.txt
-rw-r--r-- 1 nginx nginx 231 Jul 3 06:34 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625265273.2847-949998836.txt
-rw-r--r-- 1 nginx nginx 231 Jul 3 08:14 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625271273.5153-1059028888.txt
-rw-r--r-- 1 nginx nginx 231 Jul 3 09:54 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625277298.7813-310601964.txt
-rw-r--r-- 1 nginx nginx 231 Jul 3 11:44 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625283877.9521-412669108.txt
-rw-r--r-- 1 nginx nginx 231 Jul 3 13:24 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625289886.807-2092152976.txt
-rw-r--r-- 1 nginx nginx 231 Jul 3 15:14 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625296463.0599-1080955996.txt
-rw-r--r-- 1 nginx nginx 231 Jul 3 16:54 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625302484.4032-1651010868.txt
-rw-r--r-- 1 nginx nginx 231 Jul 3 18:44 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625309067.7121-1067986815.txt
-rw-r--r-- 1 nginx nginx 231 Jul 3 20:24 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625315074.8086-1306110047.txt
-rw-r--r-- 1 nginx nginx 231 Jul 3 22:14 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625321659.2166-403019843.txt
-rw-r--r-- 1 nginx nginx 231 Jul 4 00:04 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625328259.0217-93337953.txt
-rw-r--r-- 1 nginx nginx 231 Jul 4 01:44 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625334265.2403-81093374.txt
-rw-r--r-- 1 nginx nginx 231 Jul 4 03:34 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625340861.6377-119559848.txt
-rw-r--r-- 1 nginx nginx 231 Jul 4 05:14 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625346863.7426-1003494675.txt
-rw-r--r-- 1 nginx nginx 231 Jul 4 06:54 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625352868.7146-1351258397.txt
-rw-r--r-- 1 nginx nginx 231 Jul 4 08:34 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625358895.2811-350216025.txt
-rw-r--r-- 1 nginx nginx 231 Jul 4 10:15 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625364905.1292-483282692.txt
-rw-r--r-- 1 nginx nginx 231 Jul 4 12:05 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625371510.5863-1975502382.txt
-rw-r--r-- 1 nginx nginx 231 Jul 4 13:54 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625378081.9596-379002381.txt
-rw-r--r-- 1 nginx nginx 231 Jul 4 15:34 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625384084.4452-1094694829.txt
-rw-r--r-- 1 nginx nginx 231 Jul 4 17:14 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625390088.3557-588511027.txt
-rw-r--r-- 1 nginx nginx 231 Jul 4 19:05 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625396707.8423-1886295111.txt
-rw-r--r-- 1 nginx nginx 231 Jul 4 20:54 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625403282.8031-1069721276.txt
-rw-r--r-- 1 nginx nginx 231 Jul 4 22:44 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625409877.6077-1660123114.txt
-rw-r--r-- 1 nginx nginx 231 Jul 5 00:34 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625416464.5966-45554414.txt
-rw-r--r-- 1 nginx nginx 231 Jul 5 02:23 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625423039.146-1550811908.txt
-rw-r--r-- 1 nginx nginx 231 Jul 5 04:04 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625429059.9922-66909225.txt
-rw-r--r-- 1 nginx nginx 231 Jul 5 05:54 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625435642.6323-187433523.txt
-rw-r--r-- 1 nginx nginx 231 Jul 5 07:34 frontend-controllers-WxMsgEventController-componentAccessTokenData-1625441682.8374-716247506.txt
4. In a total of 45 requests, the average interval of most calls is about 1 hour and 50 minutes (28 times), and the average interval of a small number of calls is about 1 hour and 40 minutes (17 times).
1小时50分:
18:15 - 20:05
20:05 - 21:54
23:34 - 01:24
03:04 - 04:53
09:54 - 11:44
13:24 - 15:14
16:54 - 18:44
20:24 - 22:14
22:14 - 00:04
01:44 - 03:34
10:15 - 12:05
12:05 - 13:54
17:14 - 19:05
19:05 - 20:54
20:54 - 22:44
22:44 - 00:34
00:34 - 02:23
04:04 - 05:54
1小时40分:
21:54 - 23:34
01:24 - 03:04
04:53 - 06:34
06:34 - 08:14
08:14 - 09:54
11:44 - 13:24
15:14 - 16:54
18:44 - 20:24
00:04 - 01:44
03:34 - 05:14
05:14 - 06:54
06:54 - 08:34
08:34 - 10:15
13:54 - 15:34
15:34 - 17:14
02:23 - 04:04
05:54 - 07:34
5. Check the content of its response. Sampling: 20:05, 21:54, 23:34. The expired deadline for the access token of its response is: 2021-07-02 22:05:18, 2021-07-02 23:54:20, 2021-07-03 01:34:34. in line with expectations. as shown in Figure 2
[root@api-7f9d76b849-kckxz runtime]# cat frontend-controllers-WxMsgEventController-componentAccessTokenData-1625227518.8292-2034263273.txt
Array
(
[component_access_token] => 46_yRwzjrgTGzx94RykB9pycN-nlEXnvYQNSbXC0gfWJ9b091k-wLhFgyeZTIovEIVVJpWvBk4em_byyQrNzfxjjMGj6mKfz-tKHWUKJmxGZDA02t5rdWOvcaYez7EmRZYJ6szrAR4qcHDHeXgPZTXjAGAEYC
[expires_at] => 1625234718
)
[root@api-7f9d76b849-kckxz runtime]# cat frontend-controllers-WxMsgEventController-componentAccessTokenData-1625234060.9016-2037842134.txt
Array
(
[component_access_token] => 46_2hBMmx4Ww0pMYSsLCun4EW80WOcNHUMrOE0i-niX0599OTCi5xOHw5yrJ3It7Um9tyXt9x3MiGuazXgPLAXKUP-3WMIO9Du8ECPk4nM8Ls_iKOGGLrn5QAyGlXueXI4d8glGjPexUdFi53iSERYdAFALYF
[expires_at] => 1625241260
)
[root@api-7f9d76b849-kckxz runtime]# cat frontend-controllers-WxMsgEventController-componentAccessTokenData-1625240074.6086-129234930.txt
Array
(
[component_access_token] => 46_FfM2ZagUut2Z33lVf-PZrUzKrauKTrMU4EcDjZ39sIB3B6RmbKKTNqWfioZgpSEubmUkQEF3foT6gUO5JR-ILanvR8zF7eafBgKh22CRFX8yLcGEMlPDw9zVJPiXWt774FVh2H-u5oV1taXJGQVhAHANXC
[expires_at] => 1625247274
)
[root@api-7f9d76b849-kckxz runtime]#
6. Finally, adjust the 20 minutes to 25 minutes, that is, within 2 hours to ensure that the token is regained after 1 hour and 40 minutes. If the acquisition fails, you can continue to regain the token after 1 hour and 50 minutes. i.e. a total of 2 chances. More fault tolerance.

