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

委托优化

parent 1097cf30
...@@ -25,17 +25,30 @@ public class WeiXinController { ...@@ -25,17 +25,30 @@ public class WeiXinController {
@Autowired @Autowired
private WeiXinService weiXinService; private WeiXinService weiXinService;
@ApiOperation(value = "获取登录token") @ApiOperation(value = "获取登录token-小程序端")
@GetMapping("/getToken") @GetMapping("/getXCXToken")
public BaseResponse getToken(String code){ public BaseResponse getXCXToken(String code){
try { try {
return weiXinService.getToken(code); return weiXinService.getToken(code,"APP");
}catch (Exception e){ }catch (Exception e){
log.debug("获取登录token{}",e); log.debug("获取登录token{}",e);
} }
return BaseResponse.errorMsg("失败!"); 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 = "当前登录用户") @ApiOperation(value = "当前登录用户")
@GetMapping("/getLoginUser") @GetMapping("/getLoginUser")
public BaseResponse getLoginUser(){ public BaseResponse getLoginUser(){
......
...@@ -29,6 +29,8 @@ public class WeiXinService { ...@@ -29,6 +29,8 @@ public class WeiXinService {
private String corpid; private String corpid;
@Value("${weixin.corpsecret}") @Value("${weixin.corpsecret}")
private String corpsecret; private String corpsecret;
@Value("${weixin.corpsecretPC}")
private String corpsecretPC;
@Autowired @Autowired
private ISysUserService userService; private ISysUserService userService;
@Autowired @Autowired
...@@ -37,16 +39,24 @@ public class WeiXinService { ...@@ -37,16 +39,24 @@ public class WeiXinService {
/** /**
* 获取登录token * 获取登录token
* @param code * @param code
* @param type PC管理端 APP小程序端
* @return * @return
*/ */
public BaseResponse<String> getToken(String code) { public BaseResponse<String> getToken(String code,String type) {
if (StrUtil.isEmpty(code)) { if (StrUtil.isEmpty(code)) {
return BaseResponse.errorMsg("code为必填项!"); return BaseResponse.errorMsg("code为必填项!");
} }
System.out.println("==================code==================="); System.out.println("==================code===================");
System.out.println(code); System.out.println(code);
try { 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"; // String param = "access_token=%s&code=%s";
// param = String.format(param, accessToken, code); // param = String.format(param, accessToken, code);
// JSONObject jsonObject = WeixinInterfaceUtil.doGet(Global.USERINFOURL, param); // JSONObject jsonObject = WeixinInterfaceUtil.doGet(Global.USERINFOURL, param);
...@@ -96,6 +106,29 @@ public class WeiXinService { ...@@ -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) { public JSONObject getUser(String accessToken, String userId) {
try { try {
......
...@@ -9,6 +9,7 @@ spring: ...@@ -9,6 +9,7 @@ spring:
datasource: datasource:
# 192.168.110.85 admin!@#123 # 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://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 username: root
password: admin!@#123 password: admin!@#123
driverClassName: com.mysql.cj.jdbc.Driver driverClassName: com.mysql.cj.jdbc.Driver
...@@ -40,4 +41,5 @@ mybatis-plus: ...@@ -40,4 +41,5 @@ mybatis-plus:
weixin: weixin:
corpsecret: gFa_7XvXtCaoeAYERzjRwwz_OTJkJfgBb8weOKjmI3o corpsecret: gFa_7XvXtCaoeAYERzjRwwz_OTJkJfgBb8weOKjmI3o
corpsecretPC: itCLYcwl9ggA9VfZam_iz96Ikp9StDFfVr4Adb0yY7A
corpid: ww348f91b2573c1867 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