|
|
@@ -1,8 +1,7 @@
|
|
|
require("app.app")
|
|
|
local http = require("socket.http")
|
|
|
local ltn12 = require("ltn12")
|
|
|
-local httpclient = require("fwutils.httpclient")
|
|
|
-local cache = require("fwutils.cache")
|
|
|
+local httpclient = require("httpclient")
|
|
|
|
|
|
|
|
|
local M = {}
|
|
|
@@ -20,7 +19,7 @@ M.url_auth = "https://open.weixin.qq.com/connect/oauth2/authorize"
|
|
|
-- 模板消息
|
|
|
M.url_template_message = "https://api.weixin.qq.com/cgi-bin/message/template/send"
|
|
|
-- 获取 access_token
|
|
|
-M.get_access_token = function(appid, appsecret)
|
|
|
+M.get_access_token = function(appid, appsecret,rds)
|
|
|
-- local value = cache.get_json("wxofficial_info")
|
|
|
-- if value then
|
|
|
-- -- 是否距离过期至少还有5分钟
|
|
|
@@ -38,10 +37,9 @@ M.get_access_token = function(appid, appsecret)
|
|
|
end
|
|
|
|
|
|
|
|
|
-
|
|
|
- -- 先检查有没有过期
|
|
|
- local cache_data = cache.get_json(tostring("wxofficial_info_"..appid))
|
|
|
+ local cache_data = rds:get("wxofficial_info_"..appid)
|
|
|
if cache_data then
|
|
|
+ cache_data = cjson.decode(cache_data)
|
|
|
if cache_data.update_time and cache_data.access_token then
|
|
|
-- 检查是否过期
|
|
|
if os.time() - cache_data.update_time < 7200 then
|
|
|
@@ -51,7 +49,6 @@ M.get_access_token = function(appid, appsecret)
|
|
|
end
|
|
|
|
|
|
|
|
|
-
|
|
|
local result, data = httpclient.get(M.url_get_access_token .. "&appid=" .. appid .. "&secret=" .. appsecret)
|
|
|
if not result then
|
|
|
return false, data
|
|
|
@@ -64,10 +61,10 @@ M.get_access_token = function(appid, appsecret)
|
|
|
|
|
|
|
|
|
-- 更新
|
|
|
- cache.set_json(tostring("wxofficial_info_"..appid),{
|
|
|
+ rds:setex("wxofficial_info_"..appid,7200,cjson.encode({
|
|
|
update_time = os.time(),
|
|
|
access_token = body.access_token
|
|
|
- })
|
|
|
+ }))
|
|
|
return true,body.access_token
|
|
|
|
|
|
|