Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
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
项目统一框架
amos-boot-biz
Commits
7001fde2
Commit
7001fde2
authored
Sep 23, 2021
by
kongfm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tzs-微信公众号 根据code 返回注册用户电话信息及openid
parent
40af7ccc
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
81 additions
and
10 deletions
+81
-10
WechatAccessDto.java
...yeejoin/amos/boot/module/tzs/api/dto/WechatAccessDto.java
+22
-0
IWechatService.java
...join/amos/boot/module/tzs/api/service/IWechatService.java
+6
-0
WechatController.java
...amos/boot/module/tzs/biz/controller/WechatController.java
+28
-2
WechatRelationController.java
...t/module/tzs/biz/controller/WechatRelationController.java
+1
-1
WechatServiceImpl.java
...s/boot/module/tzs/biz/service/impl/WechatServiceImpl.java
+23
-6
application-dev.properties
...-system-tzs/src/main/resources/application-dev.properties
+1
-1
No files found.
amos-boot-module/amos-boot-module-api/amos-boot-module-tzs-api/src/main/java/com/yeejoin/amos/boot/module/tzs/api/dto/WechatAccessDto.java
0 → 100644
View file @
7001fde2
package
com
.
yeejoin
.
amos
.
boot
.
module
.
tzs
.
api
.
dto
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/**
* 通话记录附件
*
* @author kongfm
* @date 2021-09-23
*/
@Data
@ApiModel
(
value
=
"WechatAccessDto"
,
description
=
"微信认证dto"
)
public
class
WechatAccessDto
{
@ApiModelProperty
(
value
=
"微信openId"
)
private
String
openId
;
@ApiModelProperty
(
value
=
"手机号"
)
private
String
tel
;
}
amos-boot-module/amos-boot-module-api/amos-boot-module-tzs-api/src/main/java/com/yeejoin/amos/boot/module/tzs/api/service/IWechatService.java
View file @
7001fde2
...
...
@@ -11,4 +11,10 @@ public interface IWechatService {
* @return
*/
String
getAccessToken
();
/**
* 获取微信openId
* @return
*/
String
getOpenId
(
String
code
);
}
amos-boot-module/amos-boot-module-biz/amos-boot-module-tzs-biz/src/main/java/com/yeejoin/amos/boot/module/tzs/biz/controller/WechatController.java
View file @
7001fde2
package
com
.
yeejoin
.
amos
.
boot
.
module
.
tzs
.
biz
.
controller
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.yeejoin.amos.boot.biz.common.controller.BaseController
;
import
com.yeejoin.amos.boot.biz.common.utils.RedisUtils
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.WechatAccessDto
;
import
com.yeejoin.amos.boot.module.tzs.api.entity.WechatRelation
;
import
com.yeejoin.amos.boot.module.tzs.api.service.IWechatService
;
import
com.yeejoin.amos.boot.module.tzs.biz.service.impl.WechatRelationServiceImpl
;
import
com.yeejoin.amos.component.feign.model.FeignClientResult
;
import
com.yeejoin.amos.feign.systemctl.Systemctl
;
import
com.yeejoin.amos.feign.systemctl.model.SmsRecordModel
;
...
...
@@ -55,6 +59,9 @@ public class WechatController extends BaseController {
@Autowired
private
IWechatService
wechatService
;
@Autowired
WechatRelationServiceImpl
wechatRelationServiceImpl
;
/**
...
...
@@ -134,7 +141,7 @@ public class WechatController extends BaseController {
*
* @return
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
,
needAuth
=
false
)
@GetMapping
(
value
=
"/getAccessToken"
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"获取token信息"
,
notes
=
"获取token信息"
)
public
ResponseModel
<
String
>
getAccessToken
()
{
...
...
@@ -167,7 +174,26 @@ public class WechatController extends BaseController {
}
/**
* 根据微信code获取openId和手机号接口
*
* @return
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
,
needAuth
=
false
)
@GetMapping
(
value
=
"/getOpenIdTel/{code}"
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"根据微信code获取openId和手机号接口"
,
notes
=
"根据微信code获取openId和手机号接口"
)
public
ResponseModel
<
WechatAccessDto
>
getAccessToken
(
@PathVariable
String
code
)
{
WechatAccessDto
wechatAccessDto
=
new
WechatAccessDto
();
String
openId
=
wechatService
.
getOpenId
(
code
);
if
(
StringUtils
.
isNotEmpty
(
openId
))
{
wechatAccessDto
.
setOpenId
(
openId
);
WechatRelation
temp
=
wechatRelationServiceImpl
.
getOne
(
new
LambdaQueryWrapper
<
WechatRelation
>().
eq
(
WechatRelation:
:
getOpenId
,
openId
));
if
(
temp
!=
null
)
{
wechatAccessDto
.
setTel
(
temp
.
getPhone
());
}
}
return
ResponseHelper
.
buildResponse
(
wechatAccessDto
);
}
public
static
String
getrandom
(){
String
code
=
""
;
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-tzs-biz/src/main/java/com/yeejoin/amos/boot/module/tzs/biz/controller/WechatRelationController.java
View file @
7001fde2
...
...
@@ -27,7 +27,7 @@ import org.typroject.tyboot.core.foundation.enumeration.UserType;
* @date 2021-09-22
*/
@RestController
@Api
(
tags
=
"
微信公众号openid与电话号对应关系表Api
"
)
@Api
(
tags
=
"
openId与手机号对应关系表
"
)
@RequestMapping
(
value
=
"/wechat-relation"
)
public
class
WechatRelationController
extends
BaseController
{
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-tzs-biz/src/main/java/com/yeejoin/amos/boot/module/tzs/biz/service/impl/WechatServiceImpl.java
View file @
7001fde2
...
...
@@ -42,7 +42,7 @@ public class WechatServiceImpl implements IWechatService {
Object
obj
=
redisUtils
.
get
(
RedisKey
.
WECHAT_TOKEN
);
return
obj
.
toString
();
}
else
{
String
tokenAccessUrl
=
wechatUrl
+
"/token?grant_type=client_credential&appid="
+
APP_ID
+
"&secret="
+
SECRET_KEY
;
String
tokenAccessUrl
=
wechatUrl
+
"/
cgi-bin/
token?grant_type=client_credential&appid="
+
APP_ID
+
"&secret="
+
SECRET_KEY
;
String
responseStr
=
HttpUtils
.
doGet
(
tokenAccessUrl
);
JSONObject
response
=
null
;
try
{
...
...
@@ -64,10 +64,26 @@ public class WechatServiceImpl implements IWechatService {
}
}
@Override
public
String
getOpenId
(
String
code
)
{
String
openIdUrl
=
wechatUrl
+
"/sns/oauth2/access_token?appid="
+
APP_ID
+
"&secret="
+
SECRET_KEY
+
"&code="
+
code
+
"&grant_type=authorization_code"
;
String
responseStr
=
HttpUtils
.
doGet
(
openIdUrl
);
JSONObject
response
=
null
;
try
{
response
=
JSONObject
.
parseObject
(
responseStr
);
}
catch
(
Exception
e
)
{
throw
new
BadRequest
(
"获取openId 出错:"
+
e
.
getMessage
());
}
if
(
response
.
get
(
"openid"
)
!=
null
)
{
// 获取token 成功
try
{
String
openid
=
response
.
getString
(
"openid"
);
return
openid
;
}
catch
(
Exception
e
)
{
throw
new
BadRequest
(
"获取openId 出错:"
+
e
.
getMessage
());
}
}
else
{
throw
new
BadRequest
(
"获取openId 出错"
+
response
);
}
}
}
\ No newline at end of file
amos-boot-system-tzs/src/main/resources/application-dev.properties
View file @
7001fde2
...
...
@@ -41,7 +41,7 @@ tzs.cti.appkey=4e805006-3fef-ae43-3915-a153731007c4
tzs.cti.secretkey
=
7bd29115-99ee-4f7d-1fb1-7c4719d5f43a
tzs.cti.url
=
http://36.46.151.113:8000
tzs.wechat.url
=
https://api.weixin.qq.com
/cgi-bin
tzs.wechat.url
=
https://api.weixin.qq.com
##wechatAPPID
tzs.wechat.appid
=
wx8918c1aaad956617
##wechatSECRET
...
...
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