Merge branch 'master' of http://192.168.1.26:3000/dianliang/dl_admin
This commit is contained in:
commit
4e1f18c0ff
61
ruoyi-admin/src/main/java/com/ruoyi/api/WxApi.java
Normal file
61
ruoyi-admin/src/main/java/com/ruoyi/api/WxApi.java
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package com.ruoyi.api;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.ruoyi.busi.utils.WeChatUtils;
|
||||||
|
import com.ruoyi.common.annotation.Anonymous;
|
||||||
|
import com.ruoyi.common.constant.Constants;
|
||||||
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
|
import com.ruoyi.common.core.domain.model.GzhLoginBody;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import com.ruoyi.member.service.IMemberUserService;
|
||||||
|
import com.wechat.pay.contrib.apache.httpclient.util.AesUtil;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.GeneralSecurityException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/wxApi")
|
||||||
|
public class WxApi {
|
||||||
|
@Autowired
|
||||||
|
private WeChatUtils weChatUtils;
|
||||||
|
@Autowired
|
||||||
|
private IMemberUserService memberUserService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/getCodeUrl")
|
||||||
|
@Anonymous
|
||||||
|
public Map<String, String> getCodeUrl(String userType) {
|
||||||
|
Map<String, String> res = new HashMap<>();
|
||||||
|
res.put("codeUrl", weChatUtils.getCodeUrl("https://www.nuoyunr.com/#/pages/mine/member/member-card", userType));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getWebAccessTokenAndOpenid")
|
||||||
|
@Anonymous
|
||||||
|
public JSONObject getWebAccessTokenAndOpenid(String code) {
|
||||||
|
return weChatUtils.getWebAccessTokenAndOpenid(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/gzhLogin")
|
||||||
|
@Anonymous
|
||||||
|
public AjaxResult gzhLogin(@RequestBody GzhLoginBody gzhLoginBody)
|
||||||
|
{
|
||||||
|
JSONObject userInfo = weChatUtils.getUserInfo(gzhLoginBody.getAccess_token(), gzhLoginBody.getOpenid());
|
||||||
|
//如果解析成功,获取token
|
||||||
|
String token = memberUserService.gzhLogin(gzhLoginBody.getOpenid(),userInfo);
|
||||||
|
AjaxResult ajax = AjaxResult.success();
|
||||||
|
ajax.put(Constants.TOKEN, token);
|
||||||
|
return ajax;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -66,7 +66,7 @@ public class WeChatUtils {
|
|||||||
*/
|
*/
|
||||||
public JSONObject getWebAccessTokenAndOpenid(String code) {
|
public JSONObject getWebAccessTokenAndOpenid(String code) {
|
||||||
String requestUrl = WEB_ACCESS_TOKEN_URL.replace("APPID", wechatPayConfig.getAppId())
|
String requestUrl = WEB_ACCESS_TOKEN_URL.replace("APPID", wechatPayConfig.getAppId())
|
||||||
.replace("APPSECRET", wechatPayConfig.getAppSecret())
|
.replace("APPSECRET", wechatPayConfig.getWxAppSecret())
|
||||||
.replace("CODE", code);
|
.replace("CODE", code);
|
||||||
String response = HttpUtil.get(requestUrl);
|
String response = HttpUtil.get(requestUrl);
|
||||||
return JSONUtil.parseObj(response);
|
return JSONUtil.parseObj(response);
|
||||||
@ -105,7 +105,7 @@ public class WeChatUtils {
|
|||||||
|
|
||||||
// 如果Redis中没有或者强制刷新,则从微信获取
|
// 如果Redis中没有或者强制刷新,则从微信获取
|
||||||
String requestUrl = ACCESS_TOKEN_URL.replace("APPID", wechatPayConfig.getAppId())
|
String requestUrl = ACCESS_TOKEN_URL.replace("APPID", wechatPayConfig.getAppId())
|
||||||
.replace("APPSECRET", wechatPayConfig.getAppSecret());
|
.replace("APPSECRET", wechatPayConfig.getWxAppSecret());
|
||||||
String response = HttpUtil.get(requestUrl);
|
String response = HttpUtil.get(requestUrl);
|
||||||
JSONObject jsonObject = JSONUtil.parseObj(response);
|
JSONObject jsonObject = JSONUtil.parseObj(response);
|
||||||
accessToken = jsonObject.getStr("access_token");
|
accessToken = jsonObject.getStr("access_token");
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package com.ruoyi.member.service;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
@ -76,4 +77,13 @@ public interface IMemberUserService extends IService<MemberUser> {
|
|||||||
**/
|
**/
|
||||||
void uniSaveMember(MemberUserVO memberUser);
|
void uniSaveMember(MemberUserVO memberUser);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信授权登陆
|
||||||
|
*
|
||||||
|
* @return java.lang.String
|
||||||
|
* @author vinjor-M
|
||||||
|
* @date 15:55 2025/3/26
|
||||||
|
**/
|
||||||
|
String gzhLogin(String wxOpenId, JSONObject userInfo);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import com.ruoyi.common.core.domain.model.LoginUser;
|
|||||||
import com.ruoyi.common.exception.ServiceException;
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.constant.DictConstants;
|
import com.ruoyi.constant.DictConstants;
|
||||||
import com.ruoyi.framework.web.service.TokenService;
|
import com.ruoyi.framework.web.service.TokenService;
|
||||||
import com.ruoyi.member.domain.MemberUser;
|
import com.ruoyi.member.domain.MemberUser;
|
||||||
@ -234,4 +235,55 @@ public class MemberUserServiceImpl extends ServiceImpl<MemberUserMapper, MemberU
|
|||||||
BeanUtils.copyProperties(memberUser,member);
|
BeanUtils.copyProperties(memberUser,member);
|
||||||
updateById(member);
|
updateById(member);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String gzhLogin(String wxOpenId, cn.hutool.json.JSONObject userInfo) {
|
||||||
|
//根据openid判断数据库中是否有该用户
|
||||||
|
//根据openid查询用户信息
|
||||||
|
SysUser wxUser = userMapper.selectWxUserByOpenIdOrPhone(null,null,wxOpenId,null);
|
||||||
|
if(null==wxUser&& StringUtils.isNotEmpty((String) userInfo.get("unionid"))){
|
||||||
|
//根据openId没查到,再根据unionid查
|
||||||
|
wxUser = userMapper.selectWxUserByOpenIdOrPhone(null,null,null,(String) userInfo.get("unionid"));
|
||||||
|
}
|
||||||
|
//如果查不到,则新增,查到了,则更新
|
||||||
|
SysUser user = new SysUser();
|
||||||
|
if (wxUser == null) {
|
||||||
|
// 新增
|
||||||
|
// 设置姓名 ,默认使用昵称+随机数,防止重复姓名的发生 数据库中把username的长度修改的长一点
|
||||||
|
user.setUserName((String) userInfo.get("openid"));
|
||||||
|
user.setNickName((String) userInfo.get("nickname"));
|
||||||
|
user.setWxOpenId((String) userInfo.get("openid"));
|
||||||
|
user.setUnionId((String) userInfo.get("unionid"));
|
||||||
|
user.setSex( userInfo.get("sex").equals("1")?"0":"1");
|
||||||
|
user.setCreateTime(DateUtils.getNowDate());
|
||||||
|
//新增 用户
|
||||||
|
userMapper.insertUser(user);
|
||||||
|
//插入用户扩展信息表数据
|
||||||
|
this.save(new MemberUser(DictConstants.USER_TYPE_TGZ,user,dlRightsConfig.getAddNotice()));
|
||||||
|
this.save(new MemberUser(DictConstants.USER_TYPE_BZ,user,null));
|
||||||
|
//开通会员卡
|
||||||
|
cardService.dealMemberCard(user.getUserId(),"01","67def5ba1e4c60754e68defb3fb027a5","04",null);
|
||||||
|
cardService.dealMemberCard(user.getUserId(),"02","7530cf7b7a5d0100a7b41605d1642ef1","04",null);
|
||||||
|
}else {
|
||||||
|
//,查到了
|
||||||
|
if(!"0".equals(wxUser.getStatus())){
|
||||||
|
//非正常状态,无法登录
|
||||||
|
throw new ServiceException("账号状态异常");
|
||||||
|
}
|
||||||
|
// 更新
|
||||||
|
user = wxUser;
|
||||||
|
if(!userInfo.get("openid").equals(user.getOpenId())){
|
||||||
|
user.setWxOpenId((String) userInfo.get("openid"));
|
||||||
|
user.setUpdateTime(DateUtils.getNowDate());
|
||||||
|
userMapper.updateUser(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//组装token信息
|
||||||
|
LoginUser loginUser = new LoginUser();
|
||||||
|
loginUser.setWxOpenId((String) userInfo.get("openid"));
|
||||||
|
loginUser.setUser(user);
|
||||||
|
loginUser.setUserId(user.getUserId());
|
||||||
|
// 生成token
|
||||||
|
return tokenService.createToken(loginUser);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.ruoyi.common.config.WxAppConfig;
|
import com.ruoyi.common.config.WxAppConfig;
|
||||||
|
import com.ruoyi.common.core.domain.model.GzhLoginBody;
|
||||||
import com.ruoyi.common.core.domain.model.WxLoginBody;
|
import com.ruoyi.common.core.domain.model.WxLoginBody;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.member.service.IMemberCardService;
|
import com.ruoyi.member.service.IMemberCardService;
|
||||||
@ -109,6 +110,10 @@ public class SysLoginController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录方法
|
* 登录方法
|
||||||
*
|
*
|
||||||
|
|||||||
@ -16,7 +16,7 @@ ruoyi:
|
|||||||
# 开发环境配置
|
# 开发环境配置
|
||||||
server:
|
server:
|
||||||
# 服务器的HTTP端口,默认为8080
|
# 服务器的HTTP端口,默认为8080
|
||||||
port: 8081
|
port: 8099
|
||||||
servlet:
|
servlet:
|
||||||
# 应用的访问路径
|
# 应用的访问路径
|
||||||
context-path: /
|
context-path: /
|
||||||
@ -147,6 +147,27 @@ xss:
|
|||||||
wx-app:
|
wx-app:
|
||||||
appId: wxd8ef44a8268672e4
|
appId: wxd8ef44a8268672e4
|
||||||
appSecret: 30c18855ceb0ab0f9801407c998199c2
|
appSecret: 30c18855ceb0ab0f9801407c998199c2
|
||||||
|
wxpay:
|
||||||
|
#微信公众号appid
|
||||||
|
appId: wx7d10b0fa4886a583
|
||||||
|
#商户号
|
||||||
|
mchId: 1712447936
|
||||||
|
# APIv3密钥
|
||||||
|
apiV3Key: ab94673dd0cca78abd0a453d0aac9f98
|
||||||
|
# 微信支付V3-url前缀
|
||||||
|
baseUrl: https://api.mch.weixin.qq.com/v3
|
||||||
|
# 支付通知回调, pjm6m9.natappfree.cc 为内网穿透地址
|
||||||
|
notifyUrl: https://www.nuoyunr.com/notice/notify/payNotify
|
||||||
|
# 退款通知回调, pjm6m9.natappfree.cc 为内网穿透地址
|
||||||
|
refundNotifyUrl: https://www.nuoyunr.com/notice/notify/refundNotify
|
||||||
|
# 密钥路径,resources根目录下
|
||||||
|
privateKeyPath: D:/任务平台项目/dl_admin/ruoyi-admin/src/main/resources/apiclient_key.pem
|
||||||
|
publicKeyPath: D:/任务平台项目/dl_admin/ruoyi-admin/src/main/resources/public_key.pem
|
||||||
|
#商户证书序列号
|
||||||
|
serialNo: 7FCDB0E72D6A928013361ACB77FA3F0DCBD370E3
|
||||||
|
publicKeyId: PUB_KEY_ID_0117124479362025041500321584003200
|
||||||
|
wxAppSecret: 1515e5d055e8dabf5b30faad14ccbc8d
|
||||||
|
|
||||||
# 普通用户权益值
|
# 普通用户权益值
|
||||||
dl-rights:
|
dl-rights:
|
||||||
# 每月发布通告额度
|
# 每月发布通告额度
|
||||||
|
|||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.ruoyi.common.core.domain.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class GzhLoginBody {
|
||||||
|
/** 临时登录凭证 code 只能使用一次 */
|
||||||
|
private String access_token;
|
||||||
|
|
||||||
|
/** 偏移量 */
|
||||||
|
private String expires_in;
|
||||||
|
|
||||||
|
/** 加密数据 */
|
||||||
|
private String openid;
|
||||||
|
|
||||||
|
}
|
||||||
@ -73,6 +73,7 @@ public class LoginUser implements UserDetails
|
|||||||
|
|
||||||
/** openId */
|
/** openId */
|
||||||
private String openId;
|
private String openId;
|
||||||
|
private String wxOpenId;
|
||||||
|
|
||||||
public LoginUser()
|
public LoginUser()
|
||||||
{
|
{
|
||||||
@ -274,4 +275,12 @@ public class LoginUser implements UserDetails
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getWxOpenId() {
|
||||||
|
return wxOpenId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWxOpenId(String wxOpenId) {
|
||||||
|
this.wxOpenId = wxOpenId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user