Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
数据应用
ThinkLibrary
提交
a6da99d8
T
ThinkLibrary
项目概览
数据应用
/
ThinkLibrary
通知
2
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
代码片段
项目成员
Pages
T
ThinkLibrary
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a6da99d8
编写于
5月 29, 2020
作者:
李光春
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
- 修复助手函数增加缓存
上级
9fa92f05
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
70 addition
and
16 deletion
+70
-16
src/service/wechat/MiniService.php
src/service/wechat/MiniService.php
+44
-8
src/service/wechat/WebAppService.php
src/service/wechat/WebAppService.php
+26
-8
未找到文件。
src/service/wechat/MiniService.php
浏览文件 @
a6da99d8
...
...
@@ -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
;
...
...
src/service/wechat/WebAppService.php
浏览文件 @
a6da99d8
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录