From 5cf8494a6da08dfcdc5fdb4c5e55aefd8b27d684 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期二, 26 十一月 2024 18:34:28 +0800 Subject: [PATCH] 代码提交 --- xinquan-api/xinquan-api-system/src/main/java/com/xinquan/system/api/domain/vo/WateringVO.java | 2 xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/domain/Turn.java | 39 + xinquan-auth/src/main/java/com/xinquan/auth/util/HuaWeiSMSUtil.java | 6 xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/controller/PageController.java | 16 xinquan-auth/src/main/java/com/xinquan/auth/service/SysLoginService.java | 10 xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/domain/vo/ClientPlaceOrderVO.java | 2 xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/service/impl/TurnServiceImpl.java | 35 xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/controller/CommonQuestionController.java | 11 xinquan-api/xinquan-api-system/src/main/java/com/xinquan/system/api/domain/AppUser.java | 4 xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserCourseController.java | 7 xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/controller/HomeController.java | 46 + xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserViewingHistoryController.java | 55 - xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserTreeController.java | 33 xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/domain/dto/UserAnswerDTO.java | 2 xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/service/impl/AppUserServiceImpl.java | 183 +++- xinquan-common/xinquan-common-core/src/main/java/com/xinquan/common/core/constant/CacheConstants.java | 1 xinquan-common/xinquan-common-core/src/main/java/com/xinquan/common/core/utils/EncryptUtils.java | 2 xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserController.java | 27 xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/service/OrderService.java | 2 xinquan-api/xinquan-api-system/src/main/java/com/xinquan/system/api/model/LoginUser.java | 10 xinquan-modules/xinquan-course/src/main/java/com/xinquan/course/controller/client/ClientCourseController.java | 36 xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/service/impl/OrderServiceImpl.java | 258 +++++- xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/service/TurnService.java | 20 xinquan-common/xinquan-common-core/src/main/java/com/xinquan/common/core/utils/JuHeFuUtil.java | 627 ++++++++++++++++ xinquan-common/xinquan-common-security/src/main/java/com/xinquan/common/security/service/TokenService.java | 3 xinquan-modules/xinquan-course/src/main/java/com/xinquan/course/controller/client/ClientCourseChapterController.java | 4 xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/feign/RemoteAppUserService.java | 4 xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/controller/client/ClientOrderController.java | 72 + xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/mapper/TurnMapper.java | 17 xinquan-auth/src/main/java/com/xinquan/auth/util/HWSendSms.java | 4 /dev/null | 457 ------------ xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWithdrawController.java | 211 +++++ xinquan-auth/src/main/java/com/xinquan/auth/controller/TokenController.java | 14 xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWalletRecordController.java | 20 xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/factory/RemoteAppUserFallbackFactory.java | 9 35 files changed, 1,543 insertions(+), 706 deletions(-) diff --git a/xinquan-api/xinquan-api-system/src/main/java/com/xinquan/system/api/domain/AppUser.java b/xinquan-api/xinquan-api-system/src/main/java/com/xinquan/system/api/domain/AppUser.java index a59d837..783546f 100644 --- a/xinquan-api/xinquan-api-system/src/main/java/com/xinquan/system/api/domain/AppUser.java +++ b/xinquan-api/xinquan-api-system/src/main/java/com/xinquan/system/api/domain/AppUser.java @@ -174,6 +174,10 @@ @ApiModelProperty(value = "标签id,多个id使用英文逗号拼接") @TableField("tag_id") private String tagId; + @ApiModelProperty(value = "第三方分账接收方id 用于提现") + @TableField("fenzhangId") + private String fenzhangId; + @ApiModelProperty(value = "用户标签") @TableField(exist = false) private List<String> tags; diff --git a/xinquan-api/xinquan-api-system/src/main/java/com/xinquan/system/api/domain/vo/WateringVO.java b/xinquan-api/xinquan-api-system/src/main/java/com/xinquan/system/api/domain/vo/WateringVO.java index 1db96a9..d9789f4 100644 --- a/xinquan-api/xinquan-api-system/src/main/java/com/xinquan/system/api/domain/vo/WateringVO.java +++ b/xinquan-api/xinquan-api-system/src/main/java/com/xinquan/system/api/domain/vo/WateringVO.java @@ -26,6 +26,8 @@ private Integer status; @ApiModelProperty(value = "阈值") private Integer nextLevel; + @ApiModelProperty(value = "浇水后剩余能量值") + private Integer energyValue; diff --git a/xinquan-api/xinquan-api-system/src/main/java/com/xinquan/system/api/model/LoginUser.java b/xinquan-api/xinquan-api-system/src/main/java/com/xinquan/system/api/model/LoginUser.java index 649c8ff..cc419ba 100644 --- a/xinquan-api/xinquan-api-system/src/main/java/com/xinquan/system/api/model/LoginUser.java +++ b/xinquan-api/xinquan-api-system/src/main/java/com/xinquan/system/api/model/LoginUser.java @@ -27,6 +27,8 @@ */ @ApiModelProperty(value = "用户id") private Long userid; + @ApiModelProperty(value = "app用户id") + private Long appUserId; /** * 用户名 @@ -159,4 +161,12 @@ { this.sysUser = sysUser; } + + public Long getAppUserId() { + return appUserId; + } + + public void setAppUserId(Long appUserId) { + this.appUserId = appUserId; + } } diff --git a/xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/factory/RemoteAppUserFallbackFactory.java b/xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/factory/RemoteAppUserFallbackFactory.java index 2645bb5..b0b9ada 100644 --- a/xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/factory/RemoteAppUserFallbackFactory.java +++ b/xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/factory/RemoteAppUserFallbackFactory.java @@ -215,6 +215,15 @@ public R<List<AppUser>> getAppUserList(Collection<Long> appUserIdSet, String source) { return R.fail("获取APP用户列表失败。"); } + + @Override + public void deleteAppUserCourse(Long courseId, Long appUserId) { + } + + @Override + public void subVipExpireTime(Long appUserId, Integer type) { + + } }; } } diff --git a/xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/feign/RemoteAppUserService.java b/xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/feign/RemoteAppUserService.java index bf80f88..d2716a0 100644 --- a/xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/feign/RemoteAppUserService.java +++ b/xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/feign/RemoteAppUserService.java @@ -198,4 +198,8 @@ @PostMapping("/inner/app-user/getAppUserList") R<List<AppUser>> getAppUserList(@RequestBody Collection<Long> appUserIdSet, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); + @GetMapping("/client/app-user-course/deleteAppUserCourse/{courseId}/{appUserId}") + void deleteAppUserCourse(@PathVariable("courseId") Long courseId,@PathVariable("appUserId") Long appUserId); + @PostMapping("/client/app-user/subVipExpireTime/{appUserId}/{type}") + public void subVipExpireTime(@PathVariable("appUserId") Long appUserId,@PathVariable("type") Integer type); } diff --git a/xinquan-auth/src/main/java/com/xinquan/auth/controller/TokenController.java b/xinquan-auth/src/main/java/com/xinquan/auth/controller/TokenController.java index 3d696bf..2705ac5 100644 --- a/xinquan-auth/src/main/java/com/xinquan/auth/controller/TokenController.java +++ b/xinquan-auth/src/main/java/com/xinquan/auth/controller/TokenController.java @@ -10,6 +10,7 @@ import com.xinquan.common.core.domain.R; import com.xinquan.common.core.utils.JwtUtils; import com.xinquan.common.core.utils.StringUtils; +import com.xinquan.common.redis.service.RedisService; import com.xinquan.common.security.auth.AuthUtil; import com.xinquan.common.security.service.TokenService; import com.xinquan.common.security.utils.SecurityUtils; @@ -63,6 +64,7 @@ @Resource private RemoteAppUserService remoteAppUserService; + /** * 发送验证码 * @param cellPhone 手机号码 @@ -72,21 +74,11 @@ @ApiOperation(value = "发送验证码",tags = {"APP端"}) @ApiImplicitParams({ @ApiImplicitParam(name = "cellPhone", value = "手机号码", required = true, dataType = "String", paramType = "query"), - @ApiImplicitParam(name = "type", value = "类型 1=注册 2=验证码登录 3=找回密码 4=第三方登录后验证手机 5=切换手机号 6= 添加银行卡", required = true, dataType = "Integer", paramType = "query")}) + @ApiImplicitParam(name = "type", value = "类型 1=注册 2=验证码登录 3=找回密码 4=第三方登录后验证手机 5=切换手机号 6= 添加银行卡,7=管理后台修改密码", required = true, dataType = "Integer", paramType = "query")}) public R<?> sendCaptchaCode( @RequestParam(value = "cellPhone", required = true) String cellPhone, @RequestParam("type") Integer type) { - if(type==5){ - LoginUser loginUser = tokenService.getLoginUser(); - if (loginUser==null){ - return R.tokenError("登录失效"); - } - AppUser data1 = remoteAppUserService.getAppUserById(loginUser.getUserid() + "").getData(); - if (!cellPhone.equals(data1.getCellPhone())){ - return R.fail("手机号错误"); - } - } if(type==5){ AppUser data = remoteAppUserService.getUserByPhone(cellPhone).getData(); if (data!=null){ diff --git a/xinquan-auth/src/main/java/com/xinquan/auth/service/SysLoginService.java b/xinquan-auth/src/main/java/com/xinquan/auth/service/SysLoginService.java index 1d299f5..e82d7bd 100644 --- a/xinquan-auth/src/main/java/com/xinquan/auth/service/SysLoginService.java +++ b/xinquan-auth/src/main/java/com/xinquan/auth/service/SysLoginService.java @@ -281,6 +281,8 @@ return CacheConstants.APP_CHANGE_PHONE_CODE_PREFIX; case 6: return CacheConstants.ADD_CARD_PHONE_CODE_PREFIX; + case 7: + return CacheConstants.MANAGEMENT_PASSWORD_SECRET_PREFIX; default: return ""; } @@ -303,10 +305,10 @@ TimeUnit.MINUTES); log.info("发送验证码成功,手机号:{} 验证码:{}", cellPhone, code); // TODO 修改sender参数及templateId -// HuaWeiSMSUtil.sendSms("[\"" + code + "\"]", cellPhone, "8824110423893", -// "767ad27dce184a32a4b4863517fbd301"); + HuaWeiSMSUtil.sendSms("[\"" + code + "\"]", cellPhone, "8824110423893", + "767ad27dce184a32a4b4863517fbd301"); - hwSendSms.sendSms(code, cellPhone); +// hwSendSms.sendSms(code, cellPhone); } catch (Exception e) { log.error("发送短信失败", e); throw new ServiceException("验证码发送失败"); @@ -331,7 +333,7 @@ } // 查询用户信息 AppUser appUser = remoteAppUserService.getUserByCondition( - AppUserDTO.builder().cellPhone(body.getCellPhone()).device(body.getDevice()).build(), + AppUserDTO.builder().cellPhone(body.getCellPhone()).build(), SecurityConstants.INNER).getData(); if (StringUtils.isNull(appUser)) { recordLogService.recordLogininfor(body.getCellPhone(), Constants.LOGIN_FAIL, diff --git a/xinquan-auth/src/main/java/com/xinquan/auth/util/HWSendSms.java b/xinquan-auth/src/main/java/com/xinquan/auth/util/HWSendSms.java index 1ebaada..da83def 100644 --- a/xinquan-auth/src/main/java/com/xinquan/auth/util/HWSendSms.java +++ b/xinquan-auth/src/main/java/com/xinquan/auth/util/HWSendSms.java @@ -63,7 +63,7 @@ String templateParas = "[\""+code+"\"]"; //模板变量,此处以单变量验证码短信为例,请客户自行生成6位验证码,并定义为字符串类型,以杜绝首位0丢失的问题(例如:002569变成了2569)。 //请求Body,不携带签名名称时,signature请填null - String body = buildRequestBody("8823121426646", receiver, "767ad27dce184a32a4b4863517fbd301", + String body = buildRequestBody("8824110423893", receiver, "767ad27dce184a32a4b4863517fbd301", templateParas, statusCallBack, "心泉智慧"); if (null == body || body.isEmpty()) { LOGGER.warn("body is null."); @@ -74,7 +74,7 @@ request.setKey("dFbKS778KG0jvQrQ672b9RaOktfV"); request.setSecret("3QsteXCIY3KRfgXf5zXyi6f3cHBj"); request.setMethod("POST"); - request.setUrl("https://smsapi.cn-north-4.myhuaweicloud.com:443/sms/batchSendSms/v1"); + request.setUrl("https://smsapi.cn-south-1.myhuaweicloud.com:443/sms/batchSendSms/v1"); request.addHeader("Content-Type", "application/x-www-form-urlencoded"); request.setBody(body); LOGGER.info("Print the body: {}", body); diff --git a/xinquan-auth/src/main/java/com/xinquan/auth/util/HuaWeiSMSUtil.java b/xinquan-auth/src/main/java/com/xinquan/auth/util/HuaWeiSMSUtil.java index 67c7c76..d18b21f 100644 --- a/xinquan-auth/src/main/java/com/xinquan/auth/util/HuaWeiSMSUtil.java +++ b/xinquan-auth/src/main/java/com/xinquan/auth/util/HuaWeiSMSUtil.java @@ -33,7 +33,7 @@ public static void main(String[] args) throws Exception { - sendSms("[\"" + 12356 + "\"]", "19983174515", "8824110423893", + sendSms("[\"" + 123456 + "\"]", "19983174515", "8824110423893", "767ad27dce184a32a4b4863517fbd301"); // sendSms("[\"17623778642\",\"蓉A-7823\"]","17623778642","8819122535459","6c848255000c4619833ab690e393f906"); @@ -52,13 +52,13 @@ public static void sendSms(String code, String phone, String sender, String templateId) throws Exception { // TODO 必填,请参考"开发准备"获取如下数据,替换为实际值 - String url = "https://smsapi.cn-north-4.myhuaweicloud.com:443/sms/batchSendSms/v1"; // APP接入地址+接口访问URI + String url = "https://smsapi.cn-south-1.myhuaweicloud.com:443/sms/batchSendSms/v1"; // APP接入地址+接口访问URI String appKey = "dFbKS778KG0jvQrQ672b9RaOktfV"; // APP_Key String appSecret = "3QsteXCIY3KRfgXf5zXyi6f3cHBj"; // APP_Secret // 条件必填,国内短信关注,当templateId指定的模板类型为通用模板时生效且必填,必须是已审核通过的,与模板类型一致的签名名称 // 国际/港澳台短信不用关注该参数 - String signature = "心泉智慧"; // 签名名称 + String signature = null; // 签名名称 // 必填,全局号码格式(包含国家码),示例:+8615123456789,多个号码之间用英文逗号分隔 String receiver = "+86" + phone; // 短信接收人号码 diff --git a/xinquan-common/xinquan-common-core/src/main/java/com/xinquan/common/core/constant/CacheConstants.java b/xinquan-common/xinquan-common-core/src/main/java/com/xinquan/common/core/constant/CacheConstants.java index 362856a..ef94ba9 100644 --- a/xinquan-common/xinquan-common-core/src/main/java/com/xinquan/common/core/constant/CacheConstants.java +++ b/xinquan-common/xinquan-common-core/src/main/java/com/xinquan/common/core/constant/CacheConstants.java @@ -89,5 +89,6 @@ * APP第三方登录手机号校验验证码修改密码秘钥 redis key */ public static final String APP_PASSWORD_SECRET_PREFIX = "app_password_secret:"; + public static final String MANAGEMENT_PASSWORD_SECRET_PREFIX = "management_password_secret:"; } diff --git a/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/utils/EncryptUtils.java b/xinquan-common/xinquan-common-core/src/main/java/com/xinquan/common/core/utils/EncryptUtils.java similarity index 97% rename from xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/utils/EncryptUtils.java rename to xinquan-common/xinquan-common-core/src/main/java/com/xinquan/common/core/utils/EncryptUtils.java index d19e0e0..8ae2153 100644 --- a/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/utils/EncryptUtils.java +++ b/xinquan-common/xinquan-common-core/src/main/java/com/xinquan/common/core/utils/EncryptUtils.java @@ -1,4 +1,4 @@ -package com.xinquan.order.utils; +package com.xinquan.common.core.utils; import java.nio.charset.StandardCharsets; import java.security.Security; diff --git a/xinquan-common/xinquan-common-core/src/main/java/com/xinquan/common/core/utils/JuHeFuUtil.java b/xinquan-common/xinquan-common-core/src/main/java/com/xinquan/common/core/utils/JuHeFuUtil.java new file mode 100644 index 0000000..322be9c --- /dev/null +++ b/xinquan-common/xinquan-common-core/src/main/java/com/xinquan/common/core/utils/JuHeFuUtil.java @@ -0,0 +1,627 @@ +package com.xinquan.common.core.utils; + +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import cn.hutool.http.HttpUtil; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.xinquan.common.core.domain.R; +import com.xinquan.common.core.exception.ServiceException; + +import java.security.KeyFactory; +import java.security.PrivateKey; +import java.security.Signature; +import java.security.spec.PKCS8EncodedKeySpec; +import java.util.Base64; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; + +import org.omg.PortableServer.SERVANT_RETENTION_POLICY_ID; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.crypto.Cipher; +import javax.crypto.spec.SecretKeySpec; + +/** + * 桔禾付支付工具类 + * + * @author mitao + * @date 2024/9/7 + */ +public class JuHeFuUtil { + + private static Logger logger = LoggerFactory.getLogger(JuHeFuUtil.class); + // 商户RSA私钥 TODO + private static final String MERCHANT_PRIVATE_KEY = "\"MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAKOuwQkWiVCNY5SI\"" + + " \"w6fXcIHj/e8UuQ5Gro1v4yguVnNhCdC6HsWbF6jf1ios8CQKxIQViI2I8GfVPsjB\"" + + " \"Bpfp7TK5zup0BHHYg7JUk0tC6ojL8WgbtVpKX7GJFQOdjNbZmYBlDQuBiCfvxWuL\"" + + " \"ki8juL8NlY4aj7FgSDboSHq7A+ZjAgMBAAECgYAEhei5qpDC1BVjXmAhvDdUr4st\"" + + " \"1yHB/jwGloftbVJgP9c4mFwPU9jUhtLxOWqtZErH55xtZNJX3DGu9H6NJh6y09UC\"" + + " \"LdQJJY2/BQBrTlDsVFQl5h2PwDOO+qwUkZPTVd+822Sv0lukVS4c5sCwcdYwShmi\"" + + " \"IQCuudpygHDCBxJ6AQJBANAmfr6j8PxnCKlSUfaO1PqcnT6BGOJEBbnT0CGiKwNw\"" + + " \"XKecEKh5O8Ev4Ak9FhGad4eFkKZDNvHLE+yfCPy8nwECQQDJT10Hwi9+1KFdTacQ\"" + + " \"rC94fZzipuqBOeVzgTPQrQ0iM38uKx5Sj5o4Ii9cyfkw2EoG/gFSim57U/OApLab\"" + + " \"22ljAkBoL0xzWZWOkHfaYHTcB0P9KJTgKzfsUQXYrHdZzlTfRMdrsYb4/K13FeJ6\"" + + " \"XVQFfZ5ke+sZ/TysK+yOHFAgSL0BAkAXLdYuYIOLfPwffCNyXgERRJVd245A1uO+\"" + + " \"iu/mZSaP+5H3ROu24eYF9Jmze2X/48eSSojochwKgz4UX+LOy1K1AkBQycFQjRWC\"" + + " \"jPi8biMhdLzzX47CNFkwigVp0At6VcZmb86cS9ohoTHCbeG0+hlX7p9eNMiFKLVn\"" + + " \"nCdjY6j1xqtv\""; + // 平台RSA公钥 TODO + private static final String PLAT_PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDOKBBFXirWIJth+SNJCY4mhbAT" + + "bL60sKV66bRixHMVz8vpBqONio9X6A+Pm9LNutBe+hLpI1BMmFJk3Mb1/QEcklWp" + + "tRGgHqIrBxR4b19qc/2/pSxyqlpaifYJFZhOg2+OcQ/fqpAmhNXN5uc1pcYvbvWT" + + "am0j+6+nBNQeAAku5QIDAQAB"; + // 应用的app_id TODO + private static final String APP_ID = "app_e7301b75-19f1-40e5-96ac-0fee847d4da0"; + // 商户id TODO + private static final String MER_ID = "1120241105365033"; + // AES密钥 TODO + private static final String AES_KEY = "6d548eb01bad44bbbb4a23743e733103"; + // 创建用户接口 + private static final String CREATE_USER_INTERFACE = "/api/member/create_user_a"; + private static final String UPDATE_ACCOUNT_INTERFACE = "/api/member/update_account_a"; + private static final String BALANCE_QUERY_INTERFACE = "/api/member/balance_query_a"; + private static final String BALANCE_WITHDRAW_INTERFACE = "/api/member/balance_withdraw_a"; + private static final String BALANCE_PAY = "/api/account/balance_pay"; + // 创建支付订单 + private static final String CREATE_PAYMENT_INTERFACE = "/api/payment/create_payment"; + private static final String CREATE_PAYMENT_INTERFACE_CODE = "/api/payment/create_payment_qrcode"; + private static final String CREATE_PAYMENT_INTERFACE_THIRD = "/api/payment/create_payment_third"; + // 退款接口 + private static final String PAYMENT_REFUND_INTERFACE = "/api/payment/payment_refund"; + private static final String QUERY_PAYMENT_INTERFACE = "/api/query/query_payment"; + private static final String MERCHANT_PAY_INTERFACE = "/api/account/merchant_pay"; + // 接口地址 TODO + private static final String BASE_URL = "https://payapi.juhefu.com/"; + // 支付宝支付渠道 + private static final String PAY_CHANNEL_ALIPAY = "alipay_qr"; + // 微信支付渠道 + private static final String PAY_CHANNEL_WECHAT = "wx_lite"; + private static final String PAY_CHANNEL_WECHAT_THiRD = "wx"; + // 微信小程序id TODO + private static final String WX_APP_ID = ""; + + /** + * 创建用户 + * + * @param memberId 用户id + * @return boolean + * @throws Exception + */ + public static String createUser( + String memberId + ,String username + ,String certType + ,String certId + ,String telNo + ,String cardId + ) + throws Exception { + JSONObject memberP = new JSONObject(); + memberP.put("user_name",username); + memberP.put("cert_type",certType); + memberP.put("cert_id",certId); + memberP.put("tel_no",telNo); + memberP.put("card_id",cardId); + JSONObject data = new JSONObject(); +// data.put("app_id", APP_ID); + data.put("app_id", "app_e7301b75-19f1-40e5-96ac-0fee847d4da0"); + data.put("member_id", memberId); + data.put("member_type", "01"); + TreeMap treeMap = JSONObject.parseObject(JSONObject.toJSONString(memberP), TreeMap.class); + // 转化为json + String jsonString = JSONObject.toJSONString(treeMap); + JSONObject memberP1 = JSONObject.parseObject(jsonString); + data.put("member_p", memberP1); + + System.err.println(data); + JSONObject body = new JSONObject(); +// body.put("merId", MER_ID); + body.put("merId", "1120241105365033"); + body.put("sign", sign(JSONObject.toJSONString(data))); +// body.put("reqCipher", +// EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); + body.put("reqCipher", + EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), "6d548eb01bad44bbbb4a23743e733103")); + body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); + System.err.println(body); +// String result = sendPost(BASE_URL + CREATE_USER_INTERFACE, body); + String result = sendPost("https://payapi.juhefu.com/" + CREATE_USER_INTERFACE, body); + JSONObject resJsonObject = JSONObject.parseObject(result); + System.err.println(resJsonObject); + String string = resJsonObject.getString("reqCipher"); + String decrypt = decrypt(string); + System.err.println(decrypt); + JSONObject jsonObject = JSONObject.parseObject(decrypt); + if (resJsonObject.get("error_msg")!=null){ + return resJsonObject.getString("error_msg"); + } + return "success"; + } + public static String updateAccount( + String memberId + ,String username + ,String telNo + ,String cardId + ) + throws Exception { + + JSONObject data = new JSONObject(); +// data.put("app_id", APP_ID); + data.put("app_id", "app_e7301b75-19f1-40e5-96ac-0fee847d4da0"); + data.put("member_id", memberId); + data.put("member_type", "01"); + data.put("card_id", cardId); + data.put("card_name", username); + data.put("tel_no", telNo); + JSONObject body = new JSONObject(); +// body.put("merId", MER_ID); + body.put("merId", "1120241105365033"); + body.put("sign", sign(JSONObject.toJSONString(data))); +// body.put("reqCipher", +// EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); + body.put("reqCipher", + EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), "6d548eb01bad44bbbb4a23743e733103")); + body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); + System.err.println(body); +// String result = sendPost(BASE_URL + CREATE_USER_INTERFACE, body); + String result = sendPost("https://payapi.juhefu.com/" + UPDATE_ACCOUNT_INTERFACE, body); + JSONObject resJsonObject = JSONObject.parseObject(result); + System.err.println(resJsonObject); + if (resJsonObject.get("error_msg")!=null){ + return resJsonObject.getString("error_msg"); + } + String string = resJsonObject.getString("reqCipher"); + String decrypt = decrypt(string); + System.err.println(decrypt); + JSONObject jsonObject = JSONObject.parseObject(decrypt); + System.err.println(jsonObject); + return "success"; + } + public static String queryBalance( + String memberId + ) + throws Exception { + + JSONObject data = new JSONObject(); +// data.put("app_id", APP_ID); + data.put("app_id", "app_e7301b75-19f1-40e5-96ac-0fee847d4da0"); + data.put("member_id", memberId); + data.put("member_type", "01"); + JSONObject body = new JSONObject(); +// body.put("merId", MER_ID); + body.put("merId", "1120241105365033"); + body.put("sign", sign(JSONObject.toJSONString(data))); +// body.put("reqCipher", +// EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); + body.put("reqCipher", + EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), "6d548eb01bad44bbbb4a23743e733103")); + body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); + System.err.println(body); +// String result = sendPost(BASE_URL + CREATE_USER_INTERFACE, body); + String result = sendPost("https://payapi.juhefu.com/" + BALANCE_QUERY_INTERFACE, body); + JSONObject resJsonObject = JSONObject.parseObject(result); + System.err.println(resJsonObject); + if (resJsonObject.get("error_msg")!=null){ + return resJsonObject.getString("error_msg"); + } + String string = resJsonObject.getString("resCipher"); + String decrypt = decrypt(string); + System.err.println(decrypt); + JSONObject jsonObject = JSONObject.parseObject(decrypt); + System.err.println(jsonObject); + return "success"; + } + + public static void main(String[] args) throws Exception { +// createPayment1("CZ192818331231230901", 1, "0.01", +// "充值", "充值", +// "127.0.0.1", "o4Q_v6QMqkcO7kIOOxp-x1-UpOww", +// "https://xq.xqzhihui.com/api/order/client/order/order/base/callback") +//// "https://xq.xqzhihui.com/api/order/client/order/order/base/callback") +// ; +// String orderNo = OrderUtil.getOrderNoForPrefix("User"); +// createUser("test945622121","周帅","00" +// ,"513902200006257079" +// ,"19983174515" +// ,"6228480469852935177"); +// updateAccount("test945622121","周帅","19983174515" +// ,"6228480469852935177"); +// queryBalance("test945622121"); + balancePay("12345678912", "test945622121","0.01", ""); +// String decrypt = decrypt("z8Che/JwxrGj/oTOuAvU8HFN6vXL/OqeioV41ZuPV/xVQPt9vCHHc1R5LgAO51Hq5ilD9wqsminRvSiJj6Fs/Bfk8espZSOO2g1OE7FZyqcLB1w01MSWyxfQT8nc2GH/EfOKXCuaKBCeyW24OvW3ng=="); +// System.err.println(decrypt); + } + + public static JSONObject balancePay(String orderNo, String memberId, String payAmt, String notifyUrl) throws Exception { + JSONObject data = new JSONObject(); + + data.put("order_no", orderNo); + data.put("app_id", APP_ID); + data.put("pay_amt", payAmt); + data.put("member_id", memberId); + data.put("notify_url", notifyUrl); + JSONObject body = new JSONObject(); + body.put("merId", MER_ID); + body.put("sign", sign(JSONObject.toJSONString(data))); + body.put("reqCipher", + EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); + body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); + String result = sendPost(BASE_URL + BALANCE_PAY, body); + JSONObject resJsonObject = JSONObject.parseObject(result); + System.err.println(resJsonObject); + if (resJsonObject.getString("error_msg")!=null){ + return resJsonObject; + } + String string = resJsonObject.getString("resCipher"); + String decrypt = decrypt(string); + JSONObject jsonObject = JSONObject.parseObject(decrypt); + return jsonObject; + } + public static JSONObject balanceWithdraw(String orderNo,String payAmt, String memberId,String notifyUrl) throws Exception { + JSONObject data = new JSONObject(); + data.put("order_no", orderNo); + data.put("app_id", APP_ID); + data.put("amt", payAmt); + data.put("member_id", memberId); + data.put("notify_url", notifyUrl); + JSONObject body = new JSONObject(); + body.put("merId", MER_ID); + body.put("sign", sign(JSONObject.toJSONString(data))); + body.put("reqCipher", + EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); + body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); + String result = sendPost(BASE_URL + BALANCE_WITHDRAW_INTERFACE, body); + JSONObject resJsonObject = JSONObject.parseObject(result); + System.err.println(resJsonObject); + if (resJsonObject.getString("error_msg")!=null){ + return resJsonObject; + } + String string = resJsonObject.getString("resCipher"); + String decrypt = decrypt(string); + JSONObject jsonObject = JSONObject.parseObject(decrypt); + return jsonObject; + } + + /** + * 创建支付订单 + * + * @param orderNo 订单号 + * @param payChannel 支付渠道 1:支付宝 2:微信 + * @param payAmt 支付金额 + * @param goodsTitle 商品标题 + * @param goodsDesc 商品描述信息,微信小程序和微信公众号该字段 最大长度 42 个字符 + * @param deviceIp 设备支付公网ip + * @param openId 微信openId + * @param notifyUrl 回调地址 + * @return JSONObject + * @throws Exception + */ + public static JSONObject createPayment(String orderNo, Integer payChannel, String payAmt, + String goodsTitle, String goodsDesc, String deviceIp, String openId, + String notifyUrl) throws Exception { + JSONObject data = new JSONObject(); + JSONObject expand = new JSONObject(); + data.put("order_no", orderNo); + data.put("app_id", APP_ID); + if (payChannel == 1) { + data.put("pay_channel", PAY_CHANNEL_WECHAT); + expand.put("open_id", openId); + expand.put("wx_app_id", WX_APP_ID); + data.put("expand", expand); + } else { + data.put("pay_channel", PAY_CHANNEL_ALIPAY); + } + data.put("pay_amt", payAmt); + data.put("goods_title", goodsTitle); + data.put("goods_desc", goodsDesc); + Map<String, Object> deviceInfo = new HashMap<>(); + deviceInfo.put("device_ip", deviceIp); + data.put("device_info", deviceInfo); + data.put("notify_url", notifyUrl); + JSONObject body = new JSONObject(); + body.put("merId", MER_ID); + body.put("sign", sign(JSONObject.toJSONString(data))); + body.put("reqCipher", + EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); + body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); + String result = sendPost(BASE_URL + CREATE_PAYMENT_INTERFACE, body); + JSONObject resJsonObject = JSONObject.parseObject(result); + System.err.println(resJsonObject); + String string = resJsonObject.getString("resCipher"); + String decrypt = decrypt(string); + System.err.println(decrypt); + JSONObject jsonObject = JSONObject.parseObject(decrypt); + +// if (resJsonObject.getString("status").equals("failed")) { +// throw new ServiceException(resJsonObject.getString("error_msg")); +// } +// if (resJsonObject.getString("status").equals("succeeded")) { +// return resJsonObject.getJSONObject("expand"); +// } + return jsonObject; + } + public static JSONObject createPaymentCode(String orderNo, Integer payChannel, String payAmt, + String goodsTitle, String goodsDesc, String deviceIp, String openId, + String notifyUrl) throws Exception { + JSONObject data = new JSONObject(); + JSONObject expand = new JSONObject(); + data.put("order_no", orderNo); + data.put("app_id", APP_ID); + if (payChannel == 1) { + data.put("pay_channel", PAY_CHANNEL_ALIPAY); + } else { + data.put("pay_channel", PAY_CHANNEL_WECHAT); + expand.put("open_id", openId); + expand.put("wx_app_id", WX_APP_ID); + data.put("expand", expand); + } + data.put("pay_amt", payAmt); + data.put("goods_title", goodsTitle); + data.put("goods_desc", goodsDesc); + data.put("time_expire", "20241031000000"); + Map<String, Object> deviceInfo = new HashMap<>(); + deviceInfo.put("device_ip", deviceIp); + data.put("device_info", deviceInfo); + data.put("notify_url", notifyUrl); + JSONObject body = new JSONObject(); + body.put("merId", MER_ID); + body.put("sign", sign(JSONObject.toJSONString(data))); + body.put("reqCipher", + EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); + body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); + String result = sendPost(BASE_URL + CREATE_PAYMENT_INTERFACE_CODE, body); + JSONObject resJsonObject = JSONObject.parseObject(result); + System.err.println(resJsonObject); + String string = resJsonObject.getString("resCipher"); + String decrypt = decrypt(string); + System.err.println(decrypt); + JSONObject jsonObject = JSONObject.parseObject(decrypt); + +// if (resJsonObject.getString("status").equals("failed")) { +// throw new ServiceException(resJsonObject.getString("error_msg")); +// } +// if (resJsonObject.getString("status").equals("succeeded")) { +// return resJsonObject.getJSONObject("expand"); +// } + return jsonObject.getJSONObject("expand"); + } + /** + * 创建支付订单 微信托管支付 + * + * @param orderNo 订单号 + * @param payChannel 支付渠道 1:支付宝 2:微信 + * @param payAmt 支付金额 + * @param goodsTitle 商品标题 + * @param goodsDesc 商品描述信息,微信小程序和微信公众号该字段 最大长度 42 个字符 + * @param deviceIp 设备支付公网ip + * @param openId 微信openId + * @param notifyUrl 回调地址 + * @return JSONObject + * @throws Exception + */ + public static JSONObject createPayment1(String orderNo, Integer payChannel, String payAmt, + String goodsTitle, String goodsDesc, String deviceIp, String openId, + String notifyUrl) throws Exception { + JSONObject data = new JSONObject(); + JSONObject expand = new JSONObject(); + data.put("order_no", orderNo); + data.put("app_id", APP_ID); + data.put("pay_channel", PAY_CHANNEL_WECHAT_THiRD); + data.put("pay_amt", payAmt); + data.put("goods_title", goodsTitle); + data.put("goods_desc", goodsDesc); + Map<String, Object> deviceInfo = new HashMap<>(); + deviceInfo.put("device_ip", deviceIp); + data.put("device_info", deviceInfo); + data.put("notify_url", notifyUrl); + JSONObject body = new JSONObject(); + body.put("merId", MER_ID); + body.put("sign", sign(JSONObject.toJSONString(data))); + body.put("reqCipher", + EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); + body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); + String result = sendPost(BASE_URL + CREATE_PAYMENT_INTERFACE_THIRD, body); + JSONObject resJsonObject = JSONObject.parseObject(result); + System.err.println(resJsonObject); + String string = resJsonObject.getString("resCipher"); + String decrypt = decrypt(string); + System.err.println("解密后"+decrypt); + JSONObject jsonObject = JSONObject.parseObject(decrypt); + +// if (resJsonObject.getString("status").equals("failed")) { +// throw new ServiceException(resJsonObject.getString("error_msg")); +// } +// if (resJsonObject.getString("status").equals("succeeded")) { +// return resJsonObject.getJSONObject("expand"); +// } + return jsonObject; + } + + /** + * 申请退款 + * + * @param paymentId 支付单号 + * @param orderNo 订单号 + * @return + */ + public static JSONObject refund(String paymentId, String orderNo) throws Exception { + JSONObject data = new JSONObject(); + data.put("payment_id", paymentId); + data.put("order_no", orderNo); + JSONObject body = new JSONObject(); + body.put("merId", MER_ID); + body.put("sign", sign(JSONObject.toJSONString(data))); + body.put("reqCipher", + EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); + body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); + String result = sendPost(BASE_URL + PAYMENT_REFUND_INTERFACE, body); + JSONObject resJsonObject = JSONObject.parseObject(result); + if (resJsonObject.getString("error_msg")!=null){ + return resJsonObject; + } + System.err.println(resJsonObject); + String string = resJsonObject.getString("resCipher"); + String decrypt = decrypt(string); + System.err.println("解密后"+decrypt); + JSONObject jsonObject = JSONObject.parseObject(decrypt); + return jsonObject; + } + public static JSONObject queryPayment(String paymentId) throws Exception { + JSONObject data = new JSONObject(); + data.put("payment_id", paymentId); + JSONObject body = new JSONObject(); + body.put("merId", MER_ID); + body.put("sign", sign(JSONObject.toJSONString(data))); + body.put("reqCipher", + EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); + body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); + String result = sendPost(BASE_URL + QUERY_PAYMENT_INTERFACE, body); + JSONObject resJsonObject = JSONObject.parseObject(result); + if (resJsonObject.getString("error_msg")!=null){ + return resJsonObject; + } + System.err.println(resJsonObject); + String string = resJsonObject.getString("resCipher"); + String decrypt = decrypt(string); + System.err.println("解密后"+decrypt); + JSONObject jsonObject = JSONObject.parseObject(decrypt); + return jsonObject; + } + + /** + * 商户付款 + * + * @param orderNo 订单号 + * @param payAmt 交易金额 + * @param cardName 收款银行开户名 + * @param cardId 收款银行卡号 + * @param cardType 收款银行账户类型 DEBIT_CARD:借记卡 CREDIT_CARD:贷记卡 76 QUASI_CREDIT_CARD:准贷卡 PASSBOOK:存折 + * UNIT_SETTLE_CARD:单位结算卡 PUBLIC_CARD:对公卡 + * @return + * @throws Exception + */ + public static JSONObject merchantPay(String orderNo, String payAmt, String cardName, String cardId, + String cardType) + throws Exception { + JSONObject data = new JSONObject(); + data.put("order_no", orderNo); + data.put("app_id", APP_ID); + data.put("pay_amt", payAmt); + data.put("card_name", cardName); + data.put("card_id", cardId); + data.put("card_type", cardType); + JSONObject body = new JSONObject(); + body.put("merId", MER_ID); + body.put("sign", sign(JSONObject.toJSONString(data))); + body.put("reqCipher", + EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); + body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmss")); + String result = sendPost(BASE_URL + MERCHANT_PAY_INTERFACE, body); + JSONObject resJsonObject = JSONObject.parseObject(result); + System.err.println(resJsonObject); + String string = resJsonObject.getString("resCipher"); + String decrypt = decrypt(string); + System.err.println("解密后"+decrypt); + JSONObject jsonObject = JSONObject.parseObject(decrypt); + return jsonObject; + } + + /** + * 发送post请求 + * + * @param url 请求地址 + * @param body 请求体 + * @return + */ + private static String sendPost(String url, JSONObject body) { + HttpRequest post = HttpUtil.createPost(url); + Map<String, String> headers = new HashMap<>(); + headers.put("Content-type", "application/json; charset=utf-8"); + headers.put("Accept", "application/json"); + post.addHeaders(headers); + post.body(body.toJSONString()); + HttpResponse execute = post.execute(); + String result = execute.body(); + execute.close(); + if (StringUtils.isBlank(result)) { + throw new ServiceException("请求第三方支付平台异常"); + } + return result; + } + + + + /** + * RSA私钥签名:签名方式SHA256WithRSA + * + * @param data 待签名字符串 + * @return 签名byte[] + * @throws Exception + */ + public static String sign(String data) { + // 先对该json对象数据按照参数字典顺序(参数名ASCII码从小到大排序,参数名区分大小写)排序生成字符串,再进行加签和验签。 + data = JSON.toJSONString(JSONObject.parseObject(data, TreeMap.class)); + // Base64 --> Key + try { +// byte[] bytes = Base64.getDecoder().decode(MERCHANT_PRIVATE_KEY); + byte[] bytes = Base64.getDecoder().decode("MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAKOuwQkWiVCNY5SI" + + "w6fXcIHj/e8UuQ5Gro1v4yguVnNhCdC6HsWbF6jf1ios8CQKxIQViI2I8GfVPsjB" + + "Bpfp7TK5zup0BHHYg7JUk0tC6ojL8WgbtVpKX7GJFQOdjNbZmYBlDQuBiCfvxWuL" + + "ki8juL8NlY4aj7FgSDboSHq7A+ZjAgMBAAECgYAEhei5qpDC1BVjXmAhvDdUr4st" + + "1yHB/jwGloftbVJgP9c4mFwPU9jUhtLxOWqtZErH55xtZNJX3DGu9H6NJh6y09UC" + + "LdQJJY2/BQBrTlDsVFQl5h2PwDOO+qwUkZPTVd+822Sv0lukVS4c5sCwcdYwShmi" + + "IQCuudpygHDCBxJ6AQJBANAmfr6j8PxnCKlSUfaO1PqcnT6BGOJEBbnT0CGiKwNw" + + "XKecEKh5O8Ev4Ak9FhGad4eFkKZDNvHLE+yfCPy8nwECQQDJT10Hwi9+1KFdTacQ" + + "rC94fZzipuqBOeVzgTPQrQ0iM38uKx5Sj5o4Ii9cyfkw2EoG/gFSim57U/OApLab" + + "22ljAkBoL0xzWZWOkHfaYHTcB0P9KJTgKzfsUQXYrHdZzlTfRMdrsYb4/K13FeJ6" + + "XVQFfZ5ke+sZ/TysK+yOHFAgSL0BAkAXLdYuYIOLfPwffCNyXgERRJVd245A1uO+" + + "iu/mZSaP+5H3ROu24eYF9Jmze2X/48eSSojochwKgz4UX+LOy1K1AkBQycFQjRWC" + + "jPi8biMhdLzzX47CNFkwigVp0At6VcZmb86cS9ohoTHCbeG0+hlX7p9eNMiFKLVn" + + "nCdjY6j1xqtv"); + PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(bytes); + KeyFactory keyFactory; + keyFactory = KeyFactory.getInstance("RSA"); + PrivateKey privateKey = keyFactory.generatePrivate(keySpec); + // Sign + Signature signature = Signature.getInstance("SHA256WithRSA"); + signature.initSign(privateKey); + signature.update(data.getBytes("UTF-8")); + return Base64.getEncoder().encodeToString(signature.sign()); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + public static String decrypt(String strToDecrypt) { + try { + SecretKeySpec secretKey = new SecretKeySpec(AES_KEY.getBytes(), "AES"); + Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); + cipher.init(Cipher.DECRYPT_MODE, secretKey); + return new String(cipher.doFinal(Base64.getDecoder().decode(strToDecrypt))); + } catch (Exception e) { + System.out.println("Error while decrypting: " + e.toString()); + } + return null;} +// public static boolean verify(String data, String publicKeyStr) { +// try { +// // 解码公钥 +// byte[] publicKeyBytes = Base64.getDecoder().decode(publicKeyStr); +// X509EncodedKeySpec keySpec = new X509EncodedKeySpec(publicKeyBytes); +// KeyFactory keyFactory = KeyFactory.getInstance("RSA"); +// PublicKey publicKey = keyFactory.generatePublic(keySpec); +// // 验证签名 +// Signature signature = Signature.getInstance("SHA256WithRSA"); +// signature.initVerify(publicKey); +// signature.update(data.getBytes("UTF-8")); +// +// return true; +// } catch (Exception e) { +// e.printStackTrace(); +// return false; +// } +// } + +} diff --git a/xinquan-common/xinquan-common-security/src/main/java/com/xinquan/common/security/service/TokenService.java b/xinquan-common/xinquan-common-security/src/main/java/com/xinquan/common/security/service/TokenService.java index d4a3a53..1670d08 100644 --- a/xinquan-common/xinquan-common-security/src/main/java/com/xinquan/common/security/service/TokenService.java +++ b/xinquan-common/xinquan-common-security/src/main/java/com/xinquan/common/security/service/TokenService.java @@ -162,6 +162,8 @@ // 根据uuid将loginUser缓存 String userKey = getTokenKey(loginUser.getToken()); redisService.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES); + // 存放token 到 redis 获取用户id + redisService.setCacheObject(loginUser.getAppUserId()+"", userKey, expireTime, TimeUnit.MINUTES); } private void refreshToken4AppLoginUser(AppLoginUser appLoginUser) { @@ -199,6 +201,7 @@ appLoginUser.setUserid(userId); appLoginUser.setIpaddr(IpUtils.getIpAddr()); LoginUser loginUser = new LoginUser(); + loginUser.setAppUserId(appLoginUser.getAppUserId()); loginUser.setSysUser(appLoginUser.getSysUser()); loginUser.setToken(token); loginUser.setUserid(userId); diff --git a/xinquan-modules/xinquan-course/src/main/java/com/xinquan/course/controller/client/ClientCourseChapterController.java b/xinquan-modules/xinquan-course/src/main/java/com/xinquan/course/controller/client/ClientCourseChapterController.java index cbb3ee4..6061882 100644 --- a/xinquan-modules/xinquan-course/src/main/java/com/xinquan/course/controller/client/ClientCourseChapterController.java +++ b/xinquan-modules/xinquan-course/src/main/java/com/xinquan/course/controller/client/ClientCourseChapterController.java @@ -58,12 +58,10 @@ } for (CourseChapter record : page.getRecords()) { record.setUid(record.getId()+""); - int a = 0; int b = 0; - a+= record.getVirtualLearnedNum(); Long data1 = remoteAppUserService.getCourseChapterHistoryCount(record.getId()).getData(); b+=data1; - record.setRealLearnedNum(a+b); + record.setRealLearnedNum(b); } return R.ok(PageDTO.of(page, CourseChapter.class)); diff --git a/xinquan-modules/xinquan-course/src/main/java/com/xinquan/course/controller/client/ClientCourseController.java b/xinquan-modules/xinquan-course/src/main/java/com/xinquan/course/controller/client/ClientCourseController.java index 8c48a63..fb64539 100644 --- a/xinquan-modules/xinquan-course/src/main/java/com/xinquan/course/controller/client/ClientCourseController.java +++ b/xinquan-modules/xinquan-course/src/main/java/com/xinquan/course/controller/client/ClientCourseController.java @@ -342,18 +342,17 @@ long count1 = courseUserFavoriteService.count(new LambdaQueryWrapper<CourseUserFavorite>() .eq(CourseUserFavorite::getCourseId, record.getId())); record.setCollectCount(count1); - // 查询学习人数 -// record.setCount(remoteAppUserService.getUserByCourseId(record.getId()).getData().size()); - int size1 = courseLearningRecordService.lambdaQuery().eq(CourseLearningRecord::getCourseId, record.getId()) - .groupBy(CourseLearningRecord::getAppUserId).list().size(); List<CourseChapter> list = courseChapterService.lambdaQuery() .eq(CourseChapter::getCourseId, record.getId()).list(); - // 章节列表累加虚拟学习人数 - int temp = 0; + int a = 0; + int b = 0; for (CourseChapter courseChapter : list) { - temp+=courseChapter.getVirtualLearnedNum(); + a+= courseChapter.getVirtualLearnedNum(); + Long data1 = remoteAppUserService.getCourseChapterHistoryCount(courseChapter.getId()).getData(); + b+=data1; + courseChapter.setRealLearnedNum(Integer.valueOf(data1+"")); } - record.setCount(size1+temp); + record.setCount(a+b); } return R.ok(PageDTO.of(page, Course.class)); } @@ -381,10 +380,9 @@ a+= courseChapter.getVirtualLearnedNum(); Long data1 = remoteAppUserService.getCourseChapterHistoryCount(courseChapter.getId()).getData(); b+=data1; + courseChapter.setRealLearnedNum(Integer.valueOf(data1+"")); } - int size1 = courseLearningRecordService.lambdaQuery() - .eq(CourseLearningRecord::getCourseId, uid).groupBy(CourseLearningRecord::getAppUserId) - .list().size(); + byId.setVirtualLearnedNum(a); byId.setRealLearnedNum(b); byId.setCount(a+b); @@ -616,7 +614,6 @@ @ApiImplicitParam(value = "课程id", name = "id", required = true, dataType = "String"), }) public R<ClientCourseVO> getPayCourseInfoById(@RequestParam(value = "id")Long id) { - Course byId = courseService.getById(id); ClientCourseVO clientCourseVO = new ClientCourseVO(); BeanUtils.copyProperties(byId, clientCourseVO); @@ -1012,7 +1009,10 @@ course.setRealLearnedNum(a+b); course.setVirtualLearnedNum(0); BeanUtils.copyProperties(course, courseVO); - courseVOS.add(courseVO); + List<Long> collect = courseVOS.stream().map(CourseVO::getId).collect(Collectors.toList()); + if (!collect.contains(courseVO.getId())){ + courseVOS.add(courseVO); + } } } List<Long> data1 = remoteAppUserService.getCourseHistoryByUserId(userId).getData(); @@ -1035,7 +1035,10 @@ courseVO.setVirtualLearnedNum(0); courseVO.setId(byId.getId()); courseVO.setCoverUrl(byId.getCoverUrl()); - courseVOS.add(courseVO); + List<Long> collect = courseVOS.stream().map(CourseVO::getId).collect(Collectors.toList()); + if (!collect.contains(courseVO.getId())){ + courseVOS.add(courseVO); + } } } // 查询两个相同类型的线上免费课程 @@ -1099,7 +1102,10 @@ courseVO.setVirtualLearnedNum(0); courseVO.setId(byId.getId()); courseVO.setCoverUrl(byId.getCoverUrl()); - courseVOS.add(courseVO); + List<Long> collect = courseVOS.stream().map(CourseVO::getId).collect(Collectors.toList()); + if (!collect.contains(courseVO.getId())){ + courseVOS.add(courseVO); + } } } studyPageVO.setCourseList(courseVOS); diff --git a/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/controller/client/ClientOrderController.java b/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/controller/client/ClientOrderController.java index f26ac42..5a5e1d1 100644 --- a/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/controller/client/ClientOrderController.java +++ b/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/controller/client/ClientOrderController.java @@ -11,6 +11,7 @@ import com.sun.corba.se.spi.ior.IdentifiableFactory; import com.xinquan.common.core.constant.SecurityConstants; import com.xinquan.common.core.domain.R; +import com.xinquan.common.core.utils.JuHeFuUtil; import com.xinquan.common.core.utils.page.BeanUtils; import com.xinquan.common.core.utils.page.CollUtils; import com.xinquan.common.core.utils.page.PageDTO; @@ -93,6 +94,17 @@ private SysUserClient sysUserClient; @Autowired private TokenService tokenService; + + @ResponseBody + @PostMapping("/queryPayment") + @ApiOperation(value = "查询订单支付状态", tags = "查询订单支付状态") + @ApiImplicitParams({ + @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "String", required = true), + }) + public R<String> queryPayment(@RequestParam(value = "orderId") String orderId) throws Exception { + JSONObject jsonObject = JuHeFuUtil.queryPayment(orderId); + return R.ok(jsonObject.getString("status")); + } @GetMapping("/getMeditationIsBuy/{id}/{meditationId}") public R<Integer> getMeditationIsBuy(@PathVariable("id")Long id,@PathVariable("meditationId")Long meditationId) { List<Order> list = orderService.lambdaQuery().eq(Order::getBusinessId, meditationId) @@ -225,11 +237,13 @@ Course data4 = remoteCourseService.getCourseById(data.getBusinessId()).getData(); List<CourseChapter> data2 = remoteCourseService.getChapterByCourseId(orderCourseVO.getBusinessId() + "").getData(); int temp = 0 ; + int b = 0 ; for (CourseChapter courseChapter : data2) { temp+=courseChapter.getVirtualLearnedNum(); + Long data9 = remoteAppUserService.getCourseChapterHistoryCount(courseChapter.getId()).getData(); + b+=data9; } - Integer data3 = remoteCourseService.getCountByCourseId(orderCourseVO.getBusinessId() + "").getData(); - orderCourseVO.setCount(data3+temp); + orderCourseVO.setCount(b+temp); if (data4!=null){ orderCourseVO.setCourseTitle(data4.getCourseTitle()); orderCourseVO.setCoverUrl(data4.getCoverUrl()); @@ -302,10 +316,12 @@ * @return 下单返回数据视图对象 * @see com.xinquan.order.domain.vo.ClientPlaceOrderVO */ + @PostMapping("/placeOrder") @ApiOperation(value = "创建支付订单", notes = "微信|支付宝") @ApiImplicitParams({ @ApiImplicitParam(name = "targetId", value = "目标id 订单类型为会员和充值时不传", dataType = "Long", required = false), + @ApiImplicitParam(name = "type", value = "类型 用于判断苹果支付还是安卓支付", dataType = "Long", required = false), @ApiImplicitParam(name = "orderId", value = "订单id 待支付时传", dataType = "Long", required = false), @ApiImplicitParam(name = "orderFrom", value = "订单来源 1=冥想音频 2=课程 3=购买会员 4充值", dataType = "Integer", required = true), @ApiImplicitParam(name = "receiverId", value = "被赠送课程APP用户id", dataType = "Long", required = false), @@ -316,6 +332,7 @@ }) public R<ClientPlaceOrderVO> placeOrder( @RequestParam(value = "targetId", required = false) Long targetId, + @RequestParam(value = "type", required = false) Integer type, @RequestParam(value = "orderId", required = false) Long orderId, @RequestParam(value = "orderFrom") Integer orderFrom, @RequestParam(value = "receiverId", required = false) Long receiverId, @@ -323,12 +340,14 @@ @RequestParam(value = "payType") Integer payType, @RequestParam(value = "amount", required = false) BigDecimal amount, @RequestParam(value = "vipType", required = false) Integer vipType) + { try { - + ClientPlaceOrderVO clientPlaceOrderVO = orderService.placeOrder(targetId, orderFrom, receiverId, orderId, + balanceFlag, payType, amount, vipType,type); + System.err.println("支付返回参数"+clientPlaceOrderVO); return R.ok( - orderService.placeOrder(targetId, orderFrom, receiverId,orderId, - balanceFlag, payType,amount,vipType)); + clientPlaceOrderVO); } catch (Exception e) { throw new RuntimeException(e); } @@ -343,11 +362,16 @@ public R refund(@RequestParam(value = "uid") String uid, @RequestParam(value = "remark") String remark) throws Exception { Order byId = orderService.getById(uid); + String refund = orderService.refund(Long.valueOf(uid)); + if (refund!=null && (!refund.equals("success"))){ + return R.fail(refund); + } byId.setRefundStatus(2); byId.setRefundRemark(remark); byId.setPaymentStatus(3); + byId.setRefundTime(LocalDateTime.now()); orderService.updateById(byId); - orderService.refund(Long.valueOf(uid)); + return R.ok(); } @ResponseBody @@ -490,7 +514,7 @@ // if (data1.getProportion() != null) { // // BigDecimal bigDecimal = one1.getPayAmount().multiply(data1.getProportion()).divide(new BigDecimal("100")) -// .setScale(2, BigDecimal.ROUND_HALF_DOWN); +// .setScale(2, BigDecimal.ROUND_DOWN); // // 上级获取的分佣金额 // AppUser appUserById = remoteAppUserService.getAppUserById(data.getInviteUserId() + "").getData(); // // 更新用户余额 @@ -551,7 +575,7 @@ // 支付金额 String string3 = jsonObject1.getString("pay_fee"); Order one = orderService.lambdaQuery().eq(Order::getBizOrderNo, string).one(); - if (one.getPaymentStatus()==2){ + if (one.getPaymentStatus()!=1){ return; } one.setPaymentStatus(2); @@ -560,8 +584,7 @@ .ne(OrderPaymentRecord::getPaymentType, 4).one(); if (one2!=null){ one2.setPaymentStatus(2); - // 扣除用户余额 - Object data = remoteAppUserService.deleteBalance(one.getAppUserId() + "", one2.getPayAmount() + "").getData(); + one2.setPayOrderNo(string2); orderPaymentRecordService.updateById(one2); } // 实际支付金额 @@ -585,7 +608,7 @@ if (data1.getProportion() != null) { BigDecimal bigDecimal = one1.getPayAmount().multiply(data1.getProportion()).divide(new BigDecimal("100")) - .setScale(2, BigDecimal.ROUND_HALF_DOWN); + .setScale(2, BigDecimal.ROUND_DOWN); // 上级获取的分佣金额 AppUser appUserById = remoteAppUserService.getAppUserById(data.getInviteUserId() + "").getData(); // 更新用户余额 @@ -696,7 +719,7 @@ e.printStackTrace(); } } - private static final String AES_KEY = "cb0a181ac97395c6942be19315fc0727"; + private static final String AES_KEY = "6d548eb01bad44bbbb4a23743e733103"; public static String decrypt(String strToDecrypt) { try { SecretKeySpec secretKey = new SecretKeySpec(AES_KEY.getBytes(), "AES"); @@ -782,7 +805,7 @@ if (data1.getProportion() != null) { BigDecimal bigDecimal = one1.getPayAmount().multiply(data1.getProportion()).divide(new BigDecimal("100")) - .setScale(2, BigDecimal.ROUND_HALF_DOWN); + .setScale(2, BigDecimal.ROUND_DOWN); // 上级获取的分佣金额 AppUser appUserById = remoteAppUserService.getAppUserById(data9.getInviteUserId() + "").getData(); // 更新用户余额 @@ -998,22 +1021,29 @@ OrderPaymentRecord two = orderPaymentRecordService.lambdaQuery() .eq(OrderPaymentRecord::getOrderId, orderId) .ne(OrderPaymentRecord::getPaymentType, 4) - .eq(OrderPaymentRecord::getPaymentStatus, 2).one(); + .ne(OrderPaymentRecord::getPaymentStatus, 1).one(); + OrderPaymentRecord three = orderPaymentRecordService.lambdaQuery() + .eq(OrderPaymentRecord::getOrderId, orderId) + .eq(OrderPaymentRecord::getPaymentType, 4) + .ne(OrderPaymentRecord::getPaymentStatus, 1).one(); if (two==null){ one.setRemark("余额支付"); one.setBalance(one.getTotalAmount()); }else{ - switch (two.getPaymentType()){ - case 1: - one.setRemark("微信支付"); + switch (one.getPayType()){ + case 5: + one.setRemark("微信支付+余额"); break; - case 2: - one.setRemark("支付宝支付"); + case 6: + one.setRemark("支付宝支付+余额"); break; - case 3: - one.setRemark("苹果内购"); + case 7: + one.setRemark("苹果内购+余额"); } one.setPayOrderNo(two.getPayOrderNo()); + if (three!=null){ + one.setBalance(three.getPayAmount()); + } } if (one.getCommissionId()!=null){ switch (one.getOrderFrom()){ diff --git a/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/domain/vo/ClientPlaceOrderVO.java b/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/domain/vo/ClientPlaceOrderVO.java index 4e1aef2..73dc32a 100644 --- a/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/domain/vo/ClientPlaceOrderVO.java +++ b/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/domain/vo/ClientPlaceOrderVO.java @@ -19,6 +19,8 @@ @ApiModelProperty(value = "订单编号") private String orderNo; + @ApiModelProperty(value = "三方支付id 用于查询订单状态") + private String orderId; @ApiModelProperty(value = "金额为零无需支付 1是 2否") private Integer zeroFlag; diff --git a/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/service/OrderService.java b/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/service/OrderService.java index 724763c..44e2463 100644 --- a/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/service/OrderService.java +++ b/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/service/OrderService.java @@ -29,7 +29,7 @@ * @see com.xinquan.order.domain.vo.ClientPlaceOrderVO */ ClientPlaceOrderVO placeOrder(Long targetId, Integer orderFrom, Long receiverId,Long orderId, - Integer balanceFlag, Integer payType,BigDecimal amount,Integer vipType) throws Exception; + Integer balanceFlag, Integer payType,BigDecimal amount,Integer vipType,Integer type) throws Exception; /** * 根据类型获取已完成的订单列表 diff --git a/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/service/impl/OrderServiceImpl.java b/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/service/impl/OrderServiceImpl.java index b52f0b0..b92359d 100644 --- a/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/service/impl/OrderServiceImpl.java +++ b/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/service/impl/OrderServiceImpl.java @@ -1,11 +1,8 @@ package com.xinquan.order.service.impl; import com.alibaba.fastjson2.JSONObject; -import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.C; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.xinquan.common.core.constant.Constants; import com.xinquan.common.core.constant.SecurityConstants; -import com.xinquan.common.core.domain.R; import com.xinquan.common.core.enums.ChargeTypeEnum; import com.xinquan.common.core.enums.DisabledEnum; import com.xinquan.common.core.enums.PaymentStatusEnum; @@ -13,7 +10,6 @@ import com.xinquan.common.core.exception.ServiceException; import com.xinquan.common.core.utils.ip.IpUtils; import com.xinquan.common.security.service.TokenService; -import com.xinquan.common.security.utils.SecurityUtils; import com.xinquan.course.api.domain.Course; import com.xinquan.course.api.feign.RemoteCourseService; import com.xinquan.meditation.api.domain.Meditation; @@ -24,15 +20,19 @@ import com.xinquan.order.mapper.OrderMapper; import com.xinquan.order.service.OrderPaymentRecordService; import com.xinquan.order.service.OrderService; -import com.xinquan.order.utils.JuHeFuUtil; +import com.xinquan.common.core.utils.JuHeFuUtil; import com.xinquan.order.utils.OrderUtil; import com.xinquan.system.api.domain.AppUser; +import com.xinquan.system.api.domain.AppUserWalletRecord; import com.xinquan.system.api.model.LoginUser; import com.xinquan.user.api.domain.dto.AppUserDTO; import com.xinquan.user.api.feign.RemoteAppUserService; import java.math.BigDecimal; import java.math.RoundingMode; +import java.time.LocalDateTime; import java.util.List; + +import lombok.Data; import lombok.RequiredArgsConstructor; import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; @@ -77,7 +77,7 @@ @Override @Transactional(rollbackFor = Exception.class) public ClientPlaceOrderVO placeOrder(Long targetId, Integer orderFrom, Long receiverId, Long orderId, - Integer balanceFlag, Integer payType,BigDecimal amount,Integer vipType) throws Exception { + Integer balanceFlag, Integer payType,BigDecimal amount,Integer vipType,Integer type) throws Exception { // 获取当前登录用户id LoginUser loginUser = tokenService.getLoginUser(); if (loginUser==null){ @@ -91,6 +91,9 @@ AppUser appUser = getAppUserById(userId); ClientPlaceOrderVO clientPlaceOrderVO = new ClientPlaceOrderVO(); Order order = new Order(); + order.setPayType(payType); + AppUser data = remoteAppUserService.getAppUserById(userId + "").getData(); + // 购买冥想音频 if (orderFrom == 1) { Meditation meditation = remoteMeditationService.getMeditationById(targetId, @@ -106,41 +109,33 @@ order.setBizOrderNo(orderNo); order.setBusinessId(meditation.getId()); order.setAppUserId(userId); - order.setRealPayAmount(meditation.getGeneralPrice()); + order.setRealPayAmount(type==null?meditation.getGeneralPrice():meditation.getIosPrice()); + order.setTotalAmount(type==null?meditation.getGeneralPrice():meditation.getIosPrice()); order.setPayType(payType); order.setBuyContent("购买疗愈【"+meditationTitle+"】"); - order.setTotalAmount(meditation.getGeneralPrice()); order.setGiveUserId(receiverId); this.save(order); }else{ order = this.getById(orderId); - order.setBuyContent("购买疗愈【"+meditationTitle+"】"); + order.setBuyContent("购买疗愈【"+meditationTitle+"】"); } Long orderId9 = order.getId(); clientPlaceOrderVO.setOrderNo(orderNo); clientPlaceOrderVO.setId(orderId9); + // 如果冥想音频价格设定为单独收费,且需要使用余额抵扣 - if (balanceFlag.equals(1) && meditation.getChargeType().equals(ChargeTypeEnum.SEPARATE_CHARGE.getCode())) { + if (data.getBalance().compareTo(new BigDecimal("0")) > 0 && balanceFlag.equals(1) && meditation.getChargeType().equals(ChargeTypeEnum.SEPARATE_CHARGE.getCode())) { BigDecimal needPayAmount = handleBalancePayment(appUser, - meditation.getGeneralPrice(), + type==null?meditation.getGeneralPrice():meditation.getIosPrice(), orderId9); if (needPayAmount.compareTo(BigDecimal.ZERO) <= 0) { clientPlaceOrderVO.setZeroFlag(DisabledEnum.YES.getCode()); // 抵扣后金额为0 为余额支付 order.setPayType(4); - order.setRealPayAmount(meditation.getGeneralPrice()); order.setBuyContent("购买疗愈【"+meditationTitle+"】"); this.updateById(order); return clientPlaceOrderVO; - }else{ - // 余额抵扣不完 - OrderPaymentRecord one = orderPaymentRecordService.lambdaQuery().eq(OrderPaymentRecord::getPaymentType, 4) - .eq(OrderPaymentRecord::getOrderId, orderId9).one(); - if (one!=null){ - one.setPayAmount(meditation.getGeneralPrice().subtract(needPayAmount)); - orderPaymentRecordService.updateById(one); - } } if (payType==1){ // 微信+余额 @@ -156,7 +151,7 @@ wxOpenId, orderId9, clientPlaceOrderVO); } else { // 创建支付订单 - createPayment(payType, orderNo, meditation.getGeneralPrice(), meditationTitle, + createPayment(payType, orderNo, type==null?order.getRealPayAmount():order.getRealPayAmount(), meditationTitle, detailDescription, wxOpenId, orderId9, clientPlaceOrderVO); } } @@ -174,10 +169,11 @@ order.setBizOrderNo(orderNo); order.setGiveUserId(receiverId); order.setBusinessId(course.getId()); + order.setAppUserId(userId); order.setBuyContent("购买课程【"+courseTitle+"】"); - order.setRealPayAmount(course.getGeneralPrice()); - order.setTotalAmount(course.getGeneralPrice()); + order.setRealPayAmount(type==null?course.getGeneralPrice():course.getIosPrice()); + order.setTotalAmount(type==null?course.getGeneralPrice():course.getIosPrice()); this.save(order); }else{ order = this.getById(orderId); @@ -188,28 +184,19 @@ clientPlaceOrderVO.setOrderNo(orderNo); clientPlaceOrderVO.setId(orderId8); - if (balanceFlag.equals(1) && course.getChargeType() + if (data.getBalance().compareTo(new BigDecimal("0")) > 0 && balanceFlag.equals(1) && course.getChargeType() .equals(ChargeTypeEnum.SEPARATE_CHARGE.getCode())) { - BigDecimal needPayAmount = handleBalancePayment(appUser, course.getGeneralPrice(), + BigDecimal needPayAmount = handleBalancePayment(appUser, type==null?course.getGeneralPrice():course.getIosPrice(), orderId8); if (needPayAmount.compareTo(BigDecimal.ZERO) <= 0) { clientPlaceOrderVO.setZeroFlag(DisabledEnum.YES.getCode()); // 抵扣后金额为0 为余额支付 order.setPayType(4); - order.setRealPayAmount(course.getGeneralPrice()); order.setBuyContent("购买课程【"+courseTitle+"】"); this.updateById(order); return clientPlaceOrderVO; - }else{ - // 余额抵扣不完 - OrderPaymentRecord one = orderPaymentRecordService.lambdaQuery().eq(OrderPaymentRecord::getPaymentType, 4) - .eq(OrderPaymentRecord::getOrderId, orderId8).one(); - if (one!=null){ - one.setPayAmount(course.getGeneralPrice().subtract(needPayAmount)); - orderPaymentRecordService.updateById(one); - } } if (payType==1){ // 微信+余额 @@ -226,7 +213,7 @@ wxOpenId, orderId8, clientPlaceOrderVO); } else { // 创建支付订单 - createPayment(payType, orderNo, course.getGeneralPrice(), courseTitle, + createPayment(payType, orderNo, order.getRealPayAmount(), courseTitle, description, wxOpenId, orderId8, clientPlaceOrderVO); } } @@ -298,21 +285,40 @@ if (appUser.getBalance().compareTo(BigDecimal.ZERO) < 0) { throw new ServiceException("用户可用余额不足,请重新选择支付方案"); } - // 更新用户余额 - remoteAppUserService.updateAppUser( - AppUserDTO.builder().balance( - appUser.getBalance().subtract(generalPrice)) - .build(), SecurityConstants.INNER); + Order one = this.lambdaQuery().eq(Order::getId, orderId).one(); - OrderPaymentRecord balancePaymentRecord = new OrderPaymentRecord(); - balancePaymentRecord.setOrderId(orderId); - balancePaymentRecord.setPaymentType(PaymentTypeEnum.BALANCE_PAY.getCode()); - balancePaymentRecord.setPaymentStatus(PaymentStatusEnum.COMPLETED.getCode()); - orderPaymentRecordService.save(balancePaymentRecord); + // 如果余额大于通用价格 则实际支付价格为0 + if (appUser.getBalance().compareTo(one.getRealPayAmount())>=0){ + // 更新用户余额 +// remoteAppUserService.updateAppUser( +// AppUserDTO.builder().balance( +// appUser.getBalance().subtract(one.getRealPayAmount())) +// .build(), SecurityConstants.INNER); + OrderPaymentRecord balancePaymentRecord = new OrderPaymentRecord(); + balancePaymentRecord.setOrderId(orderId); + balancePaymentRecord.setPayAmount(one.getRealPayAmount()); + balancePaymentRecord.setPaymentType(PaymentTypeEnum.BALANCE_PAY.getCode()); + balancePaymentRecord.setPaymentStatus(PaymentStatusEnum.COMPLETED.getCode()); + orderPaymentRecordService.save(balancePaymentRecord); + return new BigDecimal("0"); + }else { + // 更新用户余额 +// remoteAppUserService.updateAppUser( +// AppUserDTO.builder().balance( +// one.getRealPayAmount().subtract(appUser.getBalance())) +// .build(), SecurityConstants.INNER); - // 计算除去余额还需支付的金额 - return generalPrice - .subtract(appUser.getBalance()); + OrderPaymentRecord balancePaymentRecord = new OrderPaymentRecord(); + balancePaymentRecord.setOrderId(orderId); + balancePaymentRecord.setPaymentType(PaymentTypeEnum.BALANCE_PAY.getCode()); + balancePaymentRecord.setPaymentStatus(PaymentStatusEnum.COMPLETED.getCode()); + balancePaymentRecord.setPayAmount(appUser.getBalance()); + orderPaymentRecordService.save(balancePaymentRecord); + // 计算除去余额还需支付的金额 + return one.getRealPayAmount() + .subtract(appUser.getBalance()); + } + } /** @@ -348,8 +354,9 @@ JSONObject payInfo = JuHeFuUtil.createPayment1(orderNo, payType, needPayAmount.toString(), goodsTitle, goodsDesc, IpUtils.getIpAddr(), wxOpenId, - // "https://v7ro848ar5jx.ngrok.xiaomiqiu123.top/order/client/order/order/base/callback") - "https://xq.xqzhihui.com/api/order/client/order/order/base/callback"); + "https://xq.xqzhihui.com/api/order/client/order/order/base/callback" +// "https://xq.xqzhihui.com/api/order/client/order/order/base/callback" + ); // 第三方支付记录 OrderPaymentRecord paymentRecord = new OrderPaymentRecord(); paymentRecord.setOrderId(orderId); @@ -358,10 +365,11 @@ clientPlaceOrderVO.setPayAmt(payInfo.getString("pay_amt")); clientPlaceOrderVO.setPath(payInfo.getJSONObject("expend").getString("path")); clientPlaceOrderVO.setPayInfo(payInfo.getJSONObject("expend").getString("pay_info")); - clientPlaceOrderVO.setOrgId(payInfo.getJSONObject("expend").getString("org_id")); - clientPlaceOrderVO.setAppId(payInfo.getJSONObject("expend").getString("app_id")); + clientPlaceOrderVO.setOrgId(payInfo.getJSONObject("expend").getString("orgId")); + clientPlaceOrderVO.setAppId(payInfo.getJSONObject("expend").getString("appId")); paymentRecord.setPaymentType(PaymentTypeEnum.WECHAT_PAY.getCode()); paymentRecord.setPayOrderNo(payInfo.getString("id")); + clientPlaceOrderVO.setOrderId(payInfo.getString("id")); paymentRecord.setPaymentStatus(PaymentStatusEnum.TO_BE_PAID.getCode()); paymentRecord.setPayAmount(needPayAmount); orderPaymentRecordService.save(paymentRecord); @@ -372,19 +380,25 @@ JSONObject payInfo = JuHeFuUtil.createPayment(orderNo, payType, needPayAmount.toString(), goodsTitle, goodsDesc, IpUtils.getIpAddr(), wxOpenId, - // "https://v7ro848ar5jx.ngrok.xiaomiqiu123.top/order/client/order/order/base/callback") - "https://xq.xqzhihui.com/api/order/client/order/order/base/callback"); + "https://xq.xqzhihui.com/api/order/client/order/order/base/callback" +// "https://xq.xqzhihui.com/api/order/client/order/order/base/callback" + + ); // 第三方支付记录 OrderPaymentRecord paymentRecord = new OrderPaymentRecord(); paymentRecord.setOrderId(orderId); paymentRecord.setPayAmount(needPayAmount); Order byId = this.getById(orderId); - byId.setPayOrderNo(payInfo.getString("id")); this.updateById(byId); - clientPlaceOrderVO.setQrcodeUrl(payInfo.getString("qrcode_url")); + JSONObject expend = payInfo.getJSONObject("expend"); + String string = expend.getString("qrcode_url"); + clientPlaceOrderVO.setQrcodeUrl(string); paymentRecord.setPaymentType(PaymentTypeEnum.ALI_PAY.getCode()); paymentRecord.setPaymentStatus(PaymentStatusEnum.TO_BE_PAID.getCode()); + paymentRecord.setPayOrderNo(payInfo.getString("id")); orderPaymentRecordService.save(paymentRecord); + clientPlaceOrderVO.setPayAmt(payInfo.getString("pay_amt")); + clientPlaceOrderVO.setOrderId(payInfo.getString("id")); // 设置订单是否需要支付标识 clientPlaceOrderVO.setZeroFlag(DisabledEnum.NO.getCode()); } @@ -584,15 +598,139 @@ return order.getId()+""; } + + @Override public String refund(Long uid) throws Exception { Order byId = this.getById(uid); + OrderPaymentRecord two = orderPaymentRecordService.lambdaQuery() + .eq(OrderPaymentRecord::getPaymentType,4) + .eq(OrderPaymentRecord::getOrderId, uid) + .one(); + if (byId.getPayType() == 4){ + // 纯余额支付 直接退还余额 + // 回退余额记录 + AppUserWalletRecord appUserWalletRecord = new AppUserWalletRecord(); + appUserWalletRecord.setAppUserId(byId.getAppUserId()); + appUserWalletRecord.setChangeType(1); + appUserWalletRecord.setReason("后台退款"); + appUserWalletRecord.setOrderId(byId.getId()); + appUserWalletRecord.setAmount(two.getPayAmount()); + remoteAppUserService.addBalanceRecord(appUserWalletRecord); + remoteAppUserService.addBalance(byId.getAppUserId(),two.getPayAmount()); + byId.setRefundStatus(3); + byId.setRefundRemark("后台退款"); + byId.setRefundTime(LocalDateTime.now()); + byId.setPaymentStatus(3); + two.setPaymentStatus(3); + this.updateById(byId); + orderPaymentRecordService.updateById(two); + switch (byId.getOrderFrom()){ + case 1: + // 冥想订单 删除 + break; + case 2: + // 删除用户与课程的关系表 + remoteAppUserService.deleteAppUserCourse(byId.getBusinessId(),byId.getAppUserId()); + break; + case 3: + // 会员订单 将用户会员到期时间回退 + if (byId.getBuyContent().contains("月")){ + remoteAppUserService.subVipExpireTime(byId.getAppUserId(),1); + }else if (byId.getBuyContent().contains("季")){ + remoteAppUserService.subVipExpireTime(byId.getAppUserId(),2); + }else if (byId.getBuyContent().contains("年")){ + remoteAppUserService.subVipExpireTime(byId.getAppUserId(),3); + } + break; + } + return "success"; + }else if (byId.getPayType() == 5 || byId.getPayType() == 6 || byId.getPayType() == 7){ + OrderPaymentRecord one = orderPaymentRecordService.lambdaQuery() + .eq(OrderPaymentRecord::getOrderId, uid) + .ne(OrderPaymentRecord::getPaymentType, 4) + .ne(OrderPaymentRecord::getPaymentType, 3) + .one(); + JSONObject refund = JuHeFuUtil.refund(one.getPayOrderNo(), byId.getBizOrderNo()); + if (refund.getString("error_msg")!=null){ + return refund.getString("error_msg"); + } + // 回退余额记录 + AppUserWalletRecord appUserWalletRecord = new AppUserWalletRecord(); + appUserWalletRecord.setAppUserId(byId.getAppUserId()); + appUserWalletRecord.setChangeType(1); + appUserWalletRecord.setReason("后台退款"); + appUserWalletRecord.setOrderId(byId.getId()); + appUserWalletRecord.setAmount(two.getPayAmount()); + remoteAppUserService.addBalanceRecord(appUserWalletRecord); + remoteAppUserService.addBalance(byId.getAppUserId(),two.getPayAmount()); + byId.setRefundStatus(3); + byId.setRefundRemark("后台退款"); + byId.setRefundTime(LocalDateTime.now()); + byId.setPaymentStatus(3); + two.setPaymentStatus(3); + this.updateById(byId); + orderPaymentRecordService.updateById(two); + + switch (byId.getOrderFrom()){ + case 1: + // 冥想订单 删除 + break; + case 2: + // 删除用户与课程的关系表 + remoteAppUserService.deleteAppUserCourse(byId.getBusinessId(),byId.getAppUserId()); + break; + case 3: + // 会员订单 将用户会员到期时间回退 + if (byId.getBuyContent().contains("月")){ + remoteAppUserService.subVipExpireTime(byId.getAppUserId(),1); + }else if (byId.getBuyContent().contains("季")){ + remoteAppUserService.subVipExpireTime(byId.getAppUserId(),2); + }else if (byId.getBuyContent().contains("年")){ + remoteAppUserService.subVipExpireTime(byId.getAppUserId(),3); + } + break; + } + return "success"; + } OrderPaymentRecord one = orderPaymentRecordService.lambdaQuery() .eq(OrderPaymentRecord::getOrderId, uid) + .ne(OrderPaymentRecord::getPaymentType, 4) .ne(OrderPaymentRecord::getPaymentType, 3) - .ne(OrderPaymentRecord::getPaymentType, 4).one(); - - JuHeFuUtil.refund(one.getPayOrderNo(),byId.getBizOrderNo()); - return null; + .one(); + JSONObject refund = JuHeFuUtil.refund(one.getPayOrderNo(), byId.getBizOrderNo()); + if (refund.getString("error_msg")!=null){ + return refund.getString("error_msg"); + } + one.setPaymentStatus(3); + orderPaymentRecordService.updateById(one); + String string = refund.getString("payment_id"); + if (string!=null){ + byId.setRefundCode(string); + } + byId.setRefundTime(LocalDateTime.now()); + byId.setRefundStatus(3); + byId.setRefundRemark("后台退款"); + this.updateById(byId); + switch (byId.getOrderFrom()){ + case 1: + // 冥想订单 删除 + break; + case 2: + // 删除用户与课程的关系表 + remoteAppUserService.deleteAppUserCourse(byId.getBusinessId(),byId.getAppUserId()); + break; + case 3: + // 会员订单 将用户会员到期时间回退 + if (byId.getBuyContent().contains("月")){ + remoteAppUserService.subVipExpireTime(byId.getAppUserId(),1); + }else if (byId.getBuyContent().contains("季")){ + remoteAppUserService.subVipExpireTime(byId.getAppUserId(),2); + }else if (byId.getBuyContent().contains("年")){ + remoteAppUserService.subVipExpireTime(byId.getAppUserId(),3); + } + break; + } + return "success"; } } diff --git a/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/utils/JuHeFuUtil.java b/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/utils/JuHeFuUtil.java deleted file mode 100644 index b29cfc5..0000000 --- a/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/utils/JuHeFuUtil.java +++ /dev/null @@ -1,457 +0,0 @@ -package com.xinquan.order.utils; - -import cn.hutool.http.HttpRequest; -import cn.hutool.http.HttpResponse; -import cn.hutool.http.HttpUtil; -import com.alibaba.fastjson2.JSON; -import com.alibaba.fastjson2.JSONObject; -import com.xinquan.common.core.exception.ServiceException; -import com.xinquan.common.core.utils.DateUtils; -import com.xinquan.common.core.utils.StringUtils; -import java.security.KeyFactory; -import java.security.PrivateKey; -import java.security.PublicKey; -import java.security.Signature; -import java.security.spec.PKCS8EncodedKeySpec; -import java.security.spec.X509EncodedKeySpec; -import java.util.Base64; -import java.util.HashMap; -import java.util.Map; -import java.util.TreeMap; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.crypto.Cipher; -import javax.crypto.spec.SecretKeySpec; - -/** - * 桔禾付支付工具类 - * - * @author mitao - * @date 2024/9/7 - */ -public class JuHeFuUtil { - - private static Logger logger = LoggerFactory.getLogger(JuHeFuUtil.class); - // 商户RSA私钥 TODO - private static final String MERCHANT_PRIVATE_KEY = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMQPsMj4OYgjHFWS8wDIQOoMeAx9Ad1wKfIks7Oz5Kw8EVnmZ9o1ZY14goMMr1vJo/XxLLYXDvwj+EhV4MqT6ji2QDVqlhA4f6WFFmKOsvxgNnu0zAysfDpVpYihWC5uOf4ece9fWVci8DYFeXcawYGNB6GrJuo186sqMYwkE90/AgMBAAECgYAnMvfmhnKCPHraxSGeo2sPIGUUIh4wVs+cIShoomvy36OcdMuIvipKqbB2YR/iWyNT9d85nMybLtniJIFoH0CxshmLH/yg31vYhyLfVyih1RVFBRYuDMnIjvmNTBgXM/9vaAwkzonIQnoFoLVjxK2+JIFY+86Iak1Cv/vEi1vaSQJBAPRwebK51NBfrnO+2HY9nuDvbZbSx9I8uR+Yw/ebDUmbow/Dacibl0Hha+fw6cy5I3Rlm2kk5fKXIDIkwyLVq80CQQDNVXuQ8kXrDR0WjPcYPnwKNPEd0EHOKFiT7OqwoMFUUROyajO2nWs80eiZYZ+6M6+LEvYT6KcSiyiIwREnh1k7AkBV3BwjNzsVZkZ0yZhnEAX6pJ8t1yPxKPstqg9Lrd7g+BYyt0U0/dIHhhLNCcZV7sIRZI9OQ3Ox3nukoV0Zo0wRAkBT1eEbry+I5tPHj0qb5Xczm6YOrCcSCzsPOp4f+6Kz0F6ga+gtWVyden7jkQ5sMgosWFOMkWMVmSe1nk5ou0RdAkEAzfJJavQgu+BGQwqS1EojlXKe0GmpbQu+HwuDKcHmju0P2qGQ2yPfvURg1dMp7tmBM8AlVJhgzkNuyUAN1J841w=="; -// private static final String MERCHANT_PRIVATE_KEY = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAKOuwQkWiVCNY5SIw6fXcIHj/e8UuQ5Gro1v4yguVnNhCdC6HsWbF6jf1ios8CQKxIQViI2I8GfVPsjBBpfp7TK5zup0BHHYg7JUk0tC6ojL8WgbtVpKX7GJFQOdjNbZmYBlDQuBiCfvxWuLki8juL8NlY4aj7FgSDboSHq7A+ZjAgMBAAECgYAEhei5qpDC1BVjXmAhvDdUr4st1yHB/jwGloftbVJgP9c4mFwPU9jUhtLxOWqtZErH55xtZNJX3DGu9H6NJh6y09UCLdQJJY2/BQBrTlDsVFQl5h2PwDOO+qwUkZPTVd+822Sv0lukVS4c5sCwcdYwShmiIQCuudpygHDCBxJ6AQJBANAmfr6j8PxnCKlSUfaO1PqcnT6BGOJEBbnT0CGiKwNwXKecEKh5O8Ev4Ak9FhGad4eFkKZDNvHLE+yfCPy8nwECQQDJT10Hwi9+1KFdTacQrC94fZzipuqBOeVzgTPQrQ0iM38uKx5Sj5o4Ii9cyfkw2EoG/gFSim57U/OApLab22ljAkBoL0xzWZWOkHfaYHTcB0P9KJTgKzfsUQXYrHdZzlTfRMdrsYb4/K13FeJ6XVQFfZ5ke+sZ/TysK+yOHFAgSL0BAkAXLdYuYIOLfPwffCNyXgERRJVd245A1uO+iu/mZSaP+5H3ROu24eYF9Jmze2X/48eSSojochwKgz4UX+LOy1K1AkBQycFQjRWCjPi8biMhdLzzX47CNFkwigVp0At6VcZmb86cS9ohoTHCbeG0+hlX7p9eNMiFKLVnnCdjY6j1xqtv"; - // 平台RSA公钥 TODO - private static final String PLAT_PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDOKBBFXirWIJth+SNJCY4mhbATbL60sKV66bRixHMVz8vpBqONio9X6A+Pm9LNutBe+hLpI1BMmFJk3Mb1/QEcklWptRGgHqIrBxR4b19qc/2/pSxyqlpaifYJFZhOg2+OcQ/fqpAmhNXN5uc1pcYvbvWTam0j+6+nBNQeAAku5QIDAQAB"; - // 应用的app_id TODO - private static final String APP_ID = "app_10024101201"; - // 商户id TODO - private static final String MER_ID = "1120241012072667"; - // AES密钥 TODO - private static final String AES_KEY = "cb0a181ac97395c6942be19315fc0727"; - // 创建用户接口 - private static final String CREATE_USER_INTERFACE = "/api/member/create_user_a"; - private static final String BALANCE_PAY = "/api/account/balance_pay"; - // 创建支付订单 - private static final String CREATE_PAYMENT_INTERFACE = "/api/payment/create_payment"; - private static final String CREATE_PAYMENT_INTERFACE_CODE = "/api/payment/create_payment_qrcode"; - private static final String CREATE_PAYMENT_INTERFACE_THIRD = "/api/payment/create_payment_third"; - // 退款接口 - private static final String PAYMENT_REFUND_INTERFACE = "/api/payment/payment_refund"; - private static final String MERCHANT_PAY_INTERFACE = "/api/account/merchant_pay"; - // 接口地址 TODO - private static final String BASE_URL = "http://paytest.juhefu.com/"; - // 支付宝支付渠道 - private static final String PAY_CHANNEL_ALIPAY = "alipay_qr"; - // 微信支付渠道 - private static final String PAY_CHANNEL_WECHAT = "wx_lite"; - private static final String PAY_CHANNEL_WECHAT_THiRD = "wx"; - // 微信小程序id TODO - private static final String WX_APP_ID = ""; - - public static void main(String[] args) throws Exception { -// createPaymentCode("CZ1928183312398", 1, "0.01", -// "充值", "充值", -// "127.0.0.1", "openId", -//// "https://v7ro848ar5jx.ngrok.xiaomiqiu123.top/order/client/order/order/base/callback") -// "https://xq.xqzhihui.com/api/order/client/order/order/base/callback"); -// String orderNo = OrderUtil.getOrderNoForPrefix("User"); - createUser("test129837182731"); -// balancePay("12345678912", "0.01", "http://www.baidu.com"); - } - /** - * 创建用户 - * - * @param memberId 用户id - * @return boolean - * @throws Exception - */ - public static boolean createUser(String memberId) - throws Exception { - JSONObject memberP = new JSONObject(); - memberP.put("user_name","周帅"); - memberP.put("cert_type","00"); - memberP.put("cert_id","513902200006257079"); - memberP.put("tel_no","19983174515"); - memberP.put("card_id","6228480469852935177"); - JSONObject data = new JSONObject(); -// data.put("app_id", APP_ID); - data.put("app_id", "app_e7301b75-19f1-40e5-96ac-0fee847d4da0"); - data.put("member_id", memberId); - data.put("member_type", "01"); - String jsonString = JSON.toJSONString(memberP); - jsonString = JSON.toJSONString(JSONObject.parseObject(jsonString, TreeMap.class)); - data.put("member_p", jsonString); - System.err.println(data); - JSONObject body = new JSONObject(); -// body.put("merId", MER_ID); - body.put("merId", "1120241105365033"); - body.put("sign", sign(JSONObject.toJSONString(data))); -// body.put("reqCipher", -// EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); - body.put("reqCipher", - EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), "6d548eb01bad44bbbb4a23743e733103")); - body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); -// String result = sendPost(BASE_URL + CREATE_USER_INTERFACE, body); - String result = sendPost("https://payapi.juhefu.com/" + CREATE_USER_INTERFACE, body); - JSONObject resJsonObject = JSONObject.parseObject(result); - System.err.println(resJsonObject); - return false; - } - -// public static void main(String[] args) throws Exception { -//// createPaymentCode("CZ1928183312398", 1, "0.01", -//// "充值", "充值", -//// "127.0.0.1", "openId", -////// "https://v7ro848ar5jx.ngrok.xiaomiqiu123.top/order/client/order/order/base/callback") -//// "https://xq.xqzhihui.com/api/order/client/order/order/base/callback"); -//// String orderNo = OrderUtil.getOrderNoForPrefix("User"); -// createUser("testuser12937812893718297391"); -//// balancePay("12345678912", "0.01", "http://www.baidu.com"); -// } - - public static JSONObject balancePay(String orderNo, String payAmt, String notifyUrl) throws Exception { - JSONObject data = new JSONObject(); - - data.put("order_no", orderNo); - data.put("app_id", APP_ID); - data.put("pay_amt", payAmt); - data.put("member_id", "21233333"); - data.put("notify_url", notifyUrl); - JSONObject body = new JSONObject(); - body.put("merId", MER_ID); - body.put("sign", sign(JSONObject.toJSONString(data))); - body.put("reqCipher", - EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); - body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); - String result = sendPost(BASE_URL + BALANCE_PAY, body); - JSONObject resJsonObject = JSONObject.parseObject(result); - System.err.println(resJsonObject); - String string = resJsonObject.getString("resCipher"); - String decrypt = decrypt(string); - System.err.println(decrypt); - JSONObject jsonObject = JSONObject.parseObject(decrypt); - System.err.println(jsonObject); - return null; - } - - /** - * 创建支付订单 - * - * @param orderNo 订单号 - * @param payChannel 支付渠道 1:支付宝 2:微信 - * @param payAmt 支付金额 - * @param goodsTitle 商品标题 - * @param goodsDesc 商品描述信息,微信小程序和微信公众号该字段 最大长度 42 个字符 - * @param deviceIp 设备支付公网ip - * @param openId 微信openId - * @param notifyUrl 回调地址 - * @return JSONObject - * @throws Exception - */ - public static JSONObject createPayment(String orderNo, Integer payChannel, String payAmt, - String goodsTitle, String goodsDesc, String deviceIp, String openId, - String notifyUrl) throws Exception { - JSONObject data = new JSONObject(); - JSONObject expand = new JSONObject(); - data.put("order_no", orderNo); - data.put("app_id", APP_ID); - if (payChannel == 1) { - data.put("pay_channel", PAY_CHANNEL_WECHAT); - expand.put("open_id", openId); - expand.put("wx_app_id", WX_APP_ID); - data.put("expand", expand); - } else { - - data.put("pay_channel", PAY_CHANNEL_ALIPAY); - - } - data.put("pay_amt", payAmt); - data.put("goods_title", goodsTitle); - data.put("goods_desc", goodsDesc); - Map<String, Object> deviceInfo = new HashMap<>(); - deviceInfo.put("device_ip", deviceIp); - data.put("device_info", deviceInfo); - data.put("notify_url", notifyUrl); - JSONObject body = new JSONObject(); - body.put("merId", MER_ID); - body.put("sign", sign(JSONObject.toJSONString(data))); - body.put("reqCipher", - EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); - body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); - String result = sendPost(BASE_URL + CREATE_PAYMENT_INTERFACE, body); - JSONObject resJsonObject = JSONObject.parseObject(result); - System.err.println(resJsonObject); - String string = resJsonObject.getString("resCipher"); - String decrypt = decrypt(string); - System.err.println(decrypt); - JSONObject jsonObject = JSONObject.parseObject(decrypt); - -// if (resJsonObject.getString("status").equals("failed")) { -// throw new ServiceException(resJsonObject.getString("error_msg")); -// } -// if (resJsonObject.getString("status").equals("succeeded")) { -// return resJsonObject.getJSONObject("expand"); -// } - return jsonObject; - } - public static JSONObject createPaymentCode(String orderNo, Integer payChannel, String payAmt, - String goodsTitle, String goodsDesc, String deviceIp, String openId, - String notifyUrl) throws Exception { - JSONObject data = new JSONObject(); - JSONObject expand = new JSONObject(); - data.put("order_no", orderNo); - data.put("app_id", APP_ID); - if (payChannel == 1) { - data.put("pay_channel", PAY_CHANNEL_ALIPAY); - } else { - data.put("pay_channel", PAY_CHANNEL_WECHAT); - expand.put("open_id", openId); - expand.put("wx_app_id", WX_APP_ID); - data.put("expand", expand); - } - data.put("pay_amt", payAmt); - data.put("goods_title", goodsTitle); - data.put("goods_desc", goodsDesc); - data.put("time_expire", "20241031000000"); - Map<String, Object> deviceInfo = new HashMap<>(); - deviceInfo.put("device_ip", deviceIp); - data.put("device_info", deviceInfo); - data.put("notify_url", notifyUrl); - JSONObject body = new JSONObject(); - body.put("merId", MER_ID); - body.put("sign", sign(JSONObject.toJSONString(data))); - body.put("reqCipher", - EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); - body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); - String result = sendPost(BASE_URL + CREATE_PAYMENT_INTERFACE_CODE, body); - JSONObject resJsonObject = JSONObject.parseObject(result); - System.err.println(resJsonObject); - String string = resJsonObject.getString("resCipher"); - String decrypt = decrypt(string); - System.err.println(decrypt); - JSONObject jsonObject = JSONObject.parseObject(decrypt); - -// if (resJsonObject.getString("status").equals("failed")) { -// throw new ServiceException(resJsonObject.getString("error_msg")); -// } -// if (resJsonObject.getString("status").equals("succeeded")) { -// return resJsonObject.getJSONObject("expand"); -// } - return jsonObject.getJSONObject("expand"); - } - /** - * 创建支付订单 微信托管支付 - * - * @param orderNo 订单号 - * @param payChannel 支付渠道 1:支付宝 2:微信 - * @param payAmt 支付金额 - * @param goodsTitle 商品标题 - * @param goodsDesc 商品描述信息,微信小程序和微信公众号该字段 最大长度 42 个字符 - * @param deviceIp 设备支付公网ip - * @param openId 微信openId - * @param notifyUrl 回调地址 - * @return JSONObject - * @throws Exception - */ - public static JSONObject createPayment1(String orderNo, Integer payChannel, String payAmt, - String goodsTitle, String goodsDesc, String deviceIp, String openId, - String notifyUrl) throws Exception { - JSONObject data = new JSONObject(); - JSONObject expand = new JSONObject(); - data.put("order_no", orderNo); - data.put("app_id", APP_ID); - data.put("pay_channel", PAY_CHANNEL_WECHAT_THiRD); - data.put("pay_amt", payAmt); - data.put("goods_title", goodsTitle); - data.put("goods_desc", goodsDesc); - Map<String, Object> deviceInfo = new HashMap<>(); - deviceInfo.put("device_ip", deviceIp); - data.put("device_info", deviceInfo); - data.put("notify_url", notifyUrl); - JSONObject body = new JSONObject(); - body.put("merId", MER_ID); - body.put("sign", sign(JSONObject.toJSONString(data))); - body.put("reqCipher", - EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); - body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); - String result = sendPost(BASE_URL + CREATE_PAYMENT_INTERFACE_THIRD, body); - JSONObject resJsonObject = JSONObject.parseObject(result); - System.err.println(resJsonObject); - String string = resJsonObject.getString("resCipher"); - String decrypt = decrypt(string); - System.err.println("解密后"+decrypt); - JSONObject jsonObject = JSONObject.parseObject(decrypt); - -// if (resJsonObject.getString("status").equals("failed")) { -// throw new ServiceException(resJsonObject.getString("error_msg")); -// } -// if (resJsonObject.getString("status").equals("succeeded")) { -// return resJsonObject.getJSONObject("expand"); -// } - return jsonObject; - } - - /** - * 申请退款 - * - * @param paymentId 支付单号 - * @param orderNo 订单号 - * @return - */ - public static String refund(String paymentId, String orderNo) throws Exception { - JSONObject data = new JSONObject(); - data.put("payment_id", paymentId); - data.put("order_no", orderNo); - JSONObject body = new JSONObject(); - body.put("merId", MER_ID); - body.put("sign", sign(JSONObject.toJSONString(data))); - body.put("reqCipher", - EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); - body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); - String result = sendPost(BASE_URL + PAYMENT_REFUND_INTERFACE, body); - JSONObject resJsonObject = JSONObject.parseObject(result); -// if (resJsonObject.getString("status").equals("succeeded")) { -// return "ok"; -// } else if (resJsonObject.getString("status").equals("failed")) { -// throw new ServiceException(resJsonObject.getString("error_msg")); -// } - return "ok"; - } - - /** - * 商户付款 - * - * @param orderNo 订单号 - * @param payAmt 交易金额 - * @param cardName 收款银行开户名 - * @param cardId 收款银行卡号 - * @param cardType 收款银行账户类型 DEBIT_CARD:借记卡 CREDIT_CARD:贷记卡 76 QUASI_CREDIT_CARD:准贷卡 PASSBOOK:存折 - * UNIT_SETTLE_CARD:单位结算卡 PUBLIC_CARD:对公卡 - * @return - * @throws Exception - */ - public static JSONObject merchantPay(String orderNo, String payAmt, String cardName, String cardId, - String cardType) - throws Exception { - JSONObject data = new JSONObject(); - data.put("order_no", orderNo); - data.put("app_id", APP_ID); - data.put("pay_amt", payAmt); - data.put("card_name", cardName); - data.put("card_id", cardId); - data.put("card_type", cardType); - JSONObject body = new JSONObject(); - body.put("merId", MER_ID); - body.put("sign", sign(JSONObject.toJSONString(data))); - body.put("reqCipher", - EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); - body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmss")); - String result = sendPost(BASE_URL + MERCHANT_PAY_INTERFACE, body); - JSONObject resJsonObject = JSONObject.parseObject(result); - System.err.println(resJsonObject); - String string = resJsonObject.getString("resCipher"); - String decrypt = decrypt(string); - System.err.println("解密后"+decrypt); - JSONObject jsonObject = JSONObject.parseObject(decrypt); - return jsonObject; - } - - /** - * 发送post请求 - * - * @param url 请求地址 - * @param body 请求体 - * @return - */ - private static String sendPost(String url, JSONObject body) { - HttpRequest post = HttpUtil.createPost(url); - Map<String, String> headers = new HashMap<>(); - headers.put("Content-type", "application/json; charset=utf-8"); - headers.put("Accept", "application/json"); - post.addHeaders(headers); - post.body(body.toJSONString()); - HttpResponse execute = post.execute(); - String result = execute.body(); - execute.close(); - if (StringUtils.isBlank(result)) { - throw new ServiceException("请求第三方支付平台异常"); - } - return result; - } - - - - /** - * RSA私钥签名:签名方式SHA256WithRSA - * - * @param data 待签名字符串 - * @return 签名byte[] - * @throws Exception - */ - public static String sign(String data) { - // 先对该json对象数据按照参数字典顺序(参数名ASCII码从小到大排序,参数名区分大小写)排序生成字符串,再进行加签和验签。 - data = JSON.toJSONString(JSONObject.parseObject(data, TreeMap.class)); - // Base64 --> Key - try { -// byte[] bytes = Base64.getDecoder().decode(MERCHANT_PRIVATE_KEY); - byte[] bytes = Base64.getDecoder().decode(MERCHANT_PRIVATE_KEY); - PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(bytes); - KeyFactory keyFactory; - keyFactory = KeyFactory.getInstance("RSA"); - PrivateKey privateKey = keyFactory.generatePrivate(keySpec); - // Sign - Signature signature = Signature.getInstance("SHA256WithRSA"); - signature.initSign(privateKey); - signature.update(data.getBytes("UTF-8")); - return Base64.getEncoder().encodeToString(signature.sign()); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - public static String decrypt(String strToDecrypt) { - try { - SecretKeySpec secretKey = new SecretKeySpec(AES_KEY.getBytes(), "AES"); - Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); - cipher.init(Cipher.DECRYPT_MODE, secretKey); - return new String(cipher.doFinal(Base64.getDecoder().decode(strToDecrypt))); - } catch (Exception e) { - System.out.println("Error while decrypting: " + e.toString()); - } - return null;} -// public static boolean verify(String data, String publicKeyStr) { -// try { -// // 解码公钥 -// byte[] publicKeyBytes = Base64.getDecoder().decode(publicKeyStr); -// X509EncodedKeySpec keySpec = new X509EncodedKeySpec(publicKeyBytes); -// KeyFactory keyFactory = KeyFactory.getInstance("RSA"); -// PublicKey publicKey = keyFactory.generatePublic(keySpec); -// // 验证签名 -// Signature signature = Signature.getInstance("SHA256WithRSA"); -// signature.initVerify(publicKey); -// signature.update(data.getBytes("UTF-8")); -// -// return true; -// } catch (Exception e) { -// e.printStackTrace(); -// return false; -// } -// } - -} diff --git a/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/controller/CommonQuestionController.java b/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/controller/CommonQuestionController.java index 1284309..1874d42 100644 --- a/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/controller/CommonQuestionController.java +++ b/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/controller/CommonQuestionController.java @@ -204,6 +204,17 @@ one.setQrCode(s); return R.ok(one); } + + public static void main(String[] args) throws Exception { + HashMap<String, String> blueCode = new HashMap<>(); + blueCode.put("url", "https://xqgwzh.obs.cn-south-1.myhuaweicloud.com/apkAndroid.apk"); + String blueS = "https://xqgwzh.obs.cn-south-1.myhuaweicloud.com/apkAndroid.apk"; + MyQrCodeUtil.createCodeToFile(blueS); + BufferedImage blueImage = QRCodeUtil.createImage(blueS); + MultipartFile blueFile = convert(blueImage, new Date().getTime() + UUIDUtil.getRandomCode(3) + ".PNG"); + String s = ObsUploadUtil.obsUpload(blueFile); + System.err.println(s); + } @PostMapping("/getCommissionRuleShare") @ApiOperation(value = "推广活动页",tags = "H5分享") public R<CommissionRule> getCommissionRuleShare(String userId) throws Exception { diff --git a/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/controller/HomeController.java b/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/controller/HomeController.java index 1070011..690050e 100644 --- a/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/controller/HomeController.java +++ b/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/controller/HomeController.java @@ -3,11 +3,16 @@ import cn.afterturn.easypoi.excel.ExcelExportUtil; import cn.afterturn.easypoi.excel.entity.ExportParams; +import com.xinquan.common.core.constant.CacheConstants; import com.xinquan.common.core.domain.R; +import com.xinquan.common.core.exception.ServiceException; import com.xinquan.common.core.utils.DateUtils; import com.xinquan.common.core.utils.WebUtils; import com.xinquan.common.core.utils.page.BeanUtils; import com.xinquan.common.core.utils.page.PageDTO; +import com.xinquan.common.core.web.domain.BaseModel; +import com.xinquan.common.redis.service.RedisService; +import com.xinquan.common.security.utils.SecurityUtils; import com.xinquan.course.api.domain.Course; import com.xinquan.course.api.domain.CourseCategory; import com.xinquan.course.api.domain.CourseDTO; @@ -16,10 +21,15 @@ import com.xinquan.order.api.domain.Order; import com.xinquan.order.api.domain.vo.HomeDto; import com.xinquan.order.api.feign.RemoteOrderService; +import com.xinquan.system.api.domain.SysUser; import com.xinquan.system.api.domain.vo.HomeVO; import com.xinquan.system.domain.Banner; +import com.xinquan.system.domain.Turn; +import com.xinquan.system.domain.Version; import com.xinquan.system.domain.export.HomeExport; import com.xinquan.system.service.BannerService; +import com.xinquan.system.service.ISysUserService; +import com.xinquan.system.service.TurnService; import com.xinquan.user.api.feign.RemoteAppUserService; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -64,7 +74,43 @@ private RemoteMeditationService remoteMeditationService; @Resource private RemoteOrderService remoteOrderService; + @Resource + private ISysUserService sysUserService; + @Resource + private RedisService redisService; + @Resource + private TurnService turnService; + @GetMapping("/getTurn") + @ApiOperation(value = "IOS获取是否跳转三方支付", tags = "IOS获取是否跳转三方支付") + public R getTurn() { + Turn one = turnService.getOne(null); + if (one.getIsTurn()==1){ + return R.ok(true); + }else{ + return R.ok(false); + } + } + + + @GetMapping("/updatePassword") + @ApiOperation(value = "管理后台-修改密码", tags = "管理后台-修改密码") + public R updatePassword(String userName,String password) { + SysUser one = sysUserService.lambdaQuery() + .eq(SysUser::getUserType, "00") + .eq(SysUser::getDelFlag, "0") + .eq(SysUser::getUserName, userName).one(); + + if (one!=null){ +// if (one.getStatus().equals("1")){ +// return R.fail("账号已被冻结"); +// } + one.setPassword(SecurityUtils.encryptPassword(password)); + sysUserService.updateById(one); + return R.ok(); + } + return R.fail("修改失败,账号不存在"); + } @PostMapping("/homeStatistics") @ApiOperation(value = "首页统计",tags = "管理后台-首页统计") public R<HomeVO> bannerList(@RequestBody HomeDto homeDto) { diff --git a/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/controller/PageController.java b/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/controller/PageController.java index 0ad4651..d25bace 100644 --- a/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/controller/PageController.java +++ b/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/controller/PageController.java @@ -3,7 +3,9 @@ import com.xinquan.common.core.domain.R; import com.xinquan.system.domain.Page; +import com.xinquan.system.domain.Turn; import com.xinquan.system.service.PageService; +import com.xinquan.system.service.TurnService; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; @@ -22,6 +24,8 @@ public class PageController { @Resource private PageService pageService; + @Resource + private TurnService turnService; @PostMapping("/getPage") @ApiOperation(value = "获取启动页",tags = "获取启动页") public R<String> getPage() { @@ -47,6 +51,18 @@ } return R.ok(); } + @GetMapping("/updateTurn") + @ApiOperation(value = "修改IOS获取是否跳转三方支付", tags = "管理后台-启动页") + public R updateTurn() { + Turn one = turnService.getOne(null); + if (one.getIsTurn()==1){ + one.setIsTurn(2); + }else { + one.setIsTurn(1); + } + turnService.updateById(one); + return R.ok(); + } @PostMapping("/getPlan") @ApiOperation(value = "获取计划引导设置",tags = "计划引导设置") public R<String> getPlan() { diff --git a/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/domain/Turn.java b/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/domain/Turn.java new file mode 100644 index 0000000..a22c56b --- /dev/null +++ b/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/domain/Turn.java @@ -0,0 +1,39 @@ +package com.xinquan.system.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.xinquan.common.core.web.domain.BaseModel; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.math.BigDecimal; + +/** + * <p> + * 用户信息表 + * </p> + * + * @author mitao + * @since 2024-08-21 + */ +@Data +@TableName("t_turn") +@ApiModel(value="Turn对象", description="是否跳转") +public class Turn { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "id") + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + @ApiModelProperty(value = "ios是否跳转第三方支付 1是2否") + @TableField("isTurn") + private Integer isTurn; + + +} diff --git a/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/mapper/TurnMapper.java b/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/mapper/TurnMapper.java new file mode 100644 index 0000000..32008fb --- /dev/null +++ b/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/mapper/TurnMapper.java @@ -0,0 +1,17 @@ +package com.xinquan.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.xinquan.system.domain.Banner; +import com.xinquan.system.domain.Turn; + +/** + * <p> + * 用户信息表 Mapper 接口 + * </p> + * + * @author mitao + * @since 2024-08-21 + */ +public interface TurnMapper extends BaseMapper<Turn> { + +} diff --git a/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/service/TurnService.java b/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/service/TurnService.java new file mode 100644 index 0000000..6141df2 --- /dev/null +++ b/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/service/TurnService.java @@ -0,0 +1,20 @@ +package com.xinquan.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.xinquan.common.core.utils.page.PageDTO; +import com.xinquan.system.api.domain.vo.BannerVO; +import com.xinquan.system.domain.Banner; +import com.xinquan.system.domain.Turn; + +import java.util.List; + +/** + * <p> + * 用户信息表 服务类 + * </p> + * + * @author mitao + * @since 2024-08-23 + */ +public interface TurnService extends IService<Turn> { +} diff --git a/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/service/impl/TurnServiceImpl.java b/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/service/impl/TurnServiceImpl.java new file mode 100644 index 0000000..3183fe3 --- /dev/null +++ b/xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/service/impl/TurnServiceImpl.java @@ -0,0 +1,35 @@ +package com.xinquan.system.service.impl; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.xinquan.common.core.utils.page.BeanUtils; +import com.xinquan.common.core.utils.page.CollUtils; +import com.xinquan.common.core.utils.page.PageDTO; +import com.xinquan.course.api.domain.Course; +import com.xinquan.course.api.domain.CourseCategory; +import com.xinquan.course.api.domain.CourseDTO; +import com.xinquan.course.api.feign.RemoteCourseService; +import com.xinquan.system.api.domain.vo.BannerVO; +import com.xinquan.system.domain.Banner; +import com.xinquan.system.domain.Turn; +import com.xinquan.system.mapper.BannerMapper; +import com.xinquan.system.mapper.TurnMapper; +import com.xinquan.system.service.BannerService; +import com.xinquan.system.service.TurnService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * <p> + * 用户信息表 服务实现类 + * </p> + * + * @author mitao + * @since 2024-08-23 + */ +@Service +public class TurnServiceImpl extends ServiceImpl<TurnMapper, Turn> implements TurnService { + +} diff --git a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserController.java b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserController.java index 1048634..5eb9ca8 100644 --- a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserController.java +++ b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserController.java @@ -124,6 +124,27 @@ private RemoteUserService remoteUserService; @Resource private NoticeRecordService noticeRecordService; + + + @PostMapping("/subVipExpireTime/{appUserId}/{type}") + public void subVipExpireTime(@PathVariable("appUserId") Long appUserId,@PathVariable("type") Integer type){ + AppUser byId = appUserService.getById(appUserId); + switch (type){ + case 1: + LocalDateTime localDateTime = byId.getVipExpireTime().minusDays(30); + byId.setVipExpireTime(localDateTime); + break; + case 2: + LocalDateTime localDateTime1 = byId.getVipExpireTime().minusDays(90); + byId.setVipExpireTime(localDateTime1); + break; + case 3: + LocalDateTime localDateTime2 = byId.getVipExpireTime().minusDays(365); + byId.setVipExpireTime(localDateTime2); + break; + } + appUserService.updateById(byId); + } @ApiOperation(value = "会员临期", tags = "会员临期") @PostMapping("/testVip") public void testVip() { @@ -458,7 +479,9 @@ SysUser data = remoteUserService.getSysUserById(userid + "").getData(); byId.setFreezingOperator(data.getNickName()+"("+data.getUserName()+")"); appUserService.updateById(byId); - // 将被冻结的用户token清除 + String cacheList = redisService.getCacheObject(byId.getId() + ""); + redisService.deleteObject(cacheList); + return R.ok(); } @GetMapping("/detail") @@ -1303,7 +1326,7 @@ @ApiImplicitParam(value = "分页参数,每页数量", name = "pageSize", required = true, dataType = "Integer") }) public R<PageDTO<InviteRankListVO>> inviteRankListShareInfo( - @RequestParam(value = "id") Integer id, + @RequestParam(value = "id") Long id, @RequestParam(value = "pageCurr", defaultValue = "1") Integer pageCurr, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { LambdaQueryWrapper<AppUser> appUserLambdaQueryWrapper = new LambdaQueryWrapper<>(); diff --git a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserCourseController.java b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserCourseController.java index f99b161..3d203ba 100644 --- a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserCourseController.java +++ b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserCourseController.java @@ -2,6 +2,7 @@ import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.C; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.xinquan.common.core.domain.R; import com.xinquan.common.core.utils.page.CollUtils; @@ -79,6 +80,12 @@ List<AppUser> collect1 = appUserService.lambdaQuery().in(!collect.isEmpty(), AppUser::getId, collect).list(); return R.ok(collect1); } + @GetMapping("/deleteAppUserCourse/{courseId}/{appUserId}") + void deleteAppUserCourse(@PathVariable("courseId") Long courseId,@PathVariable("appUserId") Long appUserId){ + appUserCourseService.remove(new LambdaQueryWrapper<AppUserCourse>() + .eq(AppUserCourse::getCourseId,courseId) + .eq(AppUserCourse::getAppUserId,appUserId)); + } @Autowired private TokenService tokenService; /** diff --git a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserTreeController.java b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserTreeController.java index 6a688dc..118f705 100644 --- a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserTreeController.java +++ b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserTreeController.java @@ -161,6 +161,8 @@ appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务"); appUserEnergyRecordService.save(appUserEnergyRecord); byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10); + byId.setEnergyValue(byId.getEnergyValue() + 10); + } if (appUserTree.getTaskTwo() == 2) { AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); @@ -170,6 +172,7 @@ appUserEnergyRecord.setReason("完成【每日疗愈60分钟】任务"); appUserEnergyRecordService.save(appUserEnergyRecord); byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 20); + byId.setEnergyValue(byId.getEnergyValue() + 20); } appUserTree.setTaskOne(1); @@ -183,9 +186,10 @@ appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务"); appUserEnergyRecordService.save(appUserEnergyRecord); byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10); + byId.setEnergyValue(byId.getEnergyValue() + 10); } - appUserTree.setTaskOne(1); - appUserTree.setTaskTwo(2); + appUserTree.setTaskOne(2); + appUserTree.setTaskTwo(1); } else { appUserTree.setTaskOne(2); appUserTree.setTaskTwo(2); @@ -205,6 +209,9 @@ appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务"); appUserEnergyRecordService.save(appUserEnergyRecord); byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10); + one.setTaskOne(1); + byId.setEnergyValue(byId.getEnergyValue() + 10); + } if (one.getTaskTwo() == 2) { AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); @@ -214,10 +221,11 @@ appUserEnergyRecord.setReason("完成【每日疗愈60分钟】任务"); appUserEnergyRecordService.save(appUserEnergyRecord); byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 20); + one.setTaskTwo(1); + byId.setEnergyValue(byId.getEnergyValue() + 20); } - one.setTaskOne(1); - one.setTaskTwo(1); + } else if (temp >= 1800) { if (one.getTaskOne() == 2) { AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); @@ -227,9 +235,9 @@ appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务"); appUserEnergyRecordService.save(appUserEnergyRecord); byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10); + one.setTaskOne(1); + byId.setEnergyValue(byId.getEnergyValue() + 10); } - one.setTaskOne(1); - one.setTaskTwo(2); } else { one.setTaskOne(2); one.setTaskTwo(2); @@ -282,6 +290,7 @@ one.setEnergyValue(byId.getEnergyValue()); appUserTreeService.updateById(one); one.setTotalEnergyValue(byId.getTotalEnergyValue()); + appUserService.updateById(byId); return R.ok(one); } }else{ @@ -347,12 +356,14 @@ AppUser byId = appUserService.getById(userId); if (byId.getEnergyValue() == 0){ return R.energyValueError("能量值不足"); - } WateringVO wateringVO = new WateringVO(); AppUserTree one = appUserTreeService.lambdaQuery().eq(AppUserTree::getAppUserId, userId) .eq(AppUserTree::getSowAgain,2).one(); + if (one.getTreeLevelType() == 10){ + return R.fail("成长值已满,请重新播种"); + } one.setStatus(2); one.setTotal(one.getTotal()+byId.getEnergyValue()); one.setTime(LocalDateTime.now()); @@ -400,9 +411,17 @@ one.setGrowthValue(total1); one.setEnergyValue(byId.getEnergyValue()); appUserTreeService.updateById(one); + if (one.getTotal()>=data.get(9).getGrowthValue()){ + // 本次浇水量 + byId.setEnergyValue(one.getTotal()-data.get(9).getGrowthValue()); + appUserService.updateById(byId); + one.setTotal(data.get(9).getGrowthValue()); + appUserTreeService.updateById(one); + } wateringVO.setNextLevel(tem); wateringVO.setTreeLevelType(x); wateringVO.setGrowthValue(total1); + wateringVO.setEnergyValue(byId.getEnergyValue()); if (x>y){ wateringVO.setIsNext(true); NoticeRecord noticeRecord = new NoticeRecord(); diff --git a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserViewingHistoryController.java b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserViewingHistoryController.java index 9b422c4..485cadd 100644 --- a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserViewingHistoryController.java +++ b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserViewingHistoryController.java @@ -8,6 +8,7 @@ import com.xinquan.common.security.service.TokenService; import com.xinquan.common.security.utils.SecurityUtils; import com.xinquan.course.api.domain.Course; +import com.xinquan.course.api.domain.CourseChapter; import com.xinquan.course.api.domain.OrderCourseVO; import com.xinquan.course.api.feign.RemoteCourseService; import com.xinquan.meditation.api.domain.Meditation; @@ -199,8 +200,15 @@ orderCourseVO.setGeneralPrice(record.getGeneralPrice()); orderCourseVO.setIosPrice(record.getIosPrice()); orderCourseVO.setCoverUrl(record.getCoverUrl()); - List<AppUser> data1 = remoteAppUserService.getUserByCourseId(record.getId()).getData(); - orderCourseVO.setCount(data1.size()); + List<CourseChapter> data1 = remoteCourseService.getChapterByCourseId(orderCourseVO.getBusinessId() + "").getData(); + int a = 0 ; + int b = 0 ; + for (CourseChapter courseChapter : data1) { + a+=courseChapter.getVirtualLearnedNum(); + Long data9 = remoteAppUserService.getCourseChapterHistoryCount(courseChapter.getId()).getData(); + b+=data9; + } + orderCourseVO.setCount(a+b); orderCourseVOS.add(orderCourseVO); } break; @@ -225,7 +233,6 @@ return R.tokenError("登录失效"); } Long userId = loginUser.getUserid(); - AppUser byId = appUserService.getById(userId); AppUserViewingHistory appUserViewingHistory = new AppUserViewingHistory(); appUserViewingHistory.setAppUserId(userId); appUserViewingHistory.setBizId(id); @@ -233,48 +240,6 @@ appUserViewingHistory.setTimeLook(timeLook); appUserViewingHistory.setCreateTime(LocalDateTime.now()); appUserViewingHistoryService.save(appUserViewingHistory); - // 查询用户今日观看了多久冥想 如果达到30分钟 用户能量+10 如果达到60分钟 用户能量额外增加20 - // 查询用户今日观看疗愈多少秒 - LocalDateTime now = LocalDateTime.now(); - LocalDateTime startOfDay = now.toLocalDate().atStartOfDay(); - LocalDateTime endOfDay = now.toLocalDate().atTime(LocalTime.MAX); - List<AppUserViewingHistory> list = appUserViewingHistoryService - .lambdaQuery().eq(AppUserViewingHistory::getAppUserId, userId) - .eq(AppUserViewingHistory::getViewingType, 1) - .eq(BaseModel::getDelFlag,0) - .between(AppUserViewingHistory::getCreateTime, startOfDay,endOfDay).list(); - int temp = 0; - for (AppUserViewingHistory appUserViewingHistory1 : list) { - temp += appUserViewingHistory1.getTimeLook(); - } - AppUserTree one = appUserTreeService.lambdaQuery().eq(AppUserTree::getAppUserId, userId) - .eq(AppUserTree::getSowAgain,2).one(); - if (one == null){ - AppUserTree appUserTree = new AppUserTree(); - appUserTree.setAppUserId(userId); - appUserTree.setTreeLevelType(1); - appUserTree.setGrowthValue(0); - - appUserTree.setSowAgain(2); - appUserTree.setCreateTime(LocalDateTime.now()); - if (temp>=60){ - byId.setEnergyValue(byId.getEnergyValue()+30); - } - else if (temp>=30){ - byId.setEnergyValue(byId.getEnergyValue()+10); - } - appUserService.updateById(byId); - appUserTreeService.save(appUserTree); - }else{ - if (temp>=60){ - byId.setEnergyValue(byId.getEnergyValue()+30); - } - else if (temp>=30){ - byId.setEnergyValue(byId.getEnergyValue()+10); - } - appUserService.updateById(byId); - appUserTreeService.updateById(one); - } return R.ok(); } @PostMapping("/saveCourseStudyHistory") diff --git a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWalletRecordController.java b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWalletRecordController.java index 6409836..7f89cde 100644 --- a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWalletRecordController.java +++ b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWalletRecordController.java @@ -178,6 +178,7 @@ appUserWalletRecordLambdaQueryWrapper.eq(AppUserWalletRecord::getChangeType, state-1); } appUserWalletRecordLambdaQueryWrapper.eq(AppUserWalletRecord::getAppUserId, userId); + appUserWalletRecordLambdaQueryWrapper.ne(AppUserWalletRecord::getAmount, 0); appUserWalletRecordLambdaQueryWrapper.orderByDesc(BaseModel::getCreateTime); Page<AppUserWalletRecord> page = walletRecordService .page(new Page<>(pageCurr, pageSize),appUserWalletRecordLambdaQueryWrapper); @@ -352,6 +353,25 @@ if (data1!=null)orderDetailVO.setRemark("疗愈购买【"+data1.getMeditationTitle()+"】"); } return R.ok(orderDetailVO); + }else if (byId.getReason().contains("退款")){ + Order data = remoteOrderService.getOrderById(byId.getOrderId()).getData(); + if (data!=null){ + orderDetailVO.setType("后台退款"); + orderDetailVO.setPayOrderNo(data.getRefundCode()); + orderDetailVO.setAmount(byId.getAmount()); + orderDetailVO.setChangeType(1); + orderDetailVO.setPaymentTime(data.getRefundTime()); + switch (data.getOrderFrom()){ + case 1: + Meditation data1 = remoteMeditationService.getMeditationById(data.getBusinessId()).getData(); + if (data1!=null)orderDetailVO.setRemark("疗愈购买【"+data1.getMeditationTitle()+"】"); + break; + case 2: + Course data2 = remoteCourseService.getCourseById(data.getBusinessId()).getData(); + if (data2!=null)orderDetailVO.setRemark("课程购买【"+data2.getCourseTitle()+"】"); + break; + } + } } } diff --git a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWithdrawController.java b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWithdrawController.java index 85dd362..1d282e1 100644 --- a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWithdrawController.java +++ b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWithdrawController.java @@ -3,11 +3,14 @@ import cn.afterturn.easypoi.excel.ExcelExportUtil; import cn.afterturn.easypoi.excel.entity.ExportParams; +import cn.hutool.core.util.RandomUtil; +import com.alibaba.fastjson2.JSONObject; import com.alibaba.nacos.common.utils.UuidUtils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.xinquan.common.core.constant.CacheConstants; import com.xinquan.common.core.domain.R; +import com.xinquan.common.core.utils.JuHeFuUtil; import com.xinquan.common.core.utils.WebUtils; import com.xinquan.common.core.utils.page.CollUtils; import com.xinquan.common.core.utils.page.PageDTO; @@ -15,12 +18,10 @@ import com.xinquan.common.redis.service.RedisService; import com.xinquan.common.security.service.TokenService; import com.xinquan.course.api.domain.Course; +import com.xinquan.meditation.api.domain.Meditation; import com.xinquan.order.api.domain.Order; -import com.xinquan.system.api.domain.AppUserWalletRecord; +import com.xinquan.system.api.domain.*; import com.xinquan.user.api.domain.dto.OrderListDTO; -import com.xinquan.system.api.domain.AppUser; -import com.xinquan.system.api.domain.AppUserBank; -import com.xinquan.system.api.domain.AppUserWithdraw; import com.xinquan.system.api.model.LoginUser; import com.xinquan.user.domain.export.WithdrawExport; import com.xinquan.user.service.AppUserBankService; @@ -36,16 +37,20 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.crypto.Cipher; +import javax.crypto.spec.SecretKeySpec; import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.BufferedReader; import java.io.IOException; +import java.io.PrintWriter; import java.math.BigDecimal; +import java.math.RoundingMode; import java.net.URLEncoder; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; /** @@ -254,7 +259,7 @@ @ApiImplicitParam(name = "bankId", value = "银行卡id", dataType = "Long", required = true), @ApiImplicitParam(name = "money", value = "提现金额", dataType = "String", required = true) }) - public R withdraw(Long bankId,String money) { + public R withdraw(Long bankId,String money) throws Exception { LoginUser loginUser = tokenService.getLoginUser(); if (loginUser==null){ @@ -265,8 +270,9 @@ if (byId.getBalance().compareTo(new BigDecimal(money))<0){ return R.fail("提现金额不能超过钱包余额"); } + AppUserBank byId1 = appUserBankService.getById(bankId); + byId.setBalance(byId.getBalance().subtract(new BigDecimal(money))); - appUserService.updateById(byId); BigDecimal bigDecimal = new BigDecimal(money); AppUserWithdraw appUserWithdraw = new AppUserWithdraw(); appUserWithdraw.setAppUserId(userId); @@ -275,11 +281,12 @@ appUserWithdraw.setWithdrawType(1); appUserWithdraw.setWithdrawStatus(0); // todo 提现流水号 - appUserWithdraw.setSerialNo(UuidUtils.generateUuid()); - appUserWithdraw.setCode(UuidUtils.generateUuid()); + String s = UuidUtils.generateUuid(); + String replace = s.replace("-", ""); + + appUserWithdraw.setCode(replace); appUserWithdraw.setWithdrawTime(LocalDateTime.now()); appUserWithdraw.setCreateTime(LocalDateTime.now()); - withdrawService.save(appUserWithdraw); // 先扣去余额 AppUserWalletRecord appUserWalletRecord = new AppUserWalletRecord(); appUserWalletRecord.setAppUserId(userId); @@ -287,13 +294,177 @@ appUserWalletRecord.setReason("提现"); appUserWalletRecord.setOrderId(appUserWithdraw.getId()); appUserWalletRecord.setAmount(new BigDecimal(money)); + BigDecimal bigDecimal1 = new BigDecimal(money).setScale(2, RoundingMode.HALF_DOWN); + JuHeFuUtil.updateAccount(byId.getFenzhangId(),byId1.getCardholder(),byId1.getCellPhone(),byId1.getCardNo()); + JSONObject jsonObject = JuHeFuUtil.balancePay(replace, byId.getFenzhangId(), bigDecimal1 + "" + , "https://xq.xqzhihui.com/api/user/client/app-user-withdraw/base/callback"); + if (jsonObject.getString("error_msg")!=null){ + return R.fail(jsonObject.getString("error_msg")); + } + appUserService.updateById(byId); appUserWalletRecordService.save(appUserWalletRecord); - + withdrawService.save(appUserWithdraw); return R.ok(); + } + private static final String AES_KEY = "cb0a181ac97395c6942be19315fc0727"; + public static String decrypt(String strToDecrypt) { + try { + SecretKeySpec secretKey = new SecretKeySpec(AES_KEY.getBytes(), "AES"); + Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); + cipher.init(Cipher.DECRYPT_MODE, secretKey); + return new String(cipher.doFinal(Base64.getDecoder().decode(strToDecrypt))); + } catch (Exception e) { + System.out.println("Error while decrypting: " + e.toString()); + } + return null;} + @ResponseBody + @PostMapping("/base/callback") + public void callback(HttpServletRequest request, HttpServletResponse response) { + try { + System.err.println("提现到分账接收方回调================="+request); + BufferedReader reader = request.getReader(); + String string1 = reader.toString(); + StringBuilder requestBody = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + requestBody.append(line); + } + System.err.println("提现回调=================全部请求体"+requestBody); + com.alibaba.fastjson2.JSONObject jsonObject = JSONObject.parseObject(requestBody.toString()); + System.err.println("json串"+jsonObject); + String string9 = jsonObject.getString("resCipher"); + String decrypt = decrypt(string9); + System.err.println(decrypt); + JSONObject jsonObject1 = JSONObject.parseObject(decrypt); + // 系统订单号 + String string = jsonObject1.getString("order_no"); + String payId = jsonObject1.getString("pay_id"); + AppUserWithdraw one = withdrawService.lambdaQuery().eq(AppUserWithdraw::getCode, string).one(); + if (jsonObject.getString("type").equals("balancePay.succeeded")){ + if (one!=null){ + String s = UuidUtils.generateUuid(); + AppUser appUser = appUserService.getById(one.getAppUserId()); + if (one.getWithdrawStatus()==1 || one.getWithdrawStatus()==2){ + return; + } + JSONObject jsonObject2 = JuHeFuUtil.balanceWithdraw(s, one.getAmount() + "", appUser.getFenzhangId(), + "https://xq.xqzhihui.com/api/user/client/app-user-withdraw/base/callbackA"); + if (jsonObject2.getString("error_msg")!=null){ + // 调用失败 + // 回退余额记录 + AppUserWalletRecord appUserWalletRecord = new AppUserWalletRecord(); + appUserWalletRecord.setAppUserId(one.getAppUserId()); + appUserWalletRecord.setChangeType(1); + appUserWalletRecord.setReason("提现回退"); + appUserWalletRecord.setOrderId(one.getId()); + appUserWalletRecord.setAmount(one.getAmount()); + appUserWalletRecordService.save(appUserWalletRecord); + one.setWithdrawStatus(2); + one.setReason(jsonObject1.getString("error_msg")); + withdrawService.updateById(one); + // 回退用户余额 + BigDecimal add = appUser.getBalance().add(one.getAmount()); + appUser.setBalance(add); + appUserService.updateById(appUser); + PrintWriter out = response.getWriter(); + out.write("succeeded"); + out.flush(); + out.close(); + } + withdrawService.updateById(one); + } + PrintWriter out = response.getWriter(); + out.write("succeeded"); + out.flush(); + out.close(); + }else if (jsonObject.getString("type").equals("balancePay.failed")){ + // 回退余额记录 + AppUserWalletRecord appUserWalletRecord = new AppUserWalletRecord(); + appUserWalletRecord.setAppUserId(one.getAppUserId()); + appUserWalletRecord.setChangeType(1); + appUserWalletRecord.setReason("提现回退"); + appUserWalletRecord.setOrderId(one.getId()); + appUserWalletRecord.setAmount(one.getAmount()); + appUserWalletRecordService.save(appUserWalletRecord); + one.setWithdrawStatus(2); + one.setReason(jsonObject1.getString("error_msg")); + withdrawService.updateById(one); + // 回退用户余额 + AppUser appUser = appUserService.getById(one.getAppUserId()); + BigDecimal add = appUser.getBalance().add(one.getAmount()); + appUser.setBalance(add); + appUserService.updateById(appUser); + PrintWriter out = response.getWriter(); + out.write("succeeded"); + out.flush(); + out.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + @ResponseBody + @PostMapping("/base/callbackA") + public void callbackA(HttpServletRequest request, HttpServletResponse response) { + try { + System.err.println("提现到银行卡回调================="+request); + BufferedReader reader = request.getReader(); + String string1 = reader.toString(); + StringBuilder requestBody = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + requestBody.append(line); + } + System.err.println("提现到银行卡回调=================全部请求体"+requestBody); + com.alibaba.fastjson2.JSONObject jsonObject = JSONObject.parseObject(requestBody.toString()); + System.err.println("json串"+jsonObject); + String string9 = jsonObject.getString("resCipher"); + String decrypt = decrypt(string9); + System.err.println(decrypt); + JSONObject jsonObject1 = JSONObject.parseObject(decrypt); + // 系统订单号 + String string = jsonObject1.getString("order_no"); + AppUserWithdraw one = withdrawService.lambdaQuery().eq(AppUserWithdraw::getCode, string).one(); + if (jsonObject.getString("type").equals("withdraw.succeeded")){ + if (one!=null){ + System.err.println("提现成功"); + one.setWithdrawStatus(1); + one.setSerialNo(jsonObject1.getString("withdraw_id")); + withdrawService.updateById(one); + } + PrintWriter out = response.getWriter(); + out.write("succeeded"); + out.flush(); + out.close(); + }else if (jsonObject.getString("type").equals("withdraw.failed")){ + // 回退余额记录 + AppUserWalletRecord appUserWalletRecord = new AppUserWalletRecord(); + appUserWalletRecord.setAppUserId(one.getAppUserId()); + appUserWalletRecord.setChangeType(1); + appUserWalletRecord.setReason("提现回退"); + appUserWalletRecord.setOrderId(one.getId()); + appUserWalletRecord.setAmount(one.getAmount()); + appUserWalletRecordService.save(appUserWalletRecord); + one.setWithdrawStatus(2); + one.setReason(jsonObject1.getString("error_msg")); + withdrawService.updateById(one); + // 回退用户余额 + AppUser appUser = appUserService.getById(one.getAppUserId()); + BigDecimal add = appUser.getBalance().add(one.getAmount()); + appUser.setBalance(add); + appUserService.updateById(appUser); + PrintWriter out = response.getWriter(); + out.write("succeeded"); + out.flush(); + out.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } } @PostMapping("/addBank") @ApiOperation(value = "提现-添加银行卡", tags = {"钱包"}) - public R wallet(@RequestBody AppUserBank appUserWithdraw) { + public R wallet(@RequestBody AppUserBank appUserWithdraw) throws Exception { LoginUser loginUser = tokenService.getLoginUser(); if (loginUser==null){ return R.tokenError("登录失效"); @@ -310,6 +481,18 @@ // return R.fail("验证码不正确"); // } appUserBankService.save(appUserWithdraw); + // 查询是否已经开户 + AppUser byId = appUserService.getById(userId); + if (byId.getFenzhangId()==null){ + // 开户 + long time = new Date().getTime(); + String s = RandomUtil.randomNumbers(4); + String s1 = "FZ" + time + s; + JuHeFuUtil.createUser(s1, appUserWithdraw.getCardholder(), "00", + appUserWithdraw.getIdentityCard(), appUserWithdraw.getCellPhone(), appUserWithdraw.getCardNo()); + byId.setFenzhangId(s1); + appUserService.updateById(byId); + } return R.ok(); } @PostMapping("/deleteBank") diff --git a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/domain/dto/UserAnswerDTO.java b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/domain/dto/UserAnswerDTO.java index 65edc55..544d090 100644 --- a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/domain/dto/UserAnswerDTO.java +++ b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/domain/dto/UserAnswerDTO.java @@ -23,6 +23,6 @@ @ApiModelProperty(value = "问题二 多个tagId使用英文逗号拼接字符串", required = true) private String tagIds; - @ApiModelProperty(value = "设备码", required = true) + @ApiModelProperty(value = "设备码", required = false) private String device; } diff --git a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/service/impl/AppUserServiceImpl.java b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/service/impl/AppUserServiceImpl.java index a19e79e..50a8623 100644 --- a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/service/impl/AppUserServiceImpl.java +++ b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/service/impl/AppUserServiceImpl.java @@ -76,21 +76,32 @@ Optional<AppUser> one = this.lambdaQuery() .eq(AppUser::getDevice, device) .isNull(AppUser::getCellPhone).oneOpt(); - if (one.isPresent()) { - initUserTree(one.get().getId()); - this.updateById(one.get()); - return one; - } else { - - return this.lambdaQuery() - .eq(Objects.nonNull(dto.getId()), AppUser::getId, dto.getId()) - .eq(com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dto.getAppleId()), AppUser::getAppleId, dto.getAppleId()) - .eq(com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dto.getCellPhone()), AppUser::getCellPhone, - dto.getCellPhone()) - .eq(com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dto.getWxOpenId()), AppUser::getWxOpenId, - dto.getWxOpenId()) - .ne(AppUser::getUserStatus, AppUserStatusEnum.LOGOUT.getCode()).oneOpt(); + Optional<AppUser> appUser = this.lambdaQuery() + .eq(Objects.nonNull(dto.getId()), AppUser::getId, dto.getId()) + .eq(com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dto.getAppleId()), AppUser::getAppleId, dto.getAppleId()) + .eq(com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dto.getCellPhone()), AppUser::getCellPhone, + dto.getCellPhone()) + .eq(com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dto.getWxOpenId()), AppUser::getWxOpenId, + dto.getWxOpenId()) + .ne(AppUser::getUserStatus, AppUserStatusEnum.LOGOUT.getCode()).oneOpt(); + // 如果不存在 + if (!appUser.isPresent()){ + if (one.isPresent()) { + initUserTree(one.get().getId()); + this.updateById(one.get()); + return one; + } else { + return this.lambdaQuery() + .eq(Objects.nonNull(dto.getId()), AppUser::getId, dto.getId()) + .eq(com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dto.getAppleId()), AppUser::getAppleId, dto.getAppleId()) + .eq(com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dto.getCellPhone()), AppUser::getCellPhone, + dto.getCellPhone()) + .eq(com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dto.getWxOpenId()), AppUser::getWxOpenId, + dto.getWxOpenId()) + .ne(AppUser::getUserStatus, AppUserStatusEnum.LOGOUT.getCode()).oneOpt(); + } } + } return this.lambdaQuery() .eq(Objects.nonNull(dto.getId()), AppUser::getId, dto.getId()) @@ -115,6 +126,30 @@ */ @Override public AppUser registerAppUser(AppUserDTO appUserDTO) { + if (StringUtils.hasLength(appUserDTO.getDevice())){ + AppUser one = this.lambdaQuery().eq(AppUser::getDevice, appUserDTO.getDevice()) + .isNull(AppUser::getCellPhone).one(); + if (one == null){ + AppUser appUser = BeanUtils.copyBean(appUserDTO, AppUser.class); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); + String format = simpleDateFormat.format(new Date()); + // 生成四位随机数字 + String randomCode = String.valueOf((int) ((Math.random() * 9 + 1) * 1000)); + appUser.setCode("YH"+format+randomCode); + this.save(appUser); + initUserTree(appUser.getId()); + return appUser; + }else{ + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); + String format = simpleDateFormat.format(new Date()); + // 生成四位随机数字 + String randomCode = String.valueOf((int) ((Math.random() * 9 + 1) * 1000)); + one.setCode("YH"+format+randomCode); + this.updateById(one); + initUserTree(one.getId()); + return one; + } + } AppUser appUser = BeanUtils.copyBean(appUserDTO, AppUser.class); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); String format = simpleDateFormat.format(new Date()); @@ -136,7 +171,7 @@ public AppLoginUser wxLogin(AppWXLoginBody body) { AppLoginUser appLoginUser = new AppLoginUser(); Optional<AppUser> optionalAppUser = this.getUserByCondition( - AppUserDTO.builder().wxOpenId(body.getWxOpenId()).build()); + AppUserDTO.builder().wxOpenId(body.getWxOpenId()).device(body.getDevice()).build()); AppUser appUser = new AppUser(); SysUser sysUser = new SysUser(); // 存在账户,查询关联系统用户 @@ -185,6 +220,7 @@ String nickname = "用户" + IdUtil.fastSimpleUUID().substring(0, 6); sysUser.setNickName(nickname); appUser.setNickname(nickname); + appUser.setDevice(body.getDevice()); appUser.setWxName(body.getNickname()); appUser.setAvatar(body.getHeadImgUrl()); appUser.setGender(3); @@ -227,6 +263,7 @@ appUser.setNickname(nickname); appUser.setWxName(body.getNickname()); appUser.setAvatar(body.getHeadImgUrl()); + appUser.setDevice(body.getDevice()); appUser.setGender(3); appUser.setBalance(BigDecimal.ZERO); appUser.setSanskritFlag(DisabledEnum.NO.getCode()); @@ -256,7 +293,7 @@ public AppLoginUser appleLogin(String appleId,String device) { AppLoginUser appLoginUser = new AppLoginUser(); Optional<AppUser> optionalAppUser = this.getUserByCondition( - AppUserDTO.builder().appleId(appleId).build()); + AppUserDTO.builder().appleId(appleId).device(device).build()); SysUser sysUser = new SysUser(); AppUser appUser = new AppUser(); // 存在账户,查询关联系统用户 @@ -305,6 +342,7 @@ appUser.setBalance(BigDecimal.ZERO); appUser.setIncome(BigDecimal.ZERO); appUser.setTotalEnergyValue(0); + appUser.setDevice(device); appUser.setRegisterTime(LocalDateTime.now()); appUser.setLevelSettingId(TreeLevelEnum.SEED.getCode()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); @@ -342,6 +380,8 @@ appUser.setBalance(BigDecimal.ZERO); appUser.setIncome(BigDecimal.ZERO); appUser.setTotalEnergyValue(0); + appUser.setDevice(device); + appUser.setRegisterTime(LocalDateTime.now()); appUser.setLevelSettingId(TreeLevelEnum.SEED.getCode()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); @@ -373,7 +413,7 @@ public AppLoginUser appCaptchaLogin (AppCaptchaBody body){ AppLoginUser appLoginUser = new AppLoginUser(); Optional<AppUser> optionalAppUser = this.getUserByCondition( - AppUserDTO.builder().cellPhone(body.getCellPhone()).build()); + AppUserDTO.builder().device(body.getDevice()).cellPhone(body.getCellPhone()).build()); AppUser appUser = new AppUser(); SysUser sysUser = new SysUser(); if (optionalAppUser.isPresent()) { @@ -538,12 +578,14 @@ } } else { Optional<AppUser> userOptional = getAppUserByThirdId(loginType, wxOrAppleId); - if (loginType.equals(1)) { - // 微信登录 - handleUserNotPresent(userOptional, "该用户不存在,请重新进行微信授权登录"); - } else { - // 苹果登录 - handleUserNotPresent(userOptional, "该用户不存在,请重新进行苹果授权登录"); + if (!userOptional.isPresent()) { + if (loginType.equals(1)) { + // 微信登录 + handleUserNotPresent(userOptional, "该用户不存在,请重新进行微信授权登录"); + } else { + // 苹果登录 + handleUserNotPresent(userOptional, "该用户不存在,请重新进行苹果授权登录"); + } } appUser = userOptional.get(); appUser.setCellPhone(body.getCellPhone()); @@ -564,6 +606,7 @@ // 更新用户信息 this.updateById(appUser); AppLoginUser appLoginUser = new AppLoginUser(); + appLoginUser.setAppUserId(appUser.getId()); appLoginUser.setBindStatus(1); appLoginUser.setCellPhone(body.getCellPhone()); appLoginUser.setSysUser(sysUser); @@ -601,41 +644,45 @@ if (tokenService.getLoginUser()==null){ // 获取当前登录用户 if (org.springframework.util.StringUtils.hasLength(dto.getDevice())){ - SysUser sysUser = new SysUser(); - AppUser appUser = new AppUser(); - // 注册用户信息 - sysUser = new SysUser(); - String nickname = "用户" + IdUtil.fastSimpleUUID().substring(0, 6); - sysUser.setNickName(nickname); - sysUser.setAvatar("https://xqgwzh.obs.cn-south-1.myhuaweicloud.com/Logo%E7%A1%AE%E8%AE%A4%E7%89%88%281%29.jpg"); - sysUser.setUserName(dto.getDevice()); - sysUser.setUserType("01"); // app用户 - // 设置默认密码123456 - sysUser.setPassword(SecurityUtils.encryptPassword(Constants.DEFAULT_PASSWORD)); + AppUser one = this.lambdaQuery().eq(AppUser::getDevice, dto.getDevice()) + .isNull(AppUser::getCellPhone).one(); + if (one==null){ + SysUser sysUser = new SysUser(); + AppUser appUser = new AppUser(); + // 注册用户信息 + sysUser = new SysUser(); + String nickname = "用户" + IdUtil.fastSimpleUUID().substring(0, 6); + sysUser.setNickName(nickname); + sysUser.setAvatar("https://xqgwzh.obs.cn-south-1.myhuaweicloud.com/Logo%E7%A1%AE%E8%AE%A4%E7%89%88%281%29.jpg"); + sysUser.setUserName(nickname); + sysUser.setUserType("01"); // app用户 + // 设置默认密码123456 + sysUser.setPassword(SecurityUtils.encryptPassword(Constants.DEFAULT_PASSWORD)); - R<SysUser> registerResult = remoteUserService.registerAppUserInfo(sysUser, - SecurityConstants.INNER); - if (registerResult.getCode() == Constants.FAIL) { - throw new ServiceException(registerResult.getMsg()); - } - SysUser sysUserRes = registerResult.getData(); - appUser = new AppUser(); - appUser.setUserId(sysUserRes.getUserId()); - appUser.setNickname(nickname); - appUser.setAvatar("https://xqgwzh.obs.cn-south-1.myhuaweicloud.com/Logo%E7%A1%AE%E8%AE%A4%E7%89%88%281%29.jpg"); // TODO 待完善默认头像 - appUser.setBalance(BigDecimal.ZERO); - appUser.setSanskritFlag(DisabledEnum.NO.getCode()); - appUser.setBalance(BigDecimal.ZERO); - appUser.setIncome(BigDecimal.ZERO); - appUser.setTotalEnergyValue(0); - appUser.setRegisterTime(LocalDateTime.now()); - appUser.setLevelSettingId(TreeLevelEnum.SEED.getCode()); - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); - String format = simpleDateFormat.format(new Date()); - // 生成四位随机数字 - String randomCode = String.valueOf((int) ((Math.random() * 9 + 1) * 1000)); - appUser.setCode("YH"+format+randomCode); - this.save(appUser); + R<SysUser> registerResult = remoteUserService.registerAppUserInfo(sysUser, + SecurityConstants.INNER); + if (registerResult.getCode() == Constants.FAIL) { + throw new ServiceException(registerResult.getMsg()); + } + SysUser sysUserRes = registerResult.getData(); + appUser = new AppUser(); + appUser.setUserId(sysUserRes.getUserId()); + appUser.setNickname(nickname); + appUser.setAvatar("https://xqgwzh.obs.cn-south-1.myhuaweicloud.com/Logo%E7%A1%AE%E8%AE%A4%E7%89%88%281%29.jpg"); // TODO 待完善默认头像 + appUser.setBalance(BigDecimal.ZERO); + appUser.setSanskritFlag(DisabledEnum.NO.getCode()); + appUser.setBalance(BigDecimal.ZERO); + appUser.setIncome(BigDecimal.ZERO); + appUser.setTotalEnergyValue(0); + appUser.setRegisterTime(LocalDateTime.now()); + appUser.setLevelSettingId(TreeLevelEnum.SEED.getCode()); + appUser.setDevice(dto.getDevice()); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); + String format = simpleDateFormat.format(new Date()); + // 生成四位随机数字 + String randomCode = String.valueOf((int) ((Math.random() * 9 + 1) * 1000)); + appUser.setCode("YH"+format+randomCode); + this.save(appUser); Long userId = appUser.getId(); List<AppUserQuestion> appUserQuestionList = BeanUtils.copyList( dto.getUserAnswerOneDTOList(), AppUserQuestion.class); @@ -665,6 +712,26 @@ || appUserQuestion.getAnswer().equals("3")).collect(Collectors.toList()); appUser.setTagId(dto.getTagIds()); this.updateById(appUser); + }else{ + List<AppUserQuestion> appUserQuestionList = BeanUtils.copyList( + dto.getUserAnswerOneDTOList(), AppUserQuestion.class); + // 查询用户已填写的答案 + // 删除之前答案 + appUserQuestionService.lambdaUpdate().eq(AppUserQuestion::getAppUserId,one.getId()).remove(); + + // 根据类型更新答案 + for (AppUserQuestion appUserQuestion : appUserQuestionList) { + appUserQuestion.setAppUserId(one.getId()); + } + appUserQuestionService.saveBatch(appUserQuestionList); + // 筛选答案为是和偶尔有的问题,为用户设置对应的标签 + List<AppUserQuestion> appUserQuestionYesList = appUserQuestionList.stream() + .filter(appUserQuestion -> appUserQuestion.getAnswer().equals("1") + || appUserQuestion.getAnswer().equals("3")).collect(Collectors.toList()); + one.setTagId(dto.getTagIds()); + this.updateById(one); + } + } }else{ Long userId = tokenService.getLoginUser().getUserid(); @@ -687,8 +754,6 @@ appUser.setTagId(dto.getTagIds()); this.updateById(appUser); } - - } /** -- Gitblit v1.7.1