Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
shop
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
shop
Commits
6a6b73cf
Commit
6a6b73cf
authored
Dec 13, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
55d1e124
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
797 additions
and
12 deletions
+797
-12
QiyeWxService.java
src/main/java/com/egolm/shop/api/service/QiyeWxService.java
+85
-0
WeixinTokenService.java
...n/java/com/egolm/shop/api/service/WeixinTokenService.java
+0
-5
QiyeWxServiceImpl.java
...va/com/egolm/shop/api/service/impl/QiyeWxServiceImpl.java
+98
-0
WeixinTokenServiceImpl.java
...m/egolm/shop/api/service/impl/WeixinTokenServiceImpl.java
+0
-7
HttpUtil.java
src/main/java/com/egolm/shop/common/utils/HttpUtil.java
+608
-0
application.properties
src/main/resources/application.properties
+6
-0
No files found.
src/main/java/com/egolm/shop/api/service/QiyeWxService.java
0 → 100644
View file @
6a6b73cf
package
com
.
egolm
.
shop
.
api
.
service
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
public
interface
QiyeWxService
{
long
DevTime
=
1000
*
60
*
15
;
String
PrefixRedisTokenKey
=
"AccessTokenRedis_"
;
String
UrlGetToken
=
"/gettoken?corpid={0}&corpsecret={1}"
;
String
UrlSendMsg
=
"/message/send?access_token={0}"
;
String
getTokenString
();
void
refreshToken
();
void
sendMessage
(
WxMessage
wxMessage
);
public
static
class
WxMessage
{
String
touser
;
String
msgtype
=
"miniprogram_notice"
;
MiniprogramNotice
miniprogram_notice
;
public
String
getTouser
()
{
return
touser
;
}
public
void
setTouser
(
String
touser
)
{
this
.
touser
=
touser
;
}
public
String
getMsgtype
()
{
return
msgtype
;
}
public
void
setMsgtype
(
String
msgtype
)
{
this
.
msgtype
=
msgtype
;
}
public
MiniprogramNotice
getMiniprogram_notice
()
{
return
miniprogram_notice
;
}
public
void
setMiniprogram_notice
(
MiniprogramNotice
miniprogram_notice
)
{
this
.
miniprogram_notice
=
miniprogram_notice
;
}
public
static
class
MiniprogramNotice
{
String
appid
;
String
page
;
String
title
;
String
description
;
Boolean
emphasis_first_item
=
true
;
List
<
Map
<
String
,
String
>>
content_item
=
new
ArrayList
<
Map
<
String
,
String
>>();
public
String
getAppid
()
{
return
appid
;
}
public
void
setAppid
(
String
appid
)
{
this
.
appid
=
appid
;
}
public
String
getPage
()
{
return
page
;
}
public
void
setPage
(
String
page
)
{
this
.
page
=
page
;
}
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
public
Boolean
getEmphasis_first_item
()
{
return
emphasis_first_item
;
}
public
void
setEmphasis_first_item
(
Boolean
emphasis_first_item
)
{
this
.
emphasis_first_item
=
emphasis_first_item
;
}
public
List
<
Map
<
String
,
String
>>
getContent_item
()
{
return
content_item
;
}
public
void
setContent_item
(
List
<
Map
<
String
,
String
>>
content_item
)
{
this
.
content_item
=
content_item
;
}
}
}
}
src/main/java/com/egolm/shop/api/service/WeixinTokenService.java
deleted
100644 → 0
View file @
55d1e124
package
com
.
egolm
.
shop
.
api
.
service
;
public
interface
WeixinTokenService
{
}
src/main/java/com/egolm/shop/api/service/impl/QiyeWxServiceImpl.java
0 → 100644
View file @
6a6b73cf
package
com
.
egolm
.
shop
.
api
.
service
.
impl
;
import
java.text.MessageFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.egolm.common.DateUtil
;
import
com.egolm.common.StringUtil
;
import
com.egolm.shop.api.service.QiyeWxService
;
import
com.egolm.shop.common.utils.HttpUtil
;
import
com.egolm.shop.common.utils.HttpUtil.HttpReqObject
;
import
com.egolm.shop.common.utils.HttpUtil.HttpRespObject
;
import
com.egolm.shop.common.utils.HttpUtil.JsonReqObject
;
import
com.egolm.shop.common.utils.HttpUtil.SSLVersion
;
public
class
QiyeWxServiceImpl
implements
QiyeWxService
{
@Value
(
"${qiyewx.corpid}"
)
private
String
corpid
;
@Value
(
"${qiyewx.corpsecret}"
)
private
String
corpsecret
;
@Value
(
"${qiyewx.baseUrl}"
)
private
String
baseUrl
;
@Autowired
private
RedisTemplate
<
String
,
String
>
redis
;
@Override
public
String
getTokenString
()
{
String
redisCacheKey
=
PrefixRedisTokenKey
+
corpid
;
Long
systemTime
=
System
.
currentTimeMillis
();
String
tokenObjectString
=
redis
.
opsForValue
().
get
(
redisCacheKey
);
if
(
StringUtil
.
isNotBlank
(
tokenObjectString
))
{
JSONObject
tokenObject
=
JSON
.
parseObject
(
tokenObjectString
);
Integer
errcode
=
tokenObject
.
getInteger
(
"errcode"
);
if
(
errcode
==
0
)
{
Long
expires_in
=
tokenObject
.
getLong
(
"expires_in"
);
String
loadTimeString
=
tokenObject
.
getString
(
"loadTime"
);
if
(
expires_in
!=
null
&&
StringUtil
.
isNotBlank
(
loadTimeString
))
{
Date
loadTime
=
DateUtil
.
parse
(
loadTimeString
,
"yyyy-MM-dd HH:mm:ss"
);
Long
expireTime
=
loadTime
.
getTime
()
+
(
expires_in
*
1000L
);
if
((
expireTime
-
DevTime
)
>
systemTime
)
{
String
access_token
=
tokenObject
.
getString
(
"access_token"
);
if
(
StringUtil
.
isNotBlank
(
access_token
))
{
return
access_token
;
}
}
}
}
}
String
requestUrl
=
baseUrl
+
MessageFormat
.
format
(
UrlGetToken
,
corpid
,
corpsecret
);
HttpRespObject
resp
=
HttpUtil
.
newInstance
().
setSSLVersion
(
SSLVersion
.
SSLv3
).
post
(
new
HttpReqObject
(
requestUrl
,
null
,
null
));
if
(
resp
.
getHttpCode
()
==
200
)
{
String
text
=
resp
.
getResponseBody
();
JSONObject
tokenObject
=
JSON
.
parseObject
(
text
);
Integer
code
=
tokenObject
.
getInteger
(
"errcode"
);
if
(
code
==
0
)
{
tokenObject
.
put
(
"loadTime"
,
DateUtil
.
format
(
new
Date
(),
"yyyy-MM-dd HH:mm:ss"
));
redis
.
opsForValue
().
set
(
redisCacheKey
,
tokenObject
.
toJSONString
());
return
tokenObject
.
getString
(
"access_token"
);
}
}
return
null
;
}
@Override
public
void
refreshToken
()
{
String
redisCacheKey
=
PrefixRedisTokenKey
+
corpid
;
redis
.
delete
(
redisCacheKey
);
}
@Override
public
void
sendMessage
(
WxMessage
wxMessage
)
{
String
tokenString
=
this
.
getTokenString
();
String
requestUrl
=
baseUrl
+
MessageFormat
.
format
(
UrlSendMsg
,
tokenString
);
Map
<
String
,
String
>
headers
=
new
HashMap
<
String
,
String
>();
headers
.
put
(
"content-type"
,
"application/x-www-form-urlencoded"
);
HttpRespObject
resp
=
HttpUtil
.
newInstance
().
setSSLVersion
(
SSLVersion
.
SSLv3
).
postJson
(
new
JsonReqObject
(
requestUrl
,
wxMessage
,
headers
));
Integer
httpCode
=
resp
.
getHttpCode
();
if
(
httpCode
==
200
)
{
}
}
}
src/main/java/com/egolm/shop/api/service/impl/WeixinTokenServiceImpl.java
deleted
100644 → 0
View file @
55d1e124
package
com
.
egolm
.
shop
.
api
.
service
.
impl
;
import
com.egolm.shop.api.service.WeixinTokenService
;
public
class
WeixinTokenServiceImpl
implements
WeixinTokenService
{
}
src/main/java/com/egolm/shop/common/utils/HttpUtil.java
0 → 100644
View file @
6a6b73cf
This diff is collapsed.
Click to expand it.
src/main/resources/application.properties
View file @
6a6b73cf
...
@@ -76,3 +76,9 @@ redis.guest.key=B2B_Guest
...
@@ -76,3 +76,9 @@ redis.guest.key=B2B_Guest
redis.sms.code.key
=
B2B_Sms
redis.sms.code.key
=
B2B_Sms
qiyewx.corpid
=
ww0e86cf527e3e5218
qiyewx.corpsecret
=
n6weRHp134mpOF3AUPuyEDrUW8zdoG22wuk1hyfXuZAz
qiyewx.baseUrl
=
https://qyapi.weixin.qq.com/cgi-bin
qiyewx.msg.redirect.appid
=
wxa573a87e45933b56
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