|
@@ -2,10 +2,15 @@ package com.miaxis.app.controller.wx;
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.miaxis.common.config.WxpayConfig;
|
|
|
import com.miaxis.common.constant.Constants;
|
|
|
+import com.miaxis.common.core.domain.entity.UserInfo;
|
|
|
import com.miaxis.common.exception.CustomException;
|
|
|
import com.miaxis.common.utils.AesUtil;
|
|
|
+import com.miaxis.common.utils.SecurityUtils;
|
|
|
+import com.miaxis.vip.domain.VipCode;
|
|
|
+import com.miaxis.vip.service.IVipCodeService;
|
|
|
import com.miaxis.wx.domain.RefundRecord;
|
|
|
import com.miaxis.wx.domain.WxOrder;
|
|
|
import com.miaxis.wx.dto.WxNotifyReturnDTO;
|
|
@@ -34,6 +39,8 @@ import java.io.IOException;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.security.*;
|
|
|
import java.security.cert.X509Certificate;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.Random;
|
|
|
|
|
|
@RestController
|
|
|
@RequiredArgsConstructor
|
|
@@ -50,6 +57,9 @@ public class WxNotifyController {
|
|
|
@Autowired
|
|
|
private IWxOrderService wxOrderService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IVipCodeService vipCodeService;
|
|
|
+
|
|
|
|
|
|
|
|
|
@Autowired
|
|
@@ -74,6 +84,10 @@ public class WxNotifyController {
|
|
|
JSONObject jsonObject = JSONObject.parseObject(resourceString);
|
|
|
//将回调数据写入数据库
|
|
|
writeNotifyDataToDb(jsonObject);
|
|
|
+ //创建兑换码
|
|
|
+ String code = createCode();
|
|
|
+ //激活用户
|
|
|
+ avtivityCode(code);
|
|
|
|
|
|
WxNotifyReturnDTO wxNotifyReturnDTO = new WxNotifyReturnDTO();
|
|
|
wxNotifyReturnDTO.setCode("SUCCESS");
|
|
@@ -81,6 +95,39 @@ public class WxNotifyController {
|
|
|
return wxNotifyReturnDTO;
|
|
|
}
|
|
|
|
|
|
+ private void avtivityCode(String vipCode) {
|
|
|
+ QueryWrapper<VipCode> queryWrapper = new QueryWrapper<VipCode>();
|
|
|
+ queryWrapper.eq("vip_code", vipCode);
|
|
|
+ VipCode vipCodeEntity = vipCodeService.getOne(queryWrapper);
|
|
|
+ if (vipCodeEntity == null){
|
|
|
+ throw new CustomException("该激活码不存在");
|
|
|
+ }
|
|
|
+ if (vipCodeEntity.getStatus() == 1){
|
|
|
+ throw new CustomException("该激活码已被激活");
|
|
|
+ }
|
|
|
+ if (vipCodeEntity.getStatus() == 2){
|
|
|
+ throw new CustomException("该激活码已作废");
|
|
|
+ }
|
|
|
+
|
|
|
+ UserInfo student = SecurityUtils.getLoginUser().getStudent();
|
|
|
+
|
|
|
+ vipCodeEntity.setStatus(1);
|
|
|
+ vipCodeEntity.setActivationUserId(student.getId());
|
|
|
+ vipCodeEntity.setActivationTime(new Date());
|
|
|
+ vipCodeService.updateById(vipCodeEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String createCode() {
|
|
|
+ VipCode vipCode = new VipCode();
|
|
|
+ String rVipCode = null ;
|
|
|
+ do {
|
|
|
+ rVipCode = randomVipcode();
|
|
|
+ }while (isRepeat(rVipCode));
|
|
|
+ vipCode.setVipCode(rVipCode);
|
|
|
+ vipCodeService.save(vipCode);
|
|
|
+ return rVipCode;
|
|
|
+ }
|
|
|
+
|
|
|
private String getBodyString(HttpServletRequest request) {
|
|
|
BufferedReader br = null;
|
|
|
StringBuilder sb = new StringBuilder("");
|
|
@@ -181,8 +228,6 @@ public class WxNotifyController {
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
- @Transactional
|
|
|
public void writeNotifyDataToDb(JSONObject jsonObject) {
|
|
|
String outTradeNo = jsonObject.getString("out_trade_no");
|
|
|
WxOrder wxOrder = wxOrderService.getByOutTradeNo(outTradeNo);
|
|
@@ -206,22 +251,7 @@ public class WxNotifyController {
|
|
|
if (sceneInfo != null){
|
|
|
wxOrder.setDeviceId(sceneInfo.getString("device_id"));
|
|
|
}
|
|
|
-// //购买电影票
|
|
|
-// if ( "1".equals(wxOrder.getGoodsType())){
|
|
|
-// wxOrderService.buyFilmOrder(wxOrder);
|
|
|
-// }
|
|
|
-// //购买福禄视频会员
|
|
|
-// else if ( "2".equals(wxOrder.getGoodsType())){
|
|
|
-// wxOrderService.buyFuluOrder(wxOrder);
|
|
|
-// }
|
|
|
-//
|
|
|
-// //购买活动-话费充值
|
|
|
-// else if ( "3".equals(wxOrder.getGoodsType())){
|
|
|
-// wxOrderService.buyPhoneBillOrder(wxOrder);
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ wxOrderService.updateById(wxOrder);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -231,6 +261,24 @@ public class WxNotifyController {
|
|
|
return aesUtil.decryptToString(wxpaySource.getAssociated_data().getBytes(), wxpaySource.getNonce().getBytes(), wxpaySource.getCiphertext());
|
|
|
}
|
|
|
|
|
|
+ private String randomVipcode() {
|
|
|
+ String result = "";
|
|
|
+ Random random = new Random();
|
|
|
+ for(int i =0 ;i <11 ;i ++){
|
|
|
+ result+=random.nextInt(10);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ private boolean isRepeat(String rVipCode) {
|
|
|
+ QueryWrapper<VipCode> wrapper = new QueryWrapper<VipCode>();
|
|
|
+ wrapper.eq("vip_code",rVipCode);
|
|
|
+ VipCode one = vipCodeService.getOne(wrapper);
|
|
|
+ return one!= null;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
|