fix(用户管理):新增用户unionId获取逻辑
This commit is contained in:
+50
@@ -0,0 +1,50 @@
|
||||
package com.central.order.controller;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Arrays;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/token/callback")
|
||||
@RequiredArgsConstructor
|
||||
public class WxCallbackController {
|
||||
|
||||
private static final String TOKEN = "codechangetheworld2025"; //MIUFvX040zDQtUHUGEFjpzDwgNLmPe6gWPVsnQMW3nL
|
||||
|
||||
@GetMapping()
|
||||
public String verify(
|
||||
@RequestParam("signature") String signature,
|
||||
@RequestParam("timestamp") String timestamp,
|
||||
@RequestParam("nonce") String nonce,
|
||||
@RequestParam("echostr") String echostr) throws Exception {
|
||||
|
||||
log.info("开始验证微信token请求:{}", signature);
|
||||
// 1. 字典序排序并拼接
|
||||
String[] arr = {TOKEN, timestamp, nonce};
|
||||
Arrays.sort(arr);
|
||||
String rawStr = String.join("", arr);
|
||||
|
||||
// 2. SHA1 加密
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
||||
byte[] digest = md.digest(rawStr.getBytes());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte b : digest) {
|
||||
sb.append(String.format("%02x", b));
|
||||
}
|
||||
String hash = sb.toString();
|
||||
|
||||
// 3. 校验签名
|
||||
if (hash.equals(signature)) {
|
||||
return echostr;
|
||||
} else {
|
||||
return "Invalid signature";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,10 +85,8 @@ aliyun:
|
||||
|
||||
wx:
|
||||
mp:
|
||||
app-id: ${WX_APP_ID:wx0ea85b13966d88e1}
|
||||
secret: ${WX_APP_SECRET:a90637566b2b73f41f8b1dabd64dc32b}
|
||||
cloud-env: ${WX_CLOUD_ENV:prod-1gyj8ywz55460ab1}
|
||||
base-url: https://springboot-ztti-156622-7-1355625269.sh.run.tcloudbase.com
|
||||
app-id: wx0ea85b13966d88e1
|
||||
secret: a90637566b2b73f41f8b1dabd64dc32b
|
||||
template-id:
|
||||
payment-success: uscmjgLdw0cKBRq8vFyCOPbYj7p-fHuEOIhFwwIAe4A # 支付成功通知模板ID
|
||||
video-complete: TEMPLATE_ID_2 # 视频完成通知模板ID
|
||||
|
||||
+3
-2
@@ -124,8 +124,9 @@ public class SysUserController {
|
||||
@GetMapping(value = "/users-anon/wxOpenId")
|
||||
@Operation(summary = "根据WxOpenId查询用户")
|
||||
public SysUser findByWxOpenId(@RequestParam("openId") String openId,
|
||||
@RequestParam(required = false) String mobile) throws Exception {
|
||||
return appUserService.findByWxOpenid(openId,mobile);
|
||||
@RequestParam(required = false) String mobile,
|
||||
@RequestParam(required = false) String unionId) throws Exception {
|
||||
return appUserService.findByWxOpenid(openId,mobile,unionId);
|
||||
}
|
||||
|
||||
@GetMapping("/users/{id}")
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ public interface ISysUserService extends ISuperService<SysUser> {
|
||||
|
||||
SysUser findByMobile(String username);
|
||||
|
||||
SysUser findByWxOpenid(String wxOpenid,String mobile) throws Exception;
|
||||
SysUser findByWxOpenid(String wxOpenid,String mobile,String unionId) throws Exception;
|
||||
|
||||
/**
|
||||
* 通过SysUser 把roles和permissions也查询出来
|
||||
|
||||
+2
-1
@@ -71,7 +71,7 @@ public class SysUserServiceImpl extends SuperServiceImpl<SysUserMapper, SysUser>
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser findByWxOpenid(String wxOpenid,String mobile) throws Exception {
|
||||
public SysUser findByWxOpenid(String wxOpenid,String mobile,String unionId) throws Exception {
|
||||
SysUser sysUser = this.selectByOpenId(wxOpenid);
|
||||
if (ObjectUtils.isNotEmpty(sysUser) && StringUtils.isNotEmpty(sysUser.getMobile())) {
|
||||
return sysUser;
|
||||
@@ -84,6 +84,7 @@ public class SysUserServiceImpl extends SuperServiceImpl<SysUserMapper, SysUser>
|
||||
sysUser.setPassword(wxOpenid);
|
||||
sysUser.setEnabled(Boolean.TRUE);
|
||||
sysUser.setMobile(mobile);
|
||||
sysUser.setUnionId(unionId);
|
||||
}else if (ObjectUtils.isEmpty(sysUser.getMobile()) && StringUtils.isNotEmpty(mobile)) {
|
||||
sysUser.setMobile(mobile);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user