提交 a6da99d8 编写于 作者: 李光春's avatar 李光春

- 修复助手函数增加缓存

上级 9fa92f05
......@@ -22,6 +22,9 @@ use DtApp\ThinkLibrary\exception\CurlException;
use DtApp\ThinkLibrary\exception\WeChatException;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/**
* 微信小程序
......@@ -92,6 +95,9 @@ class MiniService extends Service
* @return bool|mixed|string
* @throws CacheException
* @throws CurlException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function getPaidUnionId(string $openid)
......@@ -111,6 +117,9 @@ class MiniService extends Service
* @return array|bool|mixed|string
* @throws CacheException
* @throws CurlException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function createWxaQrCode(array $data = [])
......@@ -132,6 +141,9 @@ class MiniService extends Service
* @return array|bool|mixed|string
* @throws CacheException
* @throws CurlException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function getWxaCode(array $data = [])
......@@ -153,6 +165,9 @@ class MiniService extends Service
* @return array|bool|mixed|string
* @throws CacheException
* @throws CurlException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function getWxaCodeUnLimit(array $data = [])
......@@ -174,6 +189,9 @@ class MiniService extends Service
* @return bool|mixed|string
* @throws CacheException
* @throws CurlException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function addTemplate(array $data = [])
......@@ -194,6 +212,9 @@ class MiniService extends Service
* @return bool|mixed|string
* @throws CacheException
* @throws CurlException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function deleteTemplate(string $priTmplId)
......@@ -216,6 +237,9 @@ class MiniService extends Service
* @return bool|mixed|string
* @throws CacheException
* @throws CurlException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function getCategory()
......@@ -235,6 +259,9 @@ class MiniService extends Service
* @return bool|mixed|string
* @throws CacheException
* @throws CurlException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function getPubTemplateKeyWordsById(string $tid)
......@@ -258,6 +285,9 @@ class MiniService extends Service
* @return bool|mixed|string
* @throws CacheException
* @throws CurlException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function getPubTemplateTitleList(array $data = [])
......@@ -277,6 +307,9 @@ class MiniService extends Service
* @return bool|mixed|string
* @throws CacheException
* @throws CurlException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function getTemplateList()
......@@ -296,6 +329,9 @@ class MiniService extends Service
* @return bool|mixed|string
* @throws CacheException
* @throws CurlException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function subscribeMessageSend(array $data = [])
......@@ -368,6 +404,9 @@ class MiniService extends Service
* @return bool|mixed|string
* @throws CacheException
* @throws CurlException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function accessToken()
......@@ -382,6 +421,9 @@ class MiniService extends Service
* @throws CacheException
* @throws CurlException
* @throws WeChatException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
private function getAccessToken()
{
......@@ -430,20 +472,14 @@ class MiniService extends Service
// 文件名
$file = "{$this->app_id}_access_token";
// 获取数据
$cache_mysql = new Mysql();
$cache_mysql_value = $cache_mysql
->name($file)
->get();
$cache_mysql_value = dtacache($file);
if (!empty($cache_mysql_value)) {
$access_token['access_token'] = $cache_mysql_value;
} else {
$accessToken_res = HttpService::instance()
->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->toArray();
$cache_mysql
->name($file)
->expire(6000)
->set($accessToken_res['access_token']);
dtacache($file, $accessToken_res['access_token'], 6000);
$access_token['access_token'] = $accessToken_res['access_token'];
}
return $access_token;
......
......@@ -24,6 +24,9 @@ use DtApp\ThinkLibrary\facade\Pregs;
use DtApp\ThinkLibrary\facade\Urls;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/**
* 公众号
......@@ -240,6 +243,9 @@ class WebAppService extends Service
* @return array
* @throws CacheException
* @throws CurlException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function share()
......@@ -286,6 +292,9 @@ class WebAppService extends Service
* @return array|bool|mixed|string
* @throws CacheException
* @throws CurlException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function qrCode(array $data)
......@@ -305,6 +314,9 @@ class WebAppService extends Service
* @return array|bool|mixed|string
* @throws CacheException
* @throws CurlException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function messageTemplateSend(array $data = [])
......@@ -327,6 +339,9 @@ class WebAppService extends Service
* @return bool|mixed|string
* @throws CacheException
* @throws CurlException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function setIndustry(string $access_token, array $data = [])
......@@ -347,6 +362,9 @@ class WebAppService extends Service
* @return bool
* @throws CacheException
* @throws CurlException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function shortUrl(string $long_url)
......@@ -370,6 +388,9 @@ class WebAppService extends Service
* @return array|bool|mixed|string
* @throws CacheException
* @throws CurlException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function fiNihPageSet(array $data = [])
......@@ -391,6 +412,9 @@ class WebAppService extends Service
* @throws CacheException
* @throws CurlException
* @throws WeChatException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
private function getAccessToken()
{
......@@ -440,20 +464,14 @@ class WebAppService extends Service
// 文件名
$file = "{$this->app_id}_access_token";
// 获取数据
$cache_mysql = new Mysql();
$cache_mysql_value = $cache_mysql
->name($file)
->get();
$cache_mysql_value = dtacache($file);
if (!empty($cache_mysql_value)) {
$access_token['access_token'] = $cache_mysql_value;
} else {
$accessToken_res = HttpService::instance()
->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->toArray();
$cache_mysql
->name($file)
->expire(6000)
->set($accessToken_res['access_token']);
dtacache($file, $accessToken_res['access_token'], 6000);
$access_token['access_token'] = $accessToken_res['access_token'];
}
return $access_token;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册