Commit 2570bf6c authored by 竹天卫's avatar 竹天卫

委托优化

parent 1097cf30
......@@ -25,17 +25,30 @@ public class WeiXinController {
@Autowired
private WeiXinService weiXinService;
@ApiOperation(value = "获取登录token")
@GetMapping("/getToken")
public BaseResponse getToken(String code){
@ApiOperation(value = "获取登录token-小程序端")
@GetMapping("/getXCXToken")
public BaseResponse getXCXToken(String code){
try {
return weiXinService.getToken(code);
return weiXinService.getToken(code,"APP");
}catch (Exception e){
log.debug("获取登录token{}",e);
}
return BaseResponse.errorMsg("失败!");
}
@ApiOperation(value = "获取登录token-管理端")
@GetMapping("/getPCToken")
public BaseResponse getPCToken(String code){
try {
return weiXinService.getToken(code, "PC");
}catch (Exception e){
log.debug("获取登录token{}",e);
}
return BaseResponse.errorMsg("失败!");
}
@ApiOperation(value = "当前登录用户")
@GetMapping("/getLoginUser")
public BaseResponse getLoginUser(){
......
......@@ -29,6 +29,8 @@ public class WeiXinService {
private String corpid;
@Value("${weixin.corpsecret}")
private String corpsecret;
@Value("${weixin.corpsecretPC}")
private String corpsecretPC;
@Autowired
private ISysUserService userService;
@Autowired
......@@ -37,16 +39,24 @@ public class WeiXinService {
/**
* 获取登录token
* @param code
* @param type PC管理端 APP小程序端
* @return
*/
public BaseResponse<String> getToken(String code) {
public BaseResponse<String> getToken(String code,String type) {
if (StrUtil.isEmpty(code)) {
return BaseResponse.errorMsg("code为必填项!");
}
System.out.println("==================code===================");
System.out.println(code);
try {
// String accessToken = getAccessToken();
// String accessToken = null;
// if(type.equals("PC")){
// accessToken = getAccessToken();
// }else if(type.equals("APP")){
// accessToken = getPCAccessToken();
// }else{
// return BaseResponse.errorMsg("参数错误");
// }
// String param = "access_token=%s&code=%s";
// param = String.format(param, accessToken, code);
// JSONObject jsonObject = WeixinInterfaceUtil.doGet(Global.USERINFOURL, param);
......@@ -96,6 +106,29 @@ public class WeiXinService {
}
}
public String getPCAccessToken() {
try {
String param = "corpid=%s&corpsecret=%s";
param = String.format(param, corpid, corpsecretPC);
JSONObject jsonObject = WeixinInterfaceUtil.doGet(Global.ACCESSTOKENURL, param);
String accessToken = jsonObject.getString("access_token");
System.out.println("==================accessToken===================");
System.out.println(accessToken);
return accessToken;
} catch (Exception e) {
return null;
}
}
//获取用户信息
public JSONObject getUser(String accessToken, String userId) {
try {
......
......@@ -9,6 +9,7 @@ spring:
datasource:
# 192.168.110.85 admin!@#123
url: jdbc:mysql://192.168.110.85:3306/sinoma_tcdri?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false
# url: jdbc:mysql://81.68.92.175:3306/sinoma_tcdri?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false
username: root
password: admin!@#123
driverClassName: com.mysql.cj.jdbc.Driver
......@@ -40,4 +41,5 @@ mybatis-plus:
weixin:
corpsecret: gFa_7XvXtCaoeAYERzjRwwz_OTJkJfgBb8weOKjmI3o
corpsecretPC: itCLYcwl9ggA9VfZam_iz96Ikp9StDFfVr4Adb0yY7A
corpid: ww348f91b2573c1867
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment