43 lines
1.2 KiB
Java
Raw Normal View History

2025-09-17 16:11:59 +08:00
package com.cdzy.activity.controller;
import com.alibaba.fastjson2.JSONObject;
import com.cdzy.activity.model.JsonResult;
import com.cdzy.activity.uitls.VerifyUtil;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 微信用户控制层
*
* @author attiya
* @since 2025-09-17
*/
@RestController
@RequestMapping("/user")
public class UserController {
@Resource
private VerifyUtil verifyUtil;
/**
* 用户微信无感登录
*
* @param code 微信登录返回的code
* @return 登陆结果
*/
@RequestMapping("login")
public JsonResult<?> silentLogin(@RequestParam(name ="js_code") String code) {
JSONObject result = verifyUtil.wechatAuthority(code);
if (result == null) {
return JsonResult.failed("微信登录失败");
}
if (result.containsKey("errcode")) {
return JsonResult.failed(String.format("微信登录失败 %s", result.getString("errmsg")));
}
return JsonResult.success("微信登录成功", result.getString("openid"));
}
}