主管理员 4 months ago
parent
commit
e78a7af4ee
20 changed files with 267 additions and 58 deletions
  1. +8
    -0
      jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/IAppletUserService.java
  2. +1
    -1
      jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/util/AppletUserUtil.java
  3. +7
    -2
      jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/vo/AppletUser.java
  4. +1
    -1
      jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/AppletShiroRealm.java
  5. +1
    -1
      jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroRealm.java
  6. +8
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/Final/LoginType.java
  7. +25
    -2
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiLoginController.java
  8. +3
    -2
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiMemberController.java
  9. +3
    -2
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiPromotionController.java
  10. +1
    -1
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiVipService.java
  11. +1
    -1
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiWaterService.java
  12. +70
    -25
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiLoginService.java
  13. +8
    -2
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiVipServiceImpl.java
  14. +2
    -1
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiWaterServiceImpl.java
  15. +2
    -1
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/WxAppletService.java
  16. +18
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/appletBackground/appletUser/service/impl/AppletUserServiceImpl.java
  17. +99
    -16
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/common/wxUtils/WxHttpUtils.java
  18. +3
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletWater/entity/AppletWater.java
  19. +3
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletWithdrawal/entity/AppletWithdrawal.java
  20. +3
    -0
      jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml

+ 8
- 0
jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/IAppletUserService.java View File

@ -20,6 +20,14 @@ public interface IAppletUserService extends IService<AppletUser> {
*/ */
AppletUser getByOpenid(String openid); AppletUser getByOpenid(String openid);
/**
* 根据openid查询用户
*
* @param unionId 微信openid
* @return 用户信息
*/
AppletUser getByUnionId(String openid, String unionId);
/** /**
* 根据手机号查询用户 * 根据手机号查询用户
* *


+ 1
- 1
jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/util/AppletUserUtil.java View File

@ -83,7 +83,7 @@ public class AppletUserUtil {
String openid = JwtUtil.getUsername(token); String openid = JwtUtil.getUsername(token);
if (openid != null) { if (openid != null) {
IAppletUserService appletUserService = SpringContextUtils.getBean(IAppletUserService.class); IAppletUserService appletUserService = SpringContextUtils.getBean(IAppletUserService.class);
return appletUserService.getByOpenid(openid);
return appletUserService.getByUnionId(openid, null);
} }
} }
} catch (Exception e) { } catch (Exception e) {


+ 7
- 2
jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/vo/AppletUser.java View File

@ -75,9 +75,14 @@ public class AppletUser implements Serializable {
/** /**
* 第三方认证id * 第三方认证id
*/ */
@Excel(name = "第三方认证id", width = 15)
@Schema(description = "第三方认证id")
@Excel(name = "小程序id", width = 15)
@Schema(description = "小程序id")
private java.lang.String openid; private java.lang.String openid;
private String officialId;//公众号id
private String unionId;//同平id
/** /**
* 手机号 * 手机号
*/ */


+ 1
- 1
jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/AppletShiroRealm.java View File

@ -153,7 +153,7 @@ public class AppletShiroRealm extends AuthorizingRealm {
log.debug("开始获取小程序用户信息,openid: {}", openid); log.debug("开始获取小程序用户信息,openid: {}", openid);
// 从数据库查询用户信息 // 从数据库查询用户信息
AppletUser appletUser = appletUserService.getByOpenid(openid);
AppletUser appletUser = appletUserService.getByUnionId(openid, null);
if (appletUser != null) { if (appletUser != null) {
log.debug("从数据库获取到小程序用户: {}", appletUser.getName()); log.debug("从数据库获取到小程序用户: {}", appletUser.getName());
return appletUser; return appletUser;


+ 1
- 1
jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroRealm.java View File

@ -213,7 +213,7 @@ public class ShiroRealm extends AuthorizingRealm {
throw new AuthenticationException("小程序token非法无效!"); throw new AuthenticationException("小程序token非法无效!");
} }
// 从数据库查询用户信息 // 从数据库查询用户信息
AppletUser appletUser = appletUserService.getByOpenid(openid);
AppletUser appletUser = appletUserService.getByUnionId(openid, null);
if (appletUser != null) { if (appletUser != null) {
log.debug("从数据库获取到小程序用户: {}", appletUser.getName()); log.debug("从数据库获取到小程序用户: {}", appletUser.getName());


+ 8
- 0
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/Final/LoginType.java View File

@ -0,0 +1,8 @@
package org.jeecg.modules.applet.Final;
public class LoginType {
public static final String OFFICIAL = "official";
public static final String APPLET = "applet";
}

+ 25
- 2
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiLoginController.java View File

@ -8,6 +8,7 @@ import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.AppletUser; import org.jeecg.common.system.vo.AppletUser;
import org.jeecg.config.shiro.IgnoreAuth; import org.jeecg.config.shiro.IgnoreAuth;
import org.jeecg.modules.applet.Final.LoginType;
import org.jeecg.modules.applet.service.impl.AppletApiLoginService; import org.jeecg.modules.applet.service.impl.AppletApiLoginService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -40,16 +41,38 @@ public class AppletApiLoginController {
@IgnoreAuth @IgnoreAuth
public Result<Map<String, Object>> wxLogin( public Result<Map<String, Object>> wxLogin(
@Parameter(description = "微信登录code", required = true) @RequestParam String code, @Parameter(description = "微信登录code", required = true) @RequestParam String code,
@Parameter(description = "邀请人") @RequestParam(required = false) String inviter) {
@Parameter(description = "邀请人") @RequestParam(required = false) String inviter,
@Parameter(description = "登录平台,默认小程序") @RequestParam(required = false, defaultValue = LoginType.APPLET) String type
) {
if (StringUtils.isBlank(code)) { if (StringUtils.isBlank(code)) {
return Result.error("微信登录code不能为空"); return Result.error("微信登录code不能为空");
} }
log.info("收到小程序登录请求,code: {}", code); log.info("收到小程序登录请求,code: {}", code);
return appletApiLoginService.login(code, inviter);
return appletApiLoginService.login(code, inviter, type);
} }
/**
* 获取公众号签名
*
* @param url URL
* @return 结果
*/
@PostMapping("/getSignPackage")
@Operation(summary = "获取公众号签名", description = "获取公众号签名")
@IgnoreAuth
public Result<Map<String, Object>> getSignPackage(String url) {
if (StringUtils.isBlank(url)) {
return Result.error("url网址不能为空");
}
log.info("收到小程序登录请求,code: {}", url);
return appletApiLoginService.getSignPackage(url);
}
/** /**
* 获取用户手机号 * 获取用户手机号
* *


+ 3
- 2
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiMemberController.java View File

@ -8,6 +8,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.config.shiro.IgnoreAuth; import org.jeecg.config.shiro.IgnoreAuth;
import org.jeecg.modules.applet.Final.LoginType;
import org.jeecg.modules.applet.service.AppletApiCouponService; import org.jeecg.modules.applet.service.AppletApiCouponService;
import org.jeecg.modules.applet.service.AppletApiVipService; import org.jeecg.modules.applet.service.AppletApiVipService;
import org.jeecg.modules.demo.appletCoupon.entity.AppletCoupon; import org.jeecg.modules.demo.appletCoupon.entity.AppletCoupon;
@ -42,8 +43,8 @@ public class AppletApiMemberController {
@Operation(summary = "开通会员", description = "参数会员id 套餐id 优惠卷id") @Operation(summary = "开通会员", description = "参数会员id 套餐id 优惠卷id")
@PostMapping(value = "/open") @PostMapping(value = "/open")
public Result<Object> open(AppletMemberOrder appletMemberOrder) {
Object open = appletApiVipService.getOpe(appletMemberOrder);
public Result<Object> open(AppletMemberOrder appletMemberOrder, @RequestParam(required = false,defaultValue = LoginType.APPLET) String type) {
Object open = appletApiVipService.getOpe(appletMemberOrder, type);
return Result.OK(open); return Result.OK(open);
} }


+ 3
- 2
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiPromotionController.java View File

@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.AppletUser; import org.jeecg.common.system.vo.AppletUser;
import org.jeecg.config.shiro.IgnoreAuth; import org.jeecg.config.shiro.IgnoreAuth;
import org.jeecg.modules.applet.Final.LoginType;
import org.jeecg.modules.applet.entity.StatisticsVo; import org.jeecg.modules.applet.entity.StatisticsVo;
import org.jeecg.modules.applet.service.AppletApiWaterService; import org.jeecg.modules.applet.service.AppletApiWaterService;
import org.jeecg.modules.demo.appletWater.entity.AppletWater; import org.jeecg.modules.demo.appletWater.entity.AppletWater;
@ -57,8 +58,8 @@ public class AppletApiPromotionController {
@Operation(summary = "提现", description = "参数:提现人 提现金额") @Operation(summary = "提现", description = "参数:提现人 提现金额")
@PostMapping(value = "/withdraw") @PostMapping(value = "/withdraw")
public Result<AppletWithdrawal> withdraw(AppletWithdrawal appletWithdrawal) {
AppletWithdrawal With = appletApiWaterService.getWithdraw(appletWithdrawal);
public Result<AppletWithdrawal> withdraw(AppletWithdrawal appletWithdrawal, @RequestParam(required = false, defaultValue = LoginType.APPLET) String type) {
AppletWithdrawal With = appletApiWaterService.getWithdraw(appletWithdrawal, type);
return Result.OK(With); return Result.OK(With);
} }


+ 1
- 1
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiVipService.java View File

@ -21,7 +21,7 @@ public interface AppletApiVipService {
* @return * @return
*/ */
Object getOpe(AppletMemberOrder appletMemberOrder);
Object getOpe(AppletMemberOrder appletMemberOrder, String type);


+ 1
- 1
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiWaterService.java View File

@ -35,7 +35,7 @@ public interface AppletApiWaterService {
* @return * @return
*/ */
AppletWithdrawal getWithdraw(AppletWithdrawal appletWithdrawal);
AppletWithdrawal getWithdraw(AppletWithdrawal appletWithdrawal, String type);
void withdrawSuccess(String id); void withdrawSuccess(String id);


+ 70
- 25
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiLoginService.java View File

@ -11,6 +11,7 @@ import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.vo.AppletUser; import org.jeecg.common.system.vo.AppletUser;
import org.jeecg.common.api.IAppletUserService; import org.jeecg.common.api.IAppletUserService;
import org.jeecg.common.util.RedisUtil; import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.applet.Final.LoginType;
import org.jeecg.modules.common.wxUtils.WxHttpClientUtil; import org.jeecg.modules.common.wxUtils.WxHttpClientUtil;
import org.jeecg.modules.common.wxUtils.WxHttpUtils; import org.jeecg.modules.common.wxUtils.WxHttpUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -41,6 +42,36 @@ public class AppletApiLoginService {
@Autowired @Autowired
private RedisUtil redisUtil; private RedisUtil redisUtil;
private JSONObject openLogin(String code, String type){
log.info("开始小程序登录,code: {}", code);
// 调用微信API获取openid和session_key
String loginUrl = "https://api.weixin.qq.com/sns/jscode2session";
Map<String, String> params = new HashMap<>();
if (LoginType.OFFICIAL.equals(type)){
loginUrl = "https://api.weixin.qq.com/sns/oauth2/access_token";
params.put("appid", wxHttpUtils.getOfficialAppid());
params.put("secret", wxHttpUtils.getOfficialSecret());
params.put("code", code);
params.put("grant_type", "authorization_code");
}else {
params.put("appid", wxHttpUtils.getAppid());
params.put("secret", wxHttpUtils.getSecret());
params.put("js_code", code);
params.put("grant_type", "authorization_code");
}
String response = WxHttpClientUtil.doGet(loginUrl, params);
JSONObject jsonResponse = JSON.parseObject(response);
// 检查微信API返回结果
if (jsonResponse.containsKey("errcode") && jsonResponse.getInteger("errcode") != 0) {
log.error("微信登录失败: {}", response);
throw new JeecgBootException("微信登录失败: " + jsonResponse.getString("errmsg"));
}
return jsonResponse;
}
/** /**
* 小程序登录 * 小程序登录
@ -48,27 +79,11 @@ public class AppletApiLoginService {
* @param code 微信登录code * @param code 微信登录code
* @return 登录结果 * @return 登录结果
*/ */
public Result<Map<String, Object>> login(String code,String inviter) {
public Result<Map<String, Object>> login(String code, String inviter, String type) {
try { try {
log.info("开始小程序登录,code: {}", code);
// 调用微信API获取openid和session_key
String loginUrl = "https://api.weixin.qq.com/sns/jscode2session";
Map<String, String> params = new HashMap<>();
params.put("appid", wxHttpUtils.getAppid());
params.put("secret", wxHttpUtils.getSecret());
params.put("js_code", code);
params.put("grant_type", "authorization_code");
String response = WxHttpClientUtil.doGet(loginUrl, params);
JSONObject jsonResponse = JSON.parseObject(response);
// 检查微信API返回结果
if (jsonResponse.containsKey("errcode") && jsonResponse.getInteger("errcode") != 0) {
log.error("微信登录失败: {}", response);
return Result.error("微信登录失败: " + jsonResponse.getString("errmsg"));
}
JSONObject jsonResponse = openLogin(code, type);
String openid = jsonResponse.getString("openid"); String openid = jsonResponse.getString("openid");
String sessionKey = jsonResponse.getString("session_key"); String sessionKey = jsonResponse.getString("session_key");
String unionid = jsonResponse.getString("unionid"); String unionid = jsonResponse.getString("unionid");
@ -78,8 +93,11 @@ public class AppletApiLoginService {
// 查找或创建用户 // 查找或创建用户
AppletUser appletUser = findOrCreateUser(openid, unionid, inviter); AppletUser appletUser = findOrCreateUser(openid, unionid, inviter);
if (LoginType.OFFICIAL.equals(type)){
String access_token = jsonResponse.getString("access_token");
setUserInfo(appletUser, access_token);
}
// 生成JWT token // 生成JWT token
String token = JwtUtil.sign(appletUser.getOpenid(), appletUser.getId()); String token = JwtUtil.sign(appletUser.getOpenid(), appletUser.getId());
@ -87,7 +105,6 @@ public class AppletApiLoginService {
// 设置超时时间 // 设置超时时间
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000); redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);
// 构建返回结果 // 构建返回结果
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
result.put("token", token); result.put("token", token);
@ -104,6 +121,20 @@ public class AppletApiLoginService {
} }
} }
private void setUserInfo(AppletUser user, String access_token) {
//开始获取用户信息
String memberUrl = "https://api.weixin.qq.com/sns/userinfo?access_token="+access_token+"&openid="+user.getOfficialId()+"&lang=zh_CN";
String json = WxHttpClientUtil.doGet(memberUrl);
//使用工具类
JSONObject json_member = JSONObject.parseObject(json);
String nickname = json_member.getString("nickname");
String headimgurl = json_member.getString("headimgurl");
user.setName(nickname);
user.setAvatar(headimgurl);
}
/** /**
* 获取用户手机号 * 获取用户手机号
* *
@ -181,7 +212,7 @@ public class AppletApiLoginService {
private AppletUser findOrCreateUser(String openid, String unionid, String inviter) { private AppletUser findOrCreateUser(String openid, String unionid, String inviter) {
try { try {
// 根据openid查找用户 // 根据openid查找用户
AppletUser user = appletUserService.getByOpenid(openid);
AppletUser user = appletUserService.getByUnionId(openid, unionid);
if (user == null) { if (user == null) {
// 创建新用户 // 创建新用户
@ -193,8 +224,7 @@ public class AppletApiLoginService {
user.setInviter(inviter); user.setInviter(inviter);
user.setIsPromote("N"); user.setIsPromote("N");
// TODO: 如果需要unionid字段需要在AppletUser实体类中添加该字段
// user.setUnionid(unionid);
user.setUnionId(unionid);
// 保存到数据库 // 保存到数据库
appletUserService.save(user); appletUserService.save(user);
@ -268,4 +298,19 @@ public class AppletApiLoginService {
return Result.error("获取失败: " + e.getMessage()); return Result.error("获取失败: " + e.getMessage());
} }
} }
}
/**
* 获取公众号签名
*
* @param url URL
* @return 结果
*/
public Result<Map<String, Object>> getSignPackage(String url) {
try {
return Result.ok(wxHttpUtils.getSignPackage(url));
} catch (Exception e) {
log.error("获取公众号签名异常", e);
throw new RuntimeException(e);
}
}
}

+ 8
- 2
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiVipServiceImpl.java View File

@ -7,6 +7,7 @@ import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException; import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.util.AppletUserUtil; import org.jeecg.common.system.util.AppletUserUtil;
import org.jeecg.common.system.vo.AppletUser; import org.jeecg.common.system.vo.AppletUser;
import org.jeecg.modules.applet.Final.LoginType;
import org.jeecg.modules.applet.service.AppletApiVipService; import org.jeecg.modules.applet.service.AppletApiVipService;
import org.jeecg.modules.common.IdUtils; import org.jeecg.modules.common.IdUtils;
import org.jeecg.modules.demo.appletCoupon.entity.AppletCoupon; import org.jeecg.modules.demo.appletCoupon.entity.AppletCoupon;
@ -87,7 +88,7 @@ public class AppletApiVipServiceImpl implements AppletApiVipService {
* @param order * @param order
*/ */
@Override @Override
public Object getOpe(AppletMemberOrder order) {
public Object getOpe(AppletMemberOrder order, String type) {
if (StringUtil.isEmpty(order.getMemberId())) { if (StringUtil.isEmpty(order.getMemberId())) {
throw new JeecgBootException("会员id不能为空"); throw new JeecgBootException("会员id不能为空");
@ -107,7 +108,12 @@ public class AppletApiVipServiceImpl implements AppletApiVipService {
//获取用户id //获取用户id
String userId = AppletUserUtil.getCurrentAppletUserId(); String userId = AppletUserUtil.getCurrentAppletUserId();
String openid = AppletUserUtil.getCurrentAppletUserOpenid();
AppletUser user = AppletUserUtil.getCurrentAppletUser();
String openid = user.getOpenid();
if (LoginType.OFFICIAL.equals(type)){
openid = user.getOfficialId();
}
order.setUserId(userId); order.setUserId(userId);
order.setStatus("0"); order.setStatus("0");


+ 2
- 1
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiWaterServiceImpl.java View File

@ -293,7 +293,7 @@ public class AppletApiWaterServiceImpl implements AppletApiWaterService {
} }
@Override @Override
public AppletWithdrawal getWithdraw(AppletWithdrawal appletWithdrawal) {
public AppletWithdrawal getWithdraw(AppletWithdrawal appletWithdrawal, String type) {
if (appletWithdrawal.getMoney() == null) { if (appletWithdrawal.getMoney() == null) {
throw new JeecgBootException("提现金额不能为空"); throw new JeecgBootException("提现金额不能为空");
} }
@ -331,6 +331,7 @@ public class AppletApiWaterServiceImpl implements AppletApiWaterService {
appletWithdrawal.setWaterId(water.getId()); appletWithdrawal.setWaterId(water.getId());
appletWithdrawal.setWithdrawStatus("0"); appletWithdrawal.setWithdrawStatus("0");
appletWithdrawal.setStatus("0"); appletWithdrawal.setStatus("0");
appletWithdrawal.setUserType(type);
appletWithdrawal.setUserId(userId); appletWithdrawal.setUserId(userId);
// 根据提现金额设置提现方式大于200元为线下(1)否则为微信(0) // 根据提现金额设置提现方式大于200元为线下(1)否则为微信(0)


+ 2
- 1
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/WxAppletService.java View File

@ -7,6 +7,7 @@ import org.jeecg.common.api.IAppletUserService;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException; import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.AppletUser; import org.jeecg.common.system.vo.AppletUser;
import org.jeecg.modules.applet.Final.LoginType;
import org.jeecg.modules.common.wxUtils.WxHttpUtils; import org.jeecg.modules.common.wxUtils.WxHttpUtils;
import org.jeecg.modules.common.wxUtils.transfer.TransferToUser; import org.jeecg.modules.common.wxUtils.transfer.TransferToUser;
import org.jeecg.modules.common.wxUtils.transfer.WXPayUtility; import org.jeecg.modules.common.wxUtils.transfer.WXPayUtility;
@ -233,7 +234,7 @@ public class WxAppletService {
request.appid = appid; request.appid = appid;
request.outBillNo = withdrawal.getId(); request.outBillNo = withdrawal.getId();
request.transferSceneId = "1005";// request.transferSceneId = "1005";//
request.openid = user.getOpenid();
request.openid = LoginType.OFFICIAL.equals(withdrawal.getUserType()) ? user.getOfficialId() : user.getOpenid();
request.userName = client.encrypt(withdrawal.getName()); request.userName = client.encrypt(withdrawal.getName());
request.transferAmount = withdrawal.getMoney().multiply(new BigDecimal(100)).longValue();//单位为分 request.transferAmount = withdrawal.getMoney().multiply(new BigDecimal(100)).longValue();//单位为分
request.transferRemark = "佣金报酬"; request.transferRemark = "佣金报酬";


+ 18
- 0
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/appletBackground/appletUser/service/impl/AppletUserServiceImpl.java View File

@ -1,5 +1,6 @@
package org.jeecg.modules.appletBackground.appletUser.service.impl; package org.jeecg.modules.appletBackground.appletUser.service.impl;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.IAppletUserService; import org.jeecg.common.api.IAppletUserService;
import org.jeecg.common.system.vo.AppletUser; import org.jeecg.common.system.vo.AppletUser;
import org.jeecg.modules.appletBackground.appletUser.mapper.AppletUserMapper; import org.jeecg.modules.appletBackground.appletUser.mapper.AppletUserMapper;
@ -24,6 +25,23 @@ public class AppletUserServiceImpl extends ServiceImpl<AppletUserMapper, AppletU
return this.getOne(queryWrapper); return this.getOne(queryWrapper);
} }
@Override
public AppletUser getByUnionId(String openid, String unionId) {
LambdaQueryWrapper<AppletUser> queryWrapper = new LambdaQueryWrapper<>();
//todo 目前仅支持openid
// queryWrapper.eq(StringUtils.isNotEmpty(unionId), AppletUser::getUnionId, unionId);
//StringUtils.isEmpty(unionId),
queryWrapper.and(e -> {
e.eq(AppletUser::getOpenid, openid)
.or()
.eq(AppletUser::getOfficialId, openid);
});
// queryWrapper.eq(StringUtils.isEmpty(unionId) && , )
return this.getOne(queryWrapper);
}
@Override @Override
public AppletUser getByPhone(String phone) { public AppletUser getByPhone(String phone) {
LambdaQueryWrapper<AppletUser> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<AppletUser> queryWrapper = new LambdaQueryWrapper<>();


+ 99
- 16
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/common/wxUtils/WxHttpUtils.java View File

@ -3,17 +3,23 @@ package org.jeecg.modules.common.wxUtils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Map; import java.util.Map;
import java.util.TreeMap;
@Getter
@Component @Component
public class WxHttpUtils { public class WxHttpUtils {
@ -23,31 +29,25 @@ public class WxHttpUtils {
private String secret;// private String secret;//
@Value("${wechat.merchantId}") @Value("${wechat.merchantId}")
private String mchId;// private String mchId;//
private static String shipmentUrl = "https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info?access_token=";
private static final String GET_USER_PHONE_NUMBER = "https://api.weixin.qq.com/wxa/business/getuserphonenumber";
/**
* 获取appid
*/
public String getAppid() {
return appid;
}
/**
* 获取secret
*/
public String getSecret() {
return secret;
}
@Value("${wechat.official.appid}")
private String officialAppid;
@Value("${wechat.official.appsecret}")
private String officialSecret;//
private static String shipmentUrl = "https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info?access_token=";
private static final String GET_USER_PHONE_NUMBER = "https://api.weixin.qq.com/wxa/business/getuserphonenumber";
private static String jsapiTicket = null; // 用于缓存jsapi_ticket
/** /**
* 获取令牌 * 获取令牌
* *
* @return * @return
*/ */
public String getAccessToken() {
String requestUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret;
public String getAccessToken(String mAppId, String mSecret) {
String requestUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + mAppId + "&secret=" + mSecret;
try { try {
// 使用增强版HTTP客户端具有超时配置和重试机制 // 使用增强版HTTP客户端具有超时配置和重试机制
@ -65,6 +65,9 @@ public class WxHttpUtils {
} }
} }
public String getAccessToken() {
return getAccessToken(appid, secret);
}
public String getPhoneNumber(String code) throws Exception { public String getPhoneNumber(String code) throws Exception {
URL url = new URL(GET_USER_PHONE_NUMBER + "?access_token=" + this.getAccessToken()); URL url = new URL(GET_USER_PHONE_NUMBER + "?access_token=" + this.getAccessToken());
@ -93,4 +96,84 @@ public class WxHttpUtils {
return response.toString(); return response.toString();
} }
} }
// 获取jsapi_ticket
private String getJsApiTicket() throws Exception {
String accessToken = getAccessToken(officialAppid, officialSecret);
String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + accessToken + "&type=jsapi";
jsapiTicket = sendGet(url, "UTF-8");
System.out.println("jsapiTicket=========="+jsapiTicket);
return jsapiTicket;
}
// 发送GET请求并获取响应
private String sendGet(String url, String encoding) throws Exception {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setRequestMethod("GET");
connection.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), encoding));
String inputLine;
StringBuilder content = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
in.close();
connection.disconnect();
return content.toString();
}
/**
* 获取公众号签名
*
* @param url URL
* @return 结果
*/
public Map<String, Object> getSignPackage(String url) throws Exception {
String jsapiTicket = getJsApiTicket();
JSONObject jsonObject = JSONObject.parseObject(jsapiTicket); // 解析JSON字符串
jsapiTicket = jsonObject.getString("ticket"); // 提取access_token
String nonceStr = createNonceStr();
long timestamp = System.currentTimeMillis() / 1000;
String string1 = "jsapi_ticket=" + jsapiTicket +
"&noncestr=" + nonceStr +
"&timestamp=" + timestamp +
"&url=" + url; // 确保URL是编码过的
String signature = sha1(string1);
Map<String, Object> ret = new TreeMap<>();
ret.put("appId", officialAppid);
ret.put("timestamp", timestamp);
ret.put("nonceStr", nonceStr);
ret.put("signature", signature);
ret.put("jsapi_ticket", jsapiTicket);
ret.put("url",url);
return ret;
}
// 生成随机字符串
private String createNonceStr() {
return String.valueOf((long) (Math.random() * 100000000));
}
// SHA1加密
private String sha1(String input) throws NoSuchAlgorithmException, UnsupportedEncodingException {
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] messageDigest = md.digest(input.getBytes("UTF-8"));
StringBuilder hexString = new StringBuilder();
for (byte b : messageDigest) {
String hex = Integer.toHexString(0xff & b);
if (hex.length() == 1) hexString.append('0');
hexString.append(hex);
}
return hexString.toString();
}
} }

+ 3
- 0
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletWater/entity/AppletWater.java View File

@ -93,6 +93,9 @@ public class AppletWater implements Serializable {
@Dict(dicCode = "applet_water_type") @Dict(dicCode = "applet_water_type")
@Schema(description = "流水类型") @Schema(description = "流水类型")
private java.lang.String type; private java.lang.String type;
/**用户类型*/
private java.lang.String userType;
/**备注*/ /**备注*/
@Excel(name = "备注", width = 15) @Excel(name = "备注", width = 15)
@Schema(description = "备注") @Schema(description = "备注")


+ 3
- 0
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletWithdrawal/entity/AppletWithdrawal.java View File

@ -96,4 +96,7 @@ public class AppletWithdrawal implements Serializable {
@Schema(description = "领取参数") @Schema(description = "领取参数")
private String packageInfo; private String packageInfo;
/**用户类型*/
private java.lang.String userType;
} }

+ 3
- 0
jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml View File

@ -330,6 +330,9 @@ justauth:
##配置微信##爱简收旧衣按件回收小程序 ##配置微信##爱简收旧衣按件回收小程序
wechat: wechat:
official: # 公众号
appid: wxd5dc792292466cf6
appsecret: ffa6d51fe41c0e62114778267f829382
mpAppId: wx24736a3864e8f0e9 # 微信小程序appid mpAppId: wx24736a3864e8f0e9 # 微信小程序appid
mpAppSecret: 7a530b7bba042128e76bcfdbaedd7e71 # 微信小程序密钥 mpAppSecret: 7a530b7bba042128e76bcfdbaedd7e71 # 微信小程序密钥
merchantId: 1724993508 # 商户号 merchantId: 1724993508 # 商户号


Loading…
Cancel
Save