修复:实名认证模块

This commit is contained in:
2025-06-16 18:57:34 +08:00
parent 05d8543e03
commit f5104954de
2 changed files with 38 additions and 36 deletions

View File

@@ -93,6 +93,7 @@ public class UserVerifyController extends BaseController {
loginUser.setRealName(userVerify.getRealName());
if(userVerify.getType().equals(1)){
loginUser.setRealName(userVerify.getName());
loginUser.setCertification(1);
}
userService.updateById(loginUser);
}

View File

@@ -75,10 +75,10 @@ public class WxOfficialController extends BaseController {
@ApiOperation("验证微信服务器")
@GetMapping("/{id}")
public String validate(@PathVariable("id") Integer tenantId,@RequestParam String nonce,@RequestParam String timestamp,@RequestParam String signature,@RequestParam String echostr){
public String validate(@PathVariable("id") Integer tenantId, @RequestParam String nonce, @RequestParam String timestamp, @RequestParam String signature, @RequestParam String echostr) {
System.out.println("nonce = " + nonce);
System.out.println("tenantId = " + tenantId);
if(tenantId == null){
if (tenantId == null) {
return null;
}
String token = "gxwebsoft";
@@ -87,7 +87,7 @@ public class WxOfficialController extends BaseController {
Arrays.sort(array);
// 将三个参数字符串拼接成一个字符串进行sha1加密
StringBuilder sb = new StringBuilder();
for (String str: array){
for (String str : array) {
sb.append(str);
}
final String strSha1 = DigestUtil.sha1Hex(sb.toString());
@@ -101,7 +101,7 @@ public class WxOfficialController extends BaseController {
@Transactional(rollbackFor = {Exception.class})
@RequestMapping("/{id}")
@ResponseBody
public String receiveMessages(HttpServletRequest request,@PathVariable("id") Integer tenantId) throws IOException {
public String receiveMessages(HttpServletRequest request, @PathVariable("id") Integer tenantId) throws IOException {
System.out.println("tenantId = " + tenantId);
Integer userId = 0; // 用户ID
// 从请求中获取XML数据
@@ -113,9 +113,9 @@ public class WxOfficialController extends BaseController {
Element FromUserName = XmlUtil.getElement(rootElement, "FromUserName");
String openId = FromUserName.getTextContent();
System.out.println("openId = " + openId);
if(StrUtil.isNotBlank(openId)){
if (StrUtil.isNotBlank(openId)) {
// 获取用户基本信息(UnionID机制)
final String userStr = HttpUtil.get("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + getAccessToken() + "&openid="+ openId +"&lang=zh_CN");
final String userStr = HttpUtil.get("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + getAccessToken() + "&openid=" + openId + "&lang=zh_CN");
// 保存第三方用户信息表shop_user_oauth
final JSONObject jsonObject = JSONObject.parseObject(userStr);
final String unionid = jsonObject.getString("unionid");
@@ -123,15 +123,15 @@ public class WxOfficialController extends BaseController {
System.out.println("unionid = " + unionid);
sendTemplateMessage(openId);
// 关注操作
if (subscribe != null &&subscribe.equals("1")) {
final int count = userOauthService.count(new LambdaQueryWrapper<UserOauth>().eq(UserOauth::getOauthType, MP_OFFICIAL).eq(UserOauth::getUnionid, unionid).eq(UserOauth::getTenantId,tenantId));
if (subscribe != null && subscribe.equals("1")) {
final int count = userOauthService.count(new LambdaQueryWrapper<UserOauth>().eq(UserOauth::getOauthType, MP_OFFICIAL).eq(UserOauth::getUnionid, unionid).eq(UserOauth::getTenantId, tenantId));
System.out.println("count = " + count);
if (count == 0) {
// 其他平台是否有注册过
final List<UserOauth> list = userOauthService.list(new LambdaQueryWrapper<UserOauth>().eq(UserOauth::getUnionid, unionid).eq(UserOauth::getDeleted, 0));
final int size = list.size();
// 新用户注册
if (size== 0) {
if (size == 0) {
User user = new User();
user.setStatus(0);
user.setUsername("wxoff_".concat(RandomUtil.randomString(12)));
@@ -160,8 +160,8 @@ public class WxOfficialController extends BaseController {
}
// 更新
if (!CollectionUtils.isEmpty(list)) {
for (UserOauth item: list){
if(item.getUserId() != null){
for (UserOauth item : list) {
if (item.getUserId() != null) {
userId = item.getUserId();
}
}
@@ -183,7 +183,7 @@ public class WxOfficialController extends BaseController {
return null;
}
private void sendTemplateMessage(String openId){
private void sendTemplateMessage(String openId) {
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + getAccessToken();
TemplateMessage templateMessage = new TemplateMessage();
templateMessage.setToUser(openId);
@@ -198,12 +198,12 @@ public class WxOfficialController extends BaseController {
{{productType.DATA}}{{name.DATA}} 消费时间:{{time.DATA}} {{remark.DATA}}
*/
HashMap<String, TemplateMessageDTO> data = new HashMap<>();
data.put("first",new TemplateMessageDTO("您收到了一条新的订单。"));
data.put("tradeDateTime",new TemplateMessageDTO("02月18日 01时05分"));
data.put("customerInfo",new TemplateMessageDTO("广州 王俊"));
data.put("orderItemName",new TemplateMessageDTO("兴趣车型"));
data.put("orderItemData",new TemplateMessageDTO("骐达 2011款 1.6 CVT 舒适版"));
data.put("remark",new TemplateMessageDTO("截止24日09:39分,您尚有10个订单未处理。"));
data.put("first", new TemplateMessageDTO("您收到了一条新的订单。"));
data.put("tradeDateTime", new TemplateMessageDTO("02月18日 01时05分"));
data.put("customerInfo", new TemplateMessageDTO("广州 王俊"));
data.put("orderItemName", new TemplateMessageDTO("兴趣车型"));
data.put("orderItemData", new TemplateMessageDTO("骐达 2011款 1.6 CVT 舒适版"));
data.put("remark", new TemplateMessageDTO("截止24日09:39分,您尚有10个订单未处理。"));
System.out.println("data = " + data);
// 链式构建请求
String result = HttpRequest.post(url)
@@ -219,31 +219,31 @@ public class WxOfficialController extends BaseController {
public ApiResult<?> send(UserParam param) {
// send发送订阅通知
String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/bizsend?access_token=" + getAccessToken();
final UserOauth userOauth = userOauthService.getOne(new LambdaQueryWrapper<UserOauth>().eq(UserOauth::getUserId, param.getUserId()).eq(UserOauth::getOauthType,"MP-OFFICIAL").eq(UserOauth::getDeleted, 0));
if(userOauth != null){
final UserOauth userOauth = userOauthService.getOne(new LambdaQueryWrapper<UserOauth>().eq(UserOauth::getUserId, param.getUserId()).eq(UserOauth::getOauthType, "MP-OFFICIAL").eq(UserOauth::getDeleted, 0));
if (userOauth != null) {
param.setOpenid(userOauth.getOauthId());
final String oauthId = userOauth.getOauthId();
// 跳转小程序链接
HashMap<String, String> miniprogram = new HashMap<>();
miniprogram.put("appid",miniAppid);
miniprogram.put("pagepath","pages/chat/chat?friendId=" + param.getUserId());
miniprogram.put("appid", miniAppid);
miniprogram.put("pagepath", "pages/chat/chat?friendId=" + param.getUserId());
// 参数
HashMap<String, Object> data = new HashMap<>();
final HashMap<String, String> thing1 = new HashMap<>();
final HashMap<String, String> thing2 = new HashMap<>();
thing1.put("value","有新访客需要接待");
thing2.put("value","吉媒小红娘");
data.put("thing1",thing1);
data.put("thing2",thing2);
thing1.put("value", "有新访客需要接待");
thing2.put("value", "吉媒小红娘");
data.put("thing1", thing1);
data.put("thing2", thing2);
// 请求主服务器获取用户信息
HashMap<String, Object> map = new HashMap<>();
map.put("access_token", getAccessToken());
map.put("touser",oauthId); // "opEVj6e1YIlMyovkOQFCLJ7llmuI"
map.put("touser", oauthId); // "opEVj6e1YIlMyovkOQFCLJ7llmuI"
// 红娘来信通知
map.put("template_id", templateId);
map.put("miniprogram",JSONObject.toJSONString(miniprogram));
map.put("data",data);
map.put("miniprogram", JSONObject.toJSONString(miniprogram));
map.put("data", data);
// 新访客通知
// map.put("tid","XMpEsDHmZZqpiaAzmPqO0Gk_h39WCRkaNZ9VoSI9F34");
// map.put("page","https://admin.jimeigroup.cn");
@@ -258,12 +258,12 @@ public class WxOfficialController extends BaseController {
JSONObject jsonObject = JSONObject.parseObject(result);
System.out.println("jsonObject = " + jsonObject);
if(jsonObject != null){
if (jsonObject != null) {
return success(jsonObject);
}
}
return fail("请求失败",getAccessToken());
return fail("请求失败", getAccessToken());
}
// 调用接口凭证
@@ -286,7 +286,7 @@ public class WxOfficialController extends BaseController {
JSONObject response = JSON.parseObject(result);
if (response.getString("access_token") != null) {
// 存入缓存
redisUtil.set(key, result,7000L, TimeUnit.SECONDS);
redisUtil.set(key, result, 7000L, TimeUnit.SECONDS);
return response.getString("access_token");
}
return null;
@@ -324,25 +324,26 @@ public class WxOfficialController extends BaseController {
if (entity != null) {
String result = EntityUtils.toString(entity, "UTF-8");
System.out.println("result = " + result);
if(!result.contains("ok")){
if (!result.contains("ok")) {
System.out.println("result = " + result);
String key = MP_OFFICIAL.concat(":access_token:5");
redisUtil.delete(key);
return fail(result);
}
return success("返回结果",entity);
return success("返回结果", entity);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return fail("创建失败",url);
return fail("创建失败", url);
}
@ApiOperation("test")
@PostMapping("/test")
public ApiResult<?> count(){
public ApiResult<?> count() {
final int count = userOauthService.count(new LambdaQueryWrapper<UserOauth>().eq(UserOauth::getOauthType, MP_OFFICIAL).eq(UserOauth::getUnionid, "o0FaIuKa2UsVp6FCbvmZlrcaBRCM"));
System.out.println("count = " + count);
return success(getAccessToken());
}
}