fix(用户管理):新增用户unionId获取逻辑

This commit is contained in:
2025-04-24 11:42:56 +08:00
parent 8b0a2cc636
commit 29ed66e0e3
12 changed files with 71 additions and 18 deletions
@@ -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