Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Q
qk_backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
quanku
qk_backend
Commits
c4e34921
Commit
c4e34921
authored
Jan 21, 2025
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
微信音频内容安全识别回调2
parent
ffc8e536
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
218 additions
and
4 deletions
+218
-4
ch-core/src/main/java/com/wwdz/ch/core/api/qiandao/QdWxAppletApi.java
...main/java/com/wwdz/ch/core/api/qiandao/QdWxAppletApi.java
+212
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/qiandao/QdUserServiceImpl.java
...n/java/com/wwdz/ch/wx/impl/qiandao/QdUserServiceImpl.java
+3
-2
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/qiandao/QdUserSignInServiceImpl.java
.../com/wwdz/ch/wx/impl/qiandao/QdUserSignInServiceImpl.java
+3
-2
No files found.
ch-core/src/main/java/com/wwdz/ch/core/api/qiandao/QdWxAppletApi.java
0 → 100644
View file @
c4e34921
package
com.wwdz.ch.core.api.qiandao
;
import
com.wwdz.ch.core.entity.WxCheckMediaRequestDto
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.util.OkHttpUtil
;
import
com.wwdz.ch.core.util.RedisUtils
;
import
com.xxdxxs.utils.JsonUtils
;
import
com.xxdxxs.utils.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
@Component
public
class
QdWxAppletApi
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
QdWxAppletApi
.
class
);
@Value
(
"${dts.qdwx.app-id}"
)
private
String
APPLET_APPID
;
@Value
(
"${dts.qdwx.app-secret}"
)
private
String
APPLET_APP_SECRET
;
@Autowired
RedisUtils
redisUtils
;
/**
* 测试环境和正式环境的url不同,相互隔离不会冲突
*/
@Value
(
"${dts.wx.get-officialaccount-accesstoken-url}"
)
private
String
GET_OFFICIAL_ACCOUNT_ACCESSTOKEN_URL
;
@Value
(
"${dts.wx.auction-msg-url}"
)
private
String
AUCTION_MSG_URL
;
@Autowired
QdWxLoginManager
qdWxLoginManager
;
// 微信小程序音视频内容安全识别地址
private
static
final
String
MEDIA_CHECK_URL
=
"https://api.weixin.qq.com/wxa/media_check_async?access_token=%s"
;
//获取urllink
private
static
final
String
URL_LINK
=
"https://api.weixin.qq.com/wxa/generate_urllink?access_token=%s"
;
//获取用户访问小程序数据日趋势
private
static
final
String
GET_ACCESS_DAY_URL
=
"https://api.weixin.qq.com/datacube/getweanalysisappiddailyvisittrend?access_token=%s"
;
private
static
final
String
GET_ACCESS_WEEK_URL
=
"https://api.weixin.qq.com/datacube/getweanalysisappidweeklyvisittrend?access_token=%s"
;
private
static
final
String
GET_ACCESS_MONTH_URL
=
"https://api.weixin.qq.com/datacube/getweanalysisappidmonthlyvisittrend?access_token=%s"
;
static
Map
<
String
,
String
>
ACCESS_URL_MAP
=
new
HashMap
<>();
static
{
ACCESS_URL_MAP
.
put
(
"day"
,
GET_ACCESS_DAY_URL
);
ACCESS_URL_MAP
.
put
(
"week"
,
GET_ACCESS_WEEK_URL
);
ACCESS_URL_MAP
.
put
(
"month"
,
GET_ACCESS_MONTH_URL
);
}
public
String
checkMedia
(
WxCheckMediaRequestDto
dto
)
{
String
accessToken
=
qdWxLoginManager
.
getAccessToken
();
String
url
=
String
.
format
(
MEDIA_CHECK_URL
,
accessToken
);
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"media_url"
,
dto
.
getMediaUrl
());
map
.
put
(
"media_type"
,
dto
.
getMediaType
());
map
.
put
(
"version"
,
2
);
map
.
put
(
"scene"
,
4
);
map
.
put
(
"openid"
,
dto
.
getWxOpenId
());
okHttpUtil
.
addParams
(
map
);
okHttpUtil
.
post
(
true
);
String
responseStr
=
okHttpUtil
.
async
();
logger
.
info
(
"[checkMedia] response :{}"
,
responseStr
);
return
responseStr
;
}
public
String
getUrlLink
(
String
redirectUrl
,
String
query
)
{
String
urlLink
=
""
;
try
{
String
accessToken
=
qdWxLoginManager
.
getAccessToken
();
String
url
=
String
.
format
(
URL_LINK
,
accessToken
);
StringBuffer
stringBuffer
=
new
StringBuffer
(
redirectUrl
);
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"path"
,
stringBuffer
.
toString
());
map
.
put
(
"query"
,
query
);
map
.
put
(
"is_expire"
,
true
);
map
.
put
(
"expire_type"
,
1
);
map
.
put
(
"expire_interval"
,
1
);
logger
.
info
(
"获取加密URLLink 参数:{}"
,
JsonUtils
.
from
(
map
));
okHttpUtil
.
addParams
(
map
);
okHttpUtil
.
post
(
true
);
String
responseStr
=
okHttpUtil
.
async
();
logger
.
info
(
"获取加密URLLink response :{}"
,
responseStr
);
String
msg
=
JsonUtils
.
getValueByPath
(
responseStr
,
"errmsg"
);
if
(
"ok"
.
equals
(
msg
))
{
urlLink
=
JsonUtils
.
getValueByPath
(
responseStr
,
"url_link"
);
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"获取小程序urlLink失败:{}"
,
e
);
}
return
urlLink
+
" "
;
}
/**
* 获取小程序访问数据
* @param startTime
* @param endTime
* @param key
* @return
*/
public
Result
getAccessData
(
String
startTime
,
String
endTime
,
String
key
)
{
try
{
String
accessToken
=
qdWxLoginManager
.
getAccessToken
();
String
url
=
String
.
format
(
ACCESS_URL_MAP
.
get
(
key
),
accessToken
);
logger
.
info
(
"获取小程序访问数据 URL :{}"
,
url
);
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"begin_date"
,
startTime
);
map
.
put
(
"end_date"
,
endTime
);
logger
.
info
(
"获取加密URLLink 参数:{}"
,
JsonUtils
.
from
(
map
));
okHttpUtil
.
addParams
(
map
);
okHttpUtil
.
post
(
true
);
String
responseStr
=
okHttpUtil
.
async
();
logger
.
info
(
"获取用户访问小程序数据 response :{}"
,
responseStr
);
String
listInfo
=
JsonUtils
.
getValueByPath
(
responseStr
,
"list"
);
List
<
Map
<
String
,
Object
>>
dataList
=
JsonUtils
.
toMapList
(
listInfo
);
//打开次数
int
sessionCnt
=
(
int
)
dataList
.
get
(
0
).
get
(
"session_cnt"
);
//访问次数
int
visitPv
=
(
int
)
dataList
.
get
(
0
).
get
(
"visit_pv"
);
//访问人数
int
visitUv
=
(
int
)
dataList
.
get
(
0
).
get
(
"visit_uv"
);
//新用户数
int
visitUvNew
=
(
int
)
dataList
.
get
(
0
).
get
(
"visit_uv_new"
);
Map
<
String
,
Integer
>
resultMap
=
new
HashMap
<>();
resultMap
.
put
(
"sessionCnt"
,
sessionCnt
);
resultMap
.
put
(
"visitPv"
,
visitPv
);
resultMap
.
put
(
"visitUv"
,
visitUv
);
resultMap
.
put
(
"visitUvNew"
,
visitUvNew
);
return
Result
.
success
(
resultMap
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"获取用户访问小程序数据失败:{}"
,
e
);
}
return
Result
.
failed
();
}
public
String
getAppletAccessToken
()
{
//测试环境
if
(!
GET_OFFICIAL_ACCOUNT_ACCESSTOKEN_URL
.
contains
(
"stable_token"
))
{
String
accessTokenUrl
=
String
.
format
(
GET_OFFICIAL_ACCOUNT_ACCESSTOKEN_URL
,
APPLET_APPID
,
APPLET_APP_SECRET
);
String
res
=
OkHttpUtil
.
builder
().
url
(
accessTokenUrl
)
.
get
().
sync
();
logger
.
info
(
"测试环境获取小程序token返回结果: {}"
,
res
);
String
token
=
JsonUtils
.
getValueByPath
(
res
,
"access_token"
);
return
token
;
}
//正式环境先从缓存中获取,没有再刷新token
//根据商户的appid从redis中获取商户的token
String
token
=
redisUtils
.
hasKey
(
APPLET_APPID
)?
redisUtils
.
get
(
APPLET_APPID
).
toString
()
:
null
;
if
(
StringUtils
.
isEmpty
(
token
))
{
token
=
refreshAppletAccessToken
();
}
return
token
;
}
public
String
refreshAppletAccessToken
()
{
try
{
String
accessTokenUrl
=
null
;
String
responseStr
=
null
;
//正式环境的url中包含了"stable_token", 要使用post请求, 测试环境是get请求
if
(!
GET_OFFICIAL_ACCOUNT_ACCESSTOKEN_URL
.
contains
(
"stable_token"
))
{
accessTokenUrl
=
String
.
format
(
GET_OFFICIAL_ACCOUNT_ACCESSTOKEN_URL
,
APPLET_APPID
,
APPLET_APP_SECRET
);
logger
.
info
(
"测试环境获取小程序access_token url :{}"
,
accessTokenUrl
);
responseStr
=
OkHttpUtil
.
builder
().
url
(
accessTokenUrl
)
.
get
().
sync
();
}
else
{
accessTokenUrl
=
GET_OFFICIAL_ACCOUNT_ACCESSTOKEN_URL
;
logger
.
info
(
"正式环境获取小程序access_token url :{}"
,
accessTokenUrl
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"grant_type"
,
"client_credential"
);
map
.
put
(
"appid"
,
APPLET_APPID
);
map
.
put
(
"secret"
,
APPLET_APP_SECRET
);
responseStr
=
OkHttpUtil
.
builder
().
addParams
(
map
).
url
(
accessTokenUrl
)
.
post
(
true
).
sync
();
}
logger
.
info
(
"小程序刷新access_token response :{}"
,
responseStr
);
if
(!
responseStr
.
contains
(
"access_token"
))
{
String
errorCode
=
JsonUtils
.
getValueByPath
(
responseStr
,
"errcode"
);
String
errmsg
=
JsonUtils
.
getValueByPath
(
responseStr
,
"errmsg"
);
logger
.
error
(
"appid : {}, 小程序获取token出错, errorCode : {}, errmsg : {} "
,
APPLET_APPID
,
errorCode
,
errmsg
);
return
null
;
}
String
token
=
JsonUtils
.
getValueByPath
(
responseStr
,
"access_token"
);
String
expires_in
=
JsonUtils
.
getValueByPath
(
responseStr
,
"expires_in"
);
redisUtils
.
set
(
APPLET_APPID
,
token
,
Long
.
valueOf
(
expires_in
)
-
10
,
TimeUnit
.
SECONDS
);
return
token
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"获取小程序access_token失败"
,
e
);
return
null
;
}
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/qiandao/QdUserServiceImpl.java
View file @
c4e34921
...
...
@@ -3,6 +3,7 @@ package com.wwdz.ch.wx.impl.qiandao;
import
cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult
;
import
com.alibaba.fastjson.JSONObject
;
import
com.wwdz.ch.core.api.WxAppletApi
;
import
com.wwdz.ch.core.api.qiandao.QdWxAppletApi
;
import
com.wwdz.ch.core.api.qiandao.QdWxLoginManager
;
import
com.wwdz.ch.core.consts.CommConsts
;
import
com.wwdz.ch.core.entity.QdUserInfo
;
...
...
@@ -87,7 +88,7 @@ public class QdUserServiceImpl implements QdUserService {
StorageService
storageService
;
@Autowired
WxAppletApi
w
xAppletApi
;
QdWxAppletApi
qdW
xAppletApi
;
@Override
public
Result
regCaptcha
(
QdUserRequestDto
dto
)
{
...
...
@@ -288,7 +289,7 @@ public class QdUserServiceImpl implements QdUserService {
wxCheckMediaRequestDto
.
setMediaType
(
2
);
wxCheckMediaRequestDto
.
setMediaUrl
(
dto
.
getAvatar
());
wxCheckMediaRequestDto
.
setWxOpenId
(
user
.
getWxOpenid
());
w
xAppletApi
.
checkMedia
(
wxCheckMediaRequestDto
);
qdW
xAppletApi
.
checkMedia
(
wxCheckMediaRequestDto
);
logger
.
info
(
"=========== 微信音频内容安全识别接口调用成功 ==========="
);
}
user
.
setAvatar
(
dto
.
getAvatar
());
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/qiandao/QdUserSignInServiceImpl.java
View file @
c4e34921
package
com.wwdz.ch.wx.impl.qiandao
;
import
com.wwdz.ch.core.api.WxAppletApi
;
import
com.wwdz.ch.core.api.qiandao.QdWxAppletApi
;
import
com.wwdz.ch.core.api.wxpay.WxPayServiceApi
;
import
com.wwdz.ch.core.consts.CommConsts
;
import
com.wwdz.ch.core.consts.DistributionEnum
;
...
...
@@ -62,7 +63,7 @@ public class QdUserSignInServiceImpl implements QdUserSignInService {
QdUserSignInTaskDao
qdUserSignInTaskDao
;
@Autowired
WxAppletApi
w
xAppletApi
;
QdWxAppletApi
qdW
xAppletApi
;
@Override
...
...
@@ -143,7 +144,7 @@ public class QdUserSignInServiceImpl implements QdUserSignInService {
//查询用户openid
QdUser
user
=
qdUserDao
.
queryById
(
dto
.
getUserId
());
wxCheckMediaRequestDto
.
setWxOpenId
(
user
.
getWxOpenid
());
w
xAppletApi
.
checkMedia
(
wxCheckMediaRequestDto
);
qdW
xAppletApi
.
checkMedia
(
wxCheckMediaRequestDto
);
logger
.
info
(
"=========== 微信音频内容安全识别接口调用成功 ==========="
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment