|
@@ -1,33 +1,8 @@
|
|
|
package cn.com.ty.lift.ud.pay.wxpay;
|
|
|
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
-import java.math.BigDecimal;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
|
|
|
-import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
|
|
|
-import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
|
-import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryResult;
|
|
|
-import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult;
|
|
|
-import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
-import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
-
|
|
|
import cn.com.ty.lift.ud.chat.mapper.entity.LiftCaseEntity;
|
|
|
import cn.com.ty.lift.ud.chat.service.ILiftCaseService;
|
|
|
+import cn.com.ty.lift.ud.constant.CommonConst;
|
|
|
import cn.com.ty.lift.ud.operation.mapper.entity.UserLevelRuleEntity;
|
|
|
import cn.com.ty.lift.ud.operation.mapper.entity.VipFeeSettingEntity;
|
|
|
import cn.com.ty.lift.ud.operation.service.IUserLevelRuleService;
|
|
@@ -36,7 +11,9 @@ import cn.com.ty.lift.ud.pay.controller.req.PassbackParamsDTO;
|
|
|
import cn.com.ty.lift.ud.pay.controller.req.PayDTO;
|
|
|
import cn.com.ty.lift.ud.pay.enums.PassbackEnum;
|
|
|
import cn.com.ty.lift.ud.pay.service.WxpayService;
|
|
|
+import cn.com.ty.lift.ud.payment.mapper.entity.UserBillEntity;
|
|
|
import cn.com.ty.lift.ud.payment.mapper.entity.UserRechargeDetailEntity;
|
|
|
+import cn.com.ty.lift.ud.payment.service.IUserBillService;
|
|
|
import cn.com.ty.lift.ud.payment.service.IUserRechargeDetailService;
|
|
|
import cn.com.ty.lift.ud.question.mapper.QuestionBankMapper;
|
|
|
import cn.com.ty.lift.ud.question.mapper.entity.QuestionBankEntity;
|
|
@@ -47,8 +24,31 @@ import cn.com.ty.lift.ud.userInfo.mapper.UserInfoMapper;
|
|
|
import cn.com.ty.lift.ud.userInfo.mapper.entity.UserInfoEntity;
|
|
|
import cn.com.ty.lift.ud.utils.UUIDUtil;
|
|
|
import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
|
|
|
+import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
|
|
|
+import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
|
+import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryResult;
|
|
|
+import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult;
|
|
|
+import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
+import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* app微信支付
|
|
@@ -100,7 +100,18 @@ public class PayResponseResource {
|
|
|
private @Autowired QuestionBankMapper questionBankMapper;
|
|
|
|
|
|
private @Autowired IUserRechargeDetailService userRechargeDetailService;
|
|
|
-
|
|
|
+ private @Autowired IUserBillService userBillService;
|
|
|
+ /**
|
|
|
+ * 微信回调接口
|
|
|
+ *
|
|
|
+ * @param xmlData
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @PostMapping("/wxpayNotify")
|
|
|
+ public String wxpayNotify(@RequestBody String xmlData) {
|
|
|
+ return wxpayNotify1(xmlData);
|
|
|
+ }
|
|
|
/**
|
|
|
* 微信支付-诊单支付
|
|
|
*
|
|
@@ -110,6 +121,43 @@ public class PayResponseResource {
|
|
|
*/
|
|
|
@PostMapping("/wxpay/case")
|
|
|
public RestResponse appPay(@RequestBody PayDTO pay, HttpServletRequest httpServletRequest) {
|
|
|
+ return appPay1(pay, httpServletRequest);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 微信支付-打赏支付
|
|
|
+ *
|
|
|
+ * @param pay
|
|
|
+ * @param httpServletRequest
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("/wxpay/reward")
|
|
|
+ public RestResponse reward(@RequestBody PayDTO pay, HttpServletRequest httpServletRequest) {
|
|
|
+ return reward1(pay,httpServletRequest);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 微信支付-app充值
|
|
|
+ *
|
|
|
+ * @param pay
|
|
|
+ * @param httpServletRequest
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("/wxpay/recharge")
|
|
|
+ public RestResponse recharge(@RequestBody PayDTO pay, HttpServletRequest httpServletRequest) {
|
|
|
+ return recharge1(pay, httpServletRequest);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 微信支付-app充值成为vip
|
|
|
+ *
|
|
|
+ * @param pay
|
|
|
+ * @param httpServletRequest
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("/wxpay/rechargeVIP")
|
|
|
+ public RestResponse rechargeVIP(@RequestBody PayDTO pay, HttpServletRequest httpServletRequest) {
|
|
|
+ return rechargeVIP1(pay, httpServletRequest);
|
|
|
+ }
|
|
|
+
|
|
|
+ private RestResponse appPay1(PayDTO pay, HttpServletRequest httpServletRequest){
|
|
|
String ip = httpServletRequest.getRemoteAddr();
|
|
|
if (StringUtils.isBlank(pay.getOrders())) {
|
|
|
log.error("订单号不能为空。");
|
|
@@ -182,7 +230,7 @@ public class PayResponseResource {
|
|
|
String noncestr = String.valueOf(currentTimeMillis);
|
|
|
String timestamp = String.valueOf(currentTimeMillis / 1000);
|
|
|
WxPayAppUnifiedOrderResult result =
|
|
|
- new WxPayAppUnifiedOrderResult(wxAppId, wxMchId, prepayId, packageInfo, noncestr, timestamp);
|
|
|
+ new WxPayAppUnifiedOrderResult(wxAppId, wxMchId, prepayId, packageInfo, noncestr, timestamp);
|
|
|
// 创建并设置签名值。
|
|
|
result.createSign(wxMchKey);
|
|
|
return RestResponse.success(result, "success");
|
|
@@ -194,16 +242,7 @@ public class PayResponseResource {
|
|
|
}
|
|
|
return RestResponse.fail("调用APP支付接口时发生异常");
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 微信支付-打赏支付
|
|
|
- *
|
|
|
- * @param pay
|
|
|
- * @param httpServletRequest
|
|
|
- * @return
|
|
|
- */
|
|
|
- @PostMapping("/wxpay/reward")
|
|
|
- public RestResponse reward(@RequestBody PayDTO pay, HttpServletRequest httpServletRequest) {
|
|
|
+ private RestResponse reward1(PayDTO pay, HttpServletRequest httpServletRequest){
|
|
|
String ip = httpServletRequest.getRemoteAddr();
|
|
|
if (StringUtils.isBlank(pay.getOrders())) {
|
|
|
log.error("订单号参数不能为空。");
|
|
@@ -227,7 +266,7 @@ public class PayResponseResource {
|
|
|
|
|
|
// 打赏金额
|
|
|
String totalAmount =
|
|
|
- tableDictService.findOneByTableAndColumnAndCode("reward_setting", "reward", pay.getReawrdMoney().getCode());
|
|
|
+ tableDictService.findOneByTableAndColumnAndCode("reward_setting", "reward", pay.getReawrdMoney().getCode());
|
|
|
if (StringUtils.isBlank(totalAmount)) {
|
|
|
log.error("打赏代号有误。");
|
|
|
return RestResponse.fail("0", "打赏代号有误。");
|
|
@@ -245,7 +284,7 @@ public class PayResponseResource {
|
|
|
// totalAmount = orders.getReward();
|
|
|
try {
|
|
|
passbackParams =
|
|
|
- assemblePassbackParams(PassbackEnum.REWARD_PAY.getCode(), "题库打赏", pay.getUserId(), pay.getOrders());
|
|
|
+ assemblePassbackParams(PassbackEnum.REWARD_PAY.getCode(), "题库打赏", pay.getUserId(), pay.getOrders());
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e.printStackTrace();
|
|
@@ -262,7 +301,7 @@ public class PayResponseResource {
|
|
|
// totalAmount = orders.getReward();
|
|
|
try {
|
|
|
passbackParams =
|
|
|
- assemblePassbackParams(PassbackEnum.VIDEO_PAY.getCode(), "视频打赏", pay.getUserId(), pay.getOrders());
|
|
|
+ assemblePassbackParams(PassbackEnum.VIDEO_PAY.getCode(), "视频打赏", pay.getUserId(), pay.getOrders());
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e.printStackTrace();
|
|
@@ -306,7 +345,7 @@ public class PayResponseResource {
|
|
|
String noncestr = String.valueOf(currentTimeMillis);
|
|
|
String timestamp = String.valueOf(currentTimeMillis / 1000);
|
|
|
WxPayAppUnifiedOrderResult result =
|
|
|
- new WxPayAppUnifiedOrderResult(wxAppId, wxMchId, prepayId, packageInfo, noncestr, timestamp);
|
|
|
+ new WxPayAppUnifiedOrderResult(wxAppId, wxMchId, prepayId, packageInfo, noncestr, timestamp);
|
|
|
// 创建并设置签名值。
|
|
|
result.createSign(wxMchKey);
|
|
|
return RestResponse.success(result, "success");
|
|
@@ -318,16 +357,7 @@ public class PayResponseResource {
|
|
|
}
|
|
|
return RestResponse.fail("调用APP支付接口时发生异常");
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 微信支付-app充值
|
|
|
- *
|
|
|
- * @param pay
|
|
|
- * @param httpServletRequest
|
|
|
- * @return
|
|
|
- */
|
|
|
- @PostMapping("/wxpay/recharge")
|
|
|
- public RestResponse recharge(@RequestBody PayDTO pay, HttpServletRequest httpServletRequest) {
|
|
|
+ private RestResponse recharge1(PayDTO pay, HttpServletRequest httpServletRequest){
|
|
|
String ip = httpServletRequest.getRemoteAddr();
|
|
|
if (StringUtils.isBlank(pay.getOrders())) {
|
|
|
log.error("请输入订单号.");
|
|
@@ -352,7 +382,7 @@ public class PayResponseResource {
|
|
|
String passbackParams = "";
|
|
|
try {
|
|
|
passbackParams =
|
|
|
- assemblePassbackParams(PassbackEnum.RECHARGE_PAY.getCode(), "用户充值", rechargeDetail.getUserId(), null);
|
|
|
+ assemblePassbackParams(PassbackEnum.RECHARGE_PAY.getCode(), "用户充值", rechargeDetail.getUserId(), null);
|
|
|
} catch (UnsupportedEncodingException e1) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e1.printStackTrace();
|
|
@@ -390,7 +420,7 @@ public class PayResponseResource {
|
|
|
String noncestr = String.valueOf(currentTimeMillis);
|
|
|
String timestamp = String.valueOf(currentTimeMillis / 1000);
|
|
|
WxPayAppUnifiedOrderResult result =
|
|
|
- new WxPayAppUnifiedOrderResult(wxAppId, wxMchId, prepayId, packageInfo, noncestr, timestamp);
|
|
|
+ new WxPayAppUnifiedOrderResult(wxAppId, wxMchId, prepayId, packageInfo, noncestr, timestamp);
|
|
|
// 创建并设置签名值。
|
|
|
result.createSign(wxMchKey);
|
|
|
return RestResponse.success(result, "success");
|
|
@@ -402,16 +432,7 @@ public class PayResponseResource {
|
|
|
}
|
|
|
return RestResponse.fail("调用APP支付接口时发生异常");
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 微信支付-app充值成为vip
|
|
|
- *
|
|
|
- * @param pay
|
|
|
- * @param httpServletRequest
|
|
|
- * @return
|
|
|
- */
|
|
|
- @PostMapping("/wxpay/rechargeVIP")
|
|
|
- public RestResponse rechargeVIP(@RequestBody PayDTO pay, HttpServletRequest httpServletRequest) {
|
|
|
+ private RestResponse rechargeVIP1(PayDTO pay, HttpServletRequest httpServletRequest){
|
|
|
String ip = httpServletRequest.getRemoteAddr();
|
|
|
if (StringUtils.isBlank(pay.getOrders())) {
|
|
|
log.error("订单号不能为空。");
|
|
@@ -423,18 +444,16 @@ public class PayResponseResource {
|
|
|
return RestResponse.fail("0", "打赏用户id不能为空。");
|
|
|
}
|
|
|
|
|
|
- QueryWrapper<VipFeeSettingEntity> queryWrapper = new QueryWrapper<VipFeeSettingEntity>();
|
|
|
- queryWrapper.eq("id", pay.getOrders());
|
|
|
- VipFeeSettingEntity orders = vipFeeSettingService.getOne(queryWrapper);
|
|
|
+ VipFeeSettingEntity vipFeeSettingEntity = vipFeeSettingService.getOne(new QueryWrapper<VipFeeSettingEntity>().eq("id", pay.getOrders()));
|
|
|
|
|
|
- if (null == orders) {
|
|
|
+ if (null == vipFeeSettingEntity) {
|
|
|
log.error("该项会费不存在请检查!");
|
|
|
return RestResponse.fail("0", "该项会费不存在请检查!");
|
|
|
}
|
|
|
|
|
|
/** 0 待审核 1 审核通过 2 驳回 3 待提交 */
|
|
|
final int flag = 1;
|
|
|
- if (flag != orders.getExamineFlag()) {
|
|
|
+ if (flag != vipFeeSettingEntity.getExamineFlag()) {
|
|
|
log.error("该项会费不支持使用请检查!");
|
|
|
return RestResponse.fail("0", "该项会费不支持使用请检查!");
|
|
|
}
|
|
@@ -444,19 +463,32 @@ public class PayResponseResource {
|
|
|
log.error("当前用户不存在");
|
|
|
return RestResponse.fail("当前用户不存在");
|
|
|
}
|
|
|
- UserLevelRuleEntity userLevelRole = iUserLevelRuleService.getById(orders.getUserLevelId());
|
|
|
+ Integer experienceCardFlag = vipFeeSettingEntity.getExperienceCard();
|
|
|
+ if (experienceCardFlag != null && experienceCardFlag.equals(1)){
|
|
|
+ //1:体验,0||null:正常卡片 默认是正常卡片
|
|
|
+ //体验卡只让买一次
|
|
|
+ List<UserBillEntity> experienceCardList = userBillService.list(new QueryWrapper<UserBillEntity>()
|
|
|
+ .eq("user_id", pay.getUserId())
|
|
|
+ .eq("business_type", CommonConst.BUSINESS_TYPE_BECOME_VIP)
|
|
|
+ .eq("data_id", vipFeeSettingEntity.getId())
|
|
|
+ );
|
|
|
+ if (experienceCardList != null && !experienceCardList.isEmpty()){
|
|
|
+ log.error("体验卡只能购买一次哦!");
|
|
|
+ return RestResponse.fail("体验卡只能购买一次哦!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ UserLevelRuleEntity userLevelRole = iUserLevelRuleService.getById(vipFeeSettingEntity.getUserLevelId());
|
|
|
if (null == userLevelRole) {
|
|
|
log.error("当前会员角色等级不存在,请检查");
|
|
|
return RestResponse.fail("当前会员角色等级不存在,请检查");
|
|
|
}
|
|
|
-
|
|
|
// 充值金额
|
|
|
- BigDecimal totalAmount = orders.getPrice().multiply(new BigDecimal(100));
|
|
|
+ BigDecimal totalAmount = vipFeeSettingEntity.getPrice().multiply(new BigDecimal(100));
|
|
|
|
|
|
String passbackParams = "";
|
|
|
try {
|
|
|
- passbackParams = assemblePassbackParams(PassbackEnum.RECHARGE_VIP_PAY.getCode(), orders.getName(),
|
|
|
- pay.getUserId(), orders.getId().toString());
|
|
|
+ passbackParams = assemblePassbackParams(PassbackEnum.RECHARGE_VIP_PAY.getCode(), vipFeeSettingEntity.getName(),
|
|
|
+ pay.getUserId(), vipFeeSettingEntity.getId().toString());
|
|
|
} catch (UnsupportedEncodingException e1) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e1.printStackTrace();
|
|
@@ -494,7 +526,7 @@ public class PayResponseResource {
|
|
|
String noncestr = String.valueOf(currentTimeMillis);
|
|
|
String timestamp = String.valueOf(currentTimeMillis / 1000);
|
|
|
WxPayAppUnifiedOrderResult result =
|
|
|
- new WxPayAppUnifiedOrderResult(wxAppId, wxMchId, prepayId, packageInfo, noncestr, timestamp);
|
|
|
+ new WxPayAppUnifiedOrderResult(wxAppId, wxMchId, prepayId, packageInfo, noncestr, timestamp);
|
|
|
// 创建并设置签名值。
|
|
|
result.createSign(wxMchKey);
|
|
|
return RestResponse.success(result, "success");
|
|
@@ -506,16 +538,7 @@ public class PayResponseResource {
|
|
|
}
|
|
|
return RestResponse.fail("调用APP支付接口时发生异常");
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 微信回调接口
|
|
|
- *
|
|
|
- * @param xmlData
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- @PostMapping("/wxpayNotify")
|
|
|
- public String wxpayNotify(@RequestBody String xmlData) {
|
|
|
+ private String wxpayNotify1(String xmlData){
|
|
|
logger.info("come into wxpayNotify()");
|
|
|
logger.info(xmlData);
|
|
|
// xmlData 异步回调参数有outTradeNo商户订单号信息,需要使用WxPayOrderNotifyResult接收。
|
|
@@ -633,8 +656,7 @@ public class PayResponseResource {
|
|
|
* @return
|
|
|
* @throws UnsupportedEncodingException
|
|
|
*/
|
|
|
- private String assemblePassbackParams(Integer type, String memo, Long userId, String dataId)
|
|
|
- throws UnsupportedEncodingException {
|
|
|
+ private String assemblePassbackParams(Integer type, String memo, Long userId, String dataId) throws UnsupportedEncodingException {
|
|
|
PassbackParamsDTO dto = new PassbackParamsDTO();
|
|
|
dto.setType(type);
|
|
|
dto.setMemo(memo);
|