|
@@ -62,7 +62,7 @@ import java.util.*;
|
|
|
@Slf4j
|
|
|
@Api(value = "/WeChatController", tags = {"微信绑定接口"})
|
|
|
@RestController
|
|
|
- @RequestMapping("/tWechat")
|
|
|
+@RequestMapping("/tWechat")
|
|
|
public class TWechatController {
|
|
|
|
|
|
@Autowired
|
|
@@ -78,10 +78,11 @@ public class TWechatController {
|
|
|
@Value("${oauth.wx.appsecret}")
|
|
|
private String appsecret;
|
|
|
|
|
|
- @Value("${oauth.callback.http:http://szwltest.sunzee.com.cn:49002}")
|
|
|
+ @Value("${oauth.callback.http}")
|
|
|
private String http;
|
|
|
|
|
|
@ApiOperation(value = "绑定微信")
|
|
|
+ @CrossOrigin(value = "https://open.weixin.qq.com/")
|
|
|
@GetMapping("/bindWechat")
|
|
|
public R bindWechat(@RequestParam Long adminId) throws Exception {
|
|
|
if (adminId==null) {
|
|
@@ -105,7 +106,7 @@ public class TWechatController {
|
|
|
throw new MyException("用户不存在!");
|
|
|
}
|
|
|
// String path = http + "/tWechat/callback?";
|
|
|
- String path = http + "http://szwltest.sunzee.com.cn/SZWL-SERVER/tWechat/callback?";
|
|
|
+ String path = http + "/SZWL-SERVER/tWechat/callback?";
|
|
|
|
|
|
try {
|
|
|
path = URLEncoder.encode(path, "UTF-8");
|
|
@@ -114,7 +115,7 @@ public class TWechatController {
|
|
|
}
|
|
|
|
|
|
// 第一步:用户同意授权,获取code
|
|
|
- String url = "http://szwltest.sunzee.com.cn/openWeixin/connect/oauth2/authorize?"
|
|
|
+ String url = "https://szwltest.sunzee.com.cn/openWeixin/connect/oauth2/authorize?"
|
|
|
// String url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
|
|
|
+ "appid=" + appid
|
|
|
+ "&redirect_uri=" + path
|
|
@@ -152,24 +153,27 @@ public class TWechatController {
|
|
|
"&lang=zh_CN";
|
|
|
JSONObject userInfo = HttpClientUtils.get(url);
|
|
|
|
|
|
- List<TWechat> list = tWechatService.lambdaQuery()
|
|
|
- .eq(TWechat::getAdminId, adminId)
|
|
|
- .list();
|
|
|
+ LambdaQueryWrapper<TWechat> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(TWechat::getAdminId, adminId);
|
|
|
+ TWechat tWechat = tWechatService.getOne(wrapper);
|
|
|
|
|
|
- if (Objects.nonNull(list)) {
|
|
|
- TWechat tWechat = list.get(0);
|
|
|
+ if (Objects.isNull(tWechat)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String openId = tWechat.getOpenId();
|
|
|
+
|
|
|
+ if (Objects.nonNull(openId)) {
|
|
|
tWechat.setOpenId(userInfo.getString("openid"));
|
|
|
tWechat.setNickName(userInfo.getString("nickname"));
|
|
|
tWechat.setAvatarUrl(userInfo.getString("headimgurl"));
|
|
|
tWechat.setModifyDate(new Date());
|
|
|
tWechatService.updateById(tWechat);
|
|
|
} else {
|
|
|
- TWechat tWechat = new TWechat();
|
|
|
tWechat.setOpenId(userInfo.getString("openid"));
|
|
|
tWechat.setNickName(userInfo.getString("nickname"));
|
|
|
tWechat.setAvatarUrl(userInfo.getString("headimgurl"));
|
|
|
tWechat.setCreateDate(new Date());
|
|
|
- tWechatService.save(tWechat);
|
|
|
+ tWechatService.updateById(tWechat);
|
|
|
}
|
|
|
|
|
|
return userInfo;
|