From 4c07eb5512914ebd38e1c1e4455094577864c9f0 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期二, 19 八月 2025 11:47:43 +0800 Subject: [PATCH] 会员支付相关 --- cloud-server-account/src/main/java/com/dsh/account/controller/AppUserController.java | 144 +++++++++++++++++++++++++++++------------------ 1 files changed, 89 insertions(+), 55 deletions(-) diff --git a/cloud-server-account/src/main/java/com/dsh/account/controller/AppUserController.java b/cloud-server-account/src/main/java/com/dsh/account/controller/AppUserController.java index 928158c..c217927 100644 --- a/cloud-server-account/src/main/java/com/dsh/account/controller/AppUserController.java +++ b/cloud-server-account/src/main/java/com/dsh/account/controller/AppUserController.java @@ -3,16 +3,13 @@ import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.api.R; import com.dsh.account.dto.BindDto; import com.dsh.account.dto.IntroduceUserQuery; import com.dsh.account.dto.SelectDto; import com.dsh.account.dto.UpdateInfoDto; -import com.dsh.account.entity.IntroduceUser; -import com.dsh.account.entity.TAppGift; -import com.dsh.account.entity.TAppUser; -import com.dsh.account.entity.TCourseInfoRecord; -import com.dsh.account.entity.TStudent; -import com.dsh.account.entity.UserIntegralChanges; +import com.dsh.account.entity.*; +import com.dsh.account.feignclient.other.VipClient; import com.dsh.account.model.AddAppUserVo; import com.dsh.account.model.AdvertisementChangeStateDTO; import com.dsh.account.model.AppUserByNameAndPhoneDTO; @@ -35,6 +32,7 @@ import com.dsh.account.util.TokenUtil; import com.dsh.account.util.ToolUtil; import com.dsh.account.util.wx.WxV3PayConfig; +import com.dsh.account.vo.VipPaymentVO; import com.wechat.pay.contrib.apache.httpclient.util.AesUtil; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -69,6 +67,8 @@ @Autowired private TAppUserService appUserService; + @Autowired + private VipClient vipClient; @Autowired private PayMoneyUtil payMoneyUtil; @@ -439,9 +439,10 @@ @ApiOperation(value = "购买年度会员", tags = {"APP-成为会员"}) @ApiImplicitParams({ @ApiImplicitParam(value = "支付方式(1=微信,2=支付宝)", name = "payType", dataType = "int", required = true), + @ApiImplicitParam(value = "会员卡id", name = "id", dataType = "int", required = true), @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) - public ResultUtil addVipPayment(Integer payType) { + public ResultUtil addVipPayment(Integer payType,Integer id) { if (ToolUtil.isEmpty(payType)) { return ResultUtil.paranErr("payType"); } @@ -450,59 +451,92 @@ if (null == uid) { return ResultUtil.tokenErr(); } - return vipPaymentService.addVipPayment(uid, payType); + return vipPaymentService.addVipPayment(uid, payType, id); } catch (Exception e) { e.printStackTrace(); return ResultUtil.runErr(); } } - - - /** - * 购买年度会员支付微信回调V3版本回调 - * - * @param request - * @param response - */ @ResponseBody - @PostMapping("/base/appUser/addVipPaymentWeChatCallback1") - public void addVipPaymentWeChatCallback1(HttpServletRequest request, HttpServletResponse response) { - try { - System.err.println("微信回调"); - System.err.println("请求" + request); - BufferedReader reader = request.getReader(); - String string1 = reader.toString(); - System.err.println("请求reader" + string1); - StringBuilder requestBody = new StringBuilder(); - String line; - while ((line = reader.readLine()) != null) { - requestBody.append(line); - } - System.err.println("全部请求体" + requestBody); - JSONObject jsonObject = JSONObject.parseObject(requestBody.toString()); - JSONObject resource = jsonObject.getJSONObject("resource"); + @PostMapping("/api/appUser/vipPayment") + @ApiOperation(value = "页面数据展示", tags = {"APP-成为会员"}) + @ApiImplicitParams({ + @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") + }) + public ResultUtil<VipPaymentVO> vipPayment() { - AesUtil aesUtil = new AesUtil(WxV3PayConfig.apiV3Key.getBytes(StandardCharsets.UTF_8)); - String decryptedData = aesUtil.decryptToString(resource.getString("associated_data").getBytes(StandardCharsets.UTF_8), resource.getString("nonce").getBytes(StandardCharsets.UTF_8), - resource.getString("ciphertext")); - System.err.println("微信解密的字符串信息" + decryptedData); - JSONObject jsonInfo = (JSONObject) JSONObject.parse(decryptedData); - String out_trade_no = jsonInfo.getString("out_trade_no"); - String transaction_id = jsonInfo.getString("transaction_id"); - String trade_state = jsonInfo.getString("trade_state"); - if (trade_state.equals("SUCCESS")) { - ResultUtil resultUtil = vipPaymentService.addVipPaymentCallback(out_trade_no, transaction_id); - if (resultUtil.getCode() == 200) { - PrintWriter out = response.getWriter(); - out.write("SUCCESS"); - out.flush(); - out.close(); - } + try { + Integer uid = tokenUtil.getUserIdFormRedis(); + if (null == uid) { + return ResultUtil.tokenErr(); } + TAppUser appUser = appUserService.getById(uid); + VipPaymentVO res = new VipPaymentVO(); + res.setHeadImg(appUser.getHeadImg()); + res.setName(appUser.getName()); + if (appUser.getVipEndTime()==null){ + res.setIsVip(0); + }else if (appUser.getVipEndTime().before(new Date())){ + res.setIsVip(0); + }else{ + res.setIsVip(1); + } + appUserService.updateById(appUser); + List<Vip> vips = vipClient.listAll(); + res.setVipList(vips); } catch (Exception e) { e.printStackTrace(); + return ResultUtil.runErr(); } + return ResultUtil.success(); } + +// +// /** +// * 购买年度会员支付微信回调V3版本回调 +// * +// * @param request +// * @param response +// */ +// @ResponseBody +// @PostMapping("/base/appUser/addVipPaymentWeChatCallback1") +// public void addVipPaymentWeChatCallback1(HttpServletRequest request, HttpServletResponse response) { +// try { +// System.err.println("微信回调"); +// System.err.println("请求" + request); +// BufferedReader reader = request.getReader(); +// String string1 = reader.toString(); +// System.err.println("请求reader" + string1); +// StringBuilder requestBody = new StringBuilder(); +// String line; +// while ((line = reader.readLine()) != null) { +// requestBody.append(line); +// } +// System.err.println("全部请求体" + requestBody); +// JSONObject jsonObject = JSONObject.parseObject(requestBody.toString()); +// JSONObject resource = jsonObject.getJSONObject("resource"); +// +// AesUtil aesUtil = new AesUtil(WxV3PayConfig.apiV3Key.getBytes(StandardCharsets.UTF_8)); +// String decryptedData = aesUtil.decryptToString(resource.getString("associated_data").getBytes(StandardCharsets.UTF_8), resource.getString("nonce").getBytes(StandardCharsets.UTF_8), +// resource.getString("ciphertext")); +// System.err.println("微信解密的字符串信息" + decryptedData); +// JSONObject jsonInfo = (JSONObject) JSONObject.parse(decryptedData); +// String out_trade_no = jsonInfo.getString("out_trade_no"); +// String transaction_id = jsonInfo.getString("transaction_id"); +// String trade_state = jsonInfo.getString("trade_state"); +// if (trade_state.equals("SUCCESS")) { +// ResultUtil resultUtil = vipPaymentService.addVipPaymentCallback(out_trade_no, transaction_id); +// if (resultUtil.getCode() == 200) { +// PrintWriter out = response.getWriter(); +// out.write("SUCCESS"); +// out.flush(); +// out.close(); +// } +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } /** * 购买年度会员支付微信回调 * @@ -730,18 +764,18 @@ @PostMapping("/appUser/queryAppUserByIds") @ResponseBody - public List<TAppUser> queryAppUserByIds(@RequestBody UserDetailsOfSearch search){ - LambdaQueryWrapper<TAppUser> tAppUserLambdaQueryWrapper = new LambdaQueryWrapper<>(); + public List<TStudent> queryAppUserByIds(@RequestBody UserDetailsOfSearch search){ + LambdaQueryWrapper<TStudent> tAppUserLambdaQueryWrapper = new LambdaQueryWrapper<>(); if(ToolUtil.isNotEmpty(search.getIdCard())){ - tAppUserLambdaQueryWrapper.eq(TAppUser::getIdCard, search.getIdCard()); + tAppUserLambdaQueryWrapper.eq(TStudent::getIdCard, search.getIdCard()); } if(ToolUtil.isNotEmpty(search.getPhone())){ - tAppUserLambdaQueryWrapper.eq(TAppUser::getPhone, search.getPhone()); + tAppUserLambdaQueryWrapper.eq(TStudent::getPhone, search.getPhone()); } if(ToolUtil.isNotEmpty(search.getName())){ - tAppUserLambdaQueryWrapper.eq(TAppUser::getName, search.getName()); + tAppUserLambdaQueryWrapper.eq(TStudent::getName, search.getName()); } - tAppUserLambdaQueryWrapper.in(TAppUser::getId,search.getUseIds()); - return appUserService.list(tAppUserLambdaQueryWrapper); + tAppUserLambdaQueryWrapper.in(TStudent::getId,search.getUseIds()); + return studentService.list(tAppUserLambdaQueryWrapper); } } -- Gitblit v1.7.1