1.access_token.json文件 用于存储access_token
{"access_token": "15_DUMf8LJODBpD7q8yTQpDFZ1kHEzs6o-pbSzPtMVIgahBJTuIWv4tsgB8Boq5uYAbM_YAb-0eg-A2DNUPOeih-XQHzH9uMfFZ7DU2MLuV9fT4oQxOPgCd47zlDGJhAFAGJM", "expires_time": 1543041788} |
2.token.php
用于读取access_token和刷新access_token
<?php header( "Content-Type: text/html;charset=utf-8" ); $ip = $_SERVER [ 'REMOTE_ADDR' ]; //设置安全ip if ( $ip == "115.181.78.94" ){ $res = file_get_contents ( 'access_token.json' ); $result = json_decode( $res , true); $expires_time = $result [ "expires_time" ]; $access_token = $result [ "access_token" ]; if (time() > ( $expires_time + 3600)){ $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx43333b9fe558&secret=30518e99f338cb1f8ecac3469204dac5" ; $res = file_get_contents ( $url ); $result = json_decode( $res , true); $access_token = $result [ "access_token" ]; $expires_time = time(); file_put_contents ( 'access_token.json' , '{"access_token": "' . $access_token . '", "expires_time": ' . $expires_time . '}' ); echo '{"access_token":"' . $access_token . '","author":"wangsanqu"}' ; } else { echo '{"access_token":"' . $access_token . '","author":"wangsanqu"}' ; } } else { echo "403禁止调用api" ; exit (); } |
3.在需要调用的地方进行调用
$url = "https://********/token.php" ; $res = file_get_contents ( $url ); $result = json_decode( $res , true); $access_token = $result [ "access_token" ]; $expires_time = time(); |
老铁怎么处理的各种过期情况
有办法实现采集有效的微信appmsg_token 跟wap_sid2这种ck跟参数吗?重金酬谢qq196116707
是如何处理并发的?