记得上下班打卡 | git大法好,push需谨慎
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liquidnet-bus-v1
Project
Project
Details
Activity
Releases
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
董敬伟
liquidnet-bus-v1
Commits
c6971d1a
Commit
c6971d1a
authored
Aug 17, 2021
by
胡佳晨
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev-sweet' into dev-sweet
parents
6886334c
fde8b8dd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
218 additions
and
0 deletions
+218
-0
WechatMpConfigure.java
...com/liquidnet/service/sweet/config/WechatMpConfigure.java
+53
-0
SweetWechatSyncDataController.java
...rvice/sweet/controller/SweetWechatSyncDataController.java
+71
-0
SweetWechatMpService.java
...dnet/service/sweet/service/impl/SweetWechatMpService.java
+94
-0
No files found.
liquidnet-bus-service/liquidnet-service-sweet/src/main/java/com/liquidnet/service/sweet/config/WechatMpConfigure.java
0 → 100644
View file @
c6971d1a
package
com
.
liquidnet
.
service
.
sweet
.
config
;
import
me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps
;
import
me.chanjar.weixin.mp.api.WxMpService
;
import
me.chanjar.weixin.mp.api.impl.WxMpServiceImpl
;
import
me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
javax.annotation.PostConstruct
;
@Configuration
public
class
WechatMpConfigure
{
private
static
String
appidZhengzai
;
private
static
String
secretZhengzai
;
@Value
(
"${liquidnet.wechat.service.zhengzai.appid}"
)
public
void
setAppidZhengzai
(
String
appidZhengzai
)
{
WechatMpConfigure
.
appidZhengzai
=
appidZhengzai
;
}
@Value
(
"${liquidnet.wechat.service.zhengzai.secret}"
)
public
void
setSecretZhengzai
(
String
secretZhengzai
)
{
WechatMpConfigure
.
secretZhengzai
=
secretZhengzai
;
}
private
WxMpService
wxMpZhengzaiService
;
@Autowired
private
StringRedisTemplate
stringRedisTemplate
;
@PostConstruct
public
void
init
()
{
wxMpZhengzaiService
=
new
WxMpServiceImpl
()
{
{
RedisTemplateWxRedisOps
redisTemplateWxRedisOps
=
new
RedisTemplateWxRedisOps
(
stringRedisTemplate
);
WxMpRedisConfigImpl
wxMpDefaultConfig
=
new
WxMpRedisConfigImpl
(
redisTemplateWxRedisOps
,
"sweet:accessToken:service:zhengzai"
);
// WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
wxMpDefaultConfig
.
setAppId
(
appidZhengzai
);
wxMpDefaultConfig
.
setSecret
(
secretZhengzai
);
this
.
setWxMpConfigStorage
(
wxMpDefaultConfig
);
}
};
}
public
WxMpService
getWxMpService
()
{
return
wxMpZhengzaiService
;
}
}
liquidnet-bus-service/liquidnet-service-sweet/src/main/java/com/liquidnet/service/sweet/controller/SweetWechatSyncDataController.java
0 → 100644
View file @
c6971d1a
package
com
.
liquidnet
.
service
.
sweet
.
controller
;
import
com.liquidnet.commons.lang.util.HttpUtil
;
import
com.liquidnet.service.sweet.service.impl.SweetWechatMpService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.io.*
;
@Api
(
tags
=
"同步微信用户数据"
)
@RestController
@RequestMapping
(
"/wechatSync"
)
public
class
SweetWechatSyncDataController
{
@Value
(
"${liquidnet.wechat.service.zhengzai.appid}"
)
private
String
zhengzaiAppid
;
@Value
(
"${liquidnet.wechat.service.zhengzai.secret}"
)
private
String
zhengzaiSecret
;
@Autowired
private
SweetWechatMpService
sweetWechatMpService
;
@GetMapping
(
"regMobile"
)
@ApiOperation
(
"注册"
)
public
void
regMobile
()
throws
IOException
{
String
filePath
=
"/Users/jiangxiulong/Desktop/keys2.txt"
;
String
encoding
=
"UTF-8"
;
File
file
=
new
File
(
filePath
);
if
(
file
.
isFile
()
&&
file
.
exists
())
{
//判断文件是否存在
InputStreamReader
read
=
new
InputStreamReader
(
new
FileInputStream
(
file
),
encoding
);
//考虑到编码格式
BufferedReader
bufferedReader
=
new
BufferedReader
(
read
);
String
mobile
=
null
;
while
((
mobile
=
bufferedReader
.
readLine
())
!=
null
)
{
System
.
out
.
println
(
mobile
);
try
{
MultiValueMap
<
String
,
String
>
params
=
new
LinkedMultiValueMap
();
params
.
add
(
"mobile"
,
mobile
);
// String url = "http://127.0.0.1:9001/adam/rsc/reg/mobile";
String
url
=
"http://testadam.zhengzai.tv/adam/rsc/reg/mobile"
;
HttpUtil
.
post
(
url
,
params
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
read
.
close
();
}
else
{
System
.
out
.
println
(
"找不到指定的文件"
);
}
}
@GetMapping
(
"users"
)
@ApiOperation
(
"关注用户"
)
public
void
getUsers
()
{
try
{
sweetWechatMpService
.
userInfo
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
liquidnet-bus-service/liquidnet-service-sweet/src/main/java/com/liquidnet/service/sweet/service/impl/SweetWechatMpService.java
0 → 100644
View file @
c6971d1a
package
com
.
liquidnet
.
service
.
sweet
.
service
.
impl
;
import
com.liquidnet.commons.lang.util.CollectionUtil
;
import
com.liquidnet.commons.lang.util.DateUtil
;
import
com.liquidnet.commons.lang.util.IDGenerator
;
import
com.liquidnet.service.base.SqlMapping
;
import
com.liquidnet.service.base.constant.MQConst
;
import
com.liquidnet.service.sweet.config.WechatMpConfigure
;
import
com.liquidnet.service.sweet.entity.SweetWechatUser
;
import
com.liquidnet.service.sweet.utils.QueueUtils
;
import
com.liquidnet.service.sweet.utils.RedisDataUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
me.chanjar.weixin.common.error.WxErrorException
;
import
me.chanjar.weixin.mp.api.WxMpService
;
import
me.chanjar.weixin.mp.bean.result.WxMpUser
;
import
me.chanjar.weixin.mp.bean.result.WxMpUserList
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.LinkedList
;
import
java.util.List
;
@Slf4j
@Service
public
class
SweetWechatMpService
{
@Autowired
WechatMpConfigure
wechatMpConfigure
;
@Autowired
private
RedisDataUtils
redisDataUtils
;
@Autowired
private
QueueUtils
queueUtils
;
@Autowired
private
SweetWechatTemplateServiceImpl
sweetWechatTemplateService
;
public
void
userInfo
()
throws
WxErrorException
{
WxMpService
wxMpService
=
wechatMpConfigure
.
getWxMpService
();
log
.
info
(
"isAccessTokenExpired:[{}] "
,
wxMpService
.
getWxMpConfigStorage
().
isAccessTokenExpired
());
log
.
info
(
"getAccessToken:[{}] "
,
wxMpService
.
getWxMpConfigStorage
().
getAccessToken
());
String
nextOpenid
=
""
;
do
{
WxMpUserList
wxMpUserList
=
wxMpService
.
getUserService
().
userList
(
nextOpenid
);
int
count
=
wxMpUserList
.
getCount
();
long
total
=
wxMpUserList
.
getTotal
();
List
<
String
>
openids
=
wxMpUserList
.
getOpenids
();
nextOpenid
=
wxMpUserList
.
getNextOpenid
();
log
.
info
(
"count:[{}] "
,
count
);
log
.
info
(
"total:[{}] "
,
total
);
// log.info("openids:[{}] ", openids);
log
.
info
(
"nextOpenid:[{}] "
,
nextOpenid
);
for
(
String
openId
:
openids
)
{
WxMpUser
wxMpUser
=
wxMpService
.
getUserService
().
userInfo
(
openId
);
log
.
info
(
"openId:[{}],wxMpUsers:[{}]"
,
openId
,
wxMpUser
);
SweetWechatUser
userInfo
=
redisDataUtils
.
getSweetWechatUser
(
wxMpUser
.
getUnionId
());
if
(
null
==
userInfo
)
{
SweetWechatUser
sweetWechatUser
=
SweetWechatUser
.
getNew
();
sweetWechatUser
.
setOpenId
(
wxMpUser
.
getOpenId
());
sweetWechatUser
.
setUnionId
(
wxMpUser
.
getUnionId
());
sweetWechatUser
.
setNickname
(
wxMpUser
.
getNickname
());
sweetWechatUser
.
setSexDesc
(
wxMpUser
.
getSexDesc
());
sweetWechatUser
.
setSex
(
wxMpUser
.
getSex
());
sweetWechatUser
.
setHeadImgUrl
(
wxMpUser
.
getHeadImgUrl
());
sweetWechatUser
.
setLanguage
(
wxMpUser
.
getLanguage
());
sweetWechatUser
.
setCountry
(
wxMpUser
.
getCountry
());
sweetWechatUser
.
setProvince
(
wxMpUser
.
getProvince
());
sweetWechatUser
.
setCity
(
wxMpUser
.
getCity
());
sweetWechatUser
.
setSubscribeTime
(
DateUtil
.
ofEpochMilli
(
wxMpUser
.
getSubscribeTime
()));
sweetWechatUser
.
setSubscribeScene
(
wxMpUser
.
getSubscribeScene
());
sweetWechatUser
.
setUserId
(
IDGenerator
.
nextSnowId
());
LinkedList
<
String
>
sqls
=
CollectionUtil
.
linkedListString
();
LinkedList
<
Object
[]>
sqlsDataA
=
CollectionUtil
.
linkedListObjectArr
();
sqls
.
add
(
SqlMapping
.
get
(
"sweet_user.insert"
));
sqlsDataA
.
add
(
new
Object
[]{
sweetWechatUser
.
getUserId
(),
sweetWechatUser
.
getOpenId
(),
sweetWechatUser
.
getUnionId
(),
sweetWechatUser
.
getNickname
(),
sweetWechatUser
.
getSexDesc
(),
sweetWechatUser
.
getSex
(),
sweetWechatUser
.
getHeadImgUrl
(),
sweetWechatUser
.
getLanguage
(),
sweetWechatUser
.
getCountry
(),
sweetWechatUser
.
getProvince
(),
sweetWechatUser
.
getCity
(),
sweetWechatUser
.
getSubscribeTime
(),
sweetWechatUser
.
getSubscribeScene
()
});
queueUtils
.
sendMsgByRedis
(
MQConst
.
SweetQueue
.
SWEET_USER_INSERT_DRAW
.
getKey
(),
SqlMapping
.
gets
(
sqls
,
sqlsDataA
));
// 入缓存
redisDataUtils
.
setSweetWechatUser
(
sweetWechatUser
);
}
}
}
while
(!
nextOpenid
.
isEmpty
());
}
}
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