|
@@ -1,6 +1,7 @@
|
|
package com.szwl.controller;
|
|
package com.szwl.controller;
|
|
|
|
|
|
|
|
|
|
|
|
+import cn.com.crbank.ommo.exception.MyException;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -18,6 +19,7 @@ import com.szwl.service.TWechatService;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiModelProperty;
|
|
import io.swagger.annotations.ApiModelProperty;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.http.Header;
|
|
import org.apache.http.Header;
|
|
import org.apache.http.HttpEntity;
|
|
import org.apache.http.HttpEntity;
|
|
@@ -33,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.format.annotation.DateTimeFormat;
|
|
import org.springframework.format.annotation.DateTimeFormat;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
+import org.springframework.web.servlet.view.RedirectView;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
@@ -56,9 +59,10 @@ import java.util.*;
|
|
* @author wuhs
|
|
* @author wuhs
|
|
* @since 2023-05-19
|
|
* @since 2023-05-19
|
|
*/
|
|
*/
|
|
|
|
+@Slf4j
|
|
@Api(value = "/WeChatController", tags = {"微信绑定接口"})
|
|
@Api(value = "/WeChatController", tags = {"微信绑定接口"})
|
|
@RestController
|
|
@RestController
|
|
-@RequestMapping("/tWechat")
|
|
|
|
|
|
+ @RequestMapping("/tWechat")
|
|
public class TWechatController {
|
|
public class TWechatController {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -74,17 +78,14 @@ public class TWechatController {
|
|
@Value("${oauth.wx.appsecret}")
|
|
@Value("${oauth.wx.appsecret}")
|
|
private String appsecret;
|
|
private String appsecret;
|
|
|
|
|
|
- @Value("${oauth.callback.http}")
|
|
|
|
|
|
+ @Value("${oauth.callback.http:http://szwltest.sunzee.com.cn:49002}")
|
|
private String http;
|
|
private String http;
|
|
|
|
|
|
-
|
|
|
|
@ApiOperation(value = "绑定微信")
|
|
@ApiOperation(value = "绑定微信")
|
|
- @CrossOrigin(value = "https://open.weixin.qq.com/")
|
|
|
|
@GetMapping("/bindWechat")
|
|
@GetMapping("/bindWechat")
|
|
- public R oauth(HttpServletResponse response, @RequestParam Long adminId) throws IOException {
|
|
|
|
-
|
|
|
|
|
|
+ public R bindWechat(@RequestParam Long adminId) throws Exception {
|
|
if (adminId==null) {
|
|
if (adminId==null) {
|
|
- return R.fail(ResponseCodesEnum.A0001, "参数为空");
|
|
|
|
|
|
+ throw new MyException("参数为空");
|
|
}
|
|
}
|
|
TAdmin tAdmin = tAdminService.getById(adminId);
|
|
TAdmin tAdmin = tAdminService.getById(adminId);
|
|
TWechat tWechat = new TWechat();
|
|
TWechat tWechat = new TWechat();
|
|
@@ -101,7 +102,7 @@ public class TWechatController {
|
|
tWechatService.save(tWechat);
|
|
tWechatService.save(tWechat);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- return R.fail("用户不存在!");
|
|
|
|
|
|
+ throw new MyException("用户不存在!");
|
|
}
|
|
}
|
|
String path = http + "/tWechat/callback?";
|
|
String path = http + "/tWechat/callback?";
|
|
|
|
|
|
@@ -112,16 +113,16 @@ public class TWechatController {
|
|
}
|
|
}
|
|
|
|
|
|
// 第一步:用户同意授权,获取code
|
|
// 第一步:用户同意授权,获取code
|
|
- String url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
|
|
|
|
|
|
+ String url = "http://szwltest.sunzee.com.cn/openWeixin/connect/oauth2/authorize?"
|
|
|
|
+// String url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
|
|
+ "appid=" + appid
|
|
+ "appid=" + appid
|
|
+ "&redirect_uri=" + path
|
|
+ "&redirect_uri=" + path
|
|
+ "&response_type=code"
|
|
+ "&response_type=code"
|
|
+ "&scope=snsapi_userinfo"
|
|
+ "&scope=snsapi_userinfo"
|
|
+ "&state=" + adminId +
|
|
+ "&state=" + adminId +
|
|
"#wechat_redirect";
|
|
"#wechat_redirect";
|
|
- response.sendRedirect(url);
|
|
|
|
-
|
|
|
|
- return R.ok();
|
|
|
|
|
|
+// response.sendRedirect(url);
|
|
|
|
+ return R.ok(url);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|