|
@@ -1,10 +1,21 @@
|
|
package com.pj.tb_wallet_record;
|
|
package com.pj.tb_wallet_record;
|
|
|
|
|
|
-
|
|
|
|
|
|
+import cn.dev33.satoken.spring.SpringMVCUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.github.binarywang.wxpay.bean.entpay.EntPayRequest;
|
|
|
|
+import com.github.binarywang.wxpay.bean.entpay.EntPayResult;
|
|
|
|
+import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
|
|
|
|
+import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
|
|
|
|
+import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
|
|
|
|
+import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
|
|
+import com.github.binarywang.wxpay.constant.WxPayConstants;
|
|
|
|
+import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
|
+import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
|
+import com.pj.common.core.utils.StringUtils;
|
|
import com.pj.current.dto.APPLoginUserInfo;
|
|
import com.pj.current.dto.APPLoginUserInfo;
|
|
import com.pj.current.satoken.StpAPPUserUtil;
|
|
import com.pj.current.satoken.StpAPPUserUtil;
|
|
import com.pj.enummj.DeleteStatus;
|
|
import com.pj.enummj.DeleteStatus;
|
|
-import com.pj.tb_order.TbOrder;
|
|
|
|
|
|
+import com.pj.tb_banner.TbBanner;
|
|
import com.pj.tb_people.TbPeople;
|
|
import com.pj.tb_people.TbPeople;
|
|
import com.pj.tb_people.TbPeopleService;
|
|
import com.pj.tb_people.TbPeopleService;
|
|
import com.pj.tb_wallet_record.vo.WalletRecordAppVo;
|
|
import com.pj.tb_wallet_record.vo.WalletRecordAppVo;
|
|
@@ -12,25 +23,33 @@ import com.pj.tb_wallet_topdown.TbWalletTopdown;
|
|
import com.pj.tb_wallet_topdown.TbWalletTopdownService;
|
|
import com.pj.tb_wallet_topdown.TbWalletTopdownService;
|
|
import com.pj.tb_wallet_topup.TbWalletTopup;
|
|
import com.pj.tb_wallet_topup.TbWalletTopup;
|
|
import com.pj.tb_wallet_topup.TbWalletTopupService;
|
|
import com.pj.tb_wallet_topup.TbWalletTopupService;
|
|
|
|
+import com.pj.utils.LogUtil;
|
|
import com.pj.utils.sg.AjaxJson;
|
|
import com.pj.utils.sg.AjaxJson;
|
|
|
|
+import com.pj.utils.sg.WebNbUtil;
|
|
import com.pj.utils.so.SoMap;
|
|
import com.pj.utils.so.SoMap;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
|
+import java.io.InputStream;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Controller: tb_wallet_record -- 服务点交易记录
|
|
* Controller: tb_wallet_record -- 服务点交易记录
|
|
* @author plj
|
|
* @author plj
|
|
*/
|
|
*/
|
|
|
|
+
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/app/WalletManage/")
|
|
@RequestMapping("/app/WalletManage/")
|
|
public class TbWalletAppController {
|
|
public class TbWalletAppController {
|
|
|
|
|
|
|
|
+ public static final String CZ_TABLE_NAME = "topup";
|
|
|
|
+ public static final String TX_TABLE_NAME = "topdown";
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 底层 Service 对象
|
|
* 底层 Service 对象
|
|
*/
|
|
*/
|
|
@@ -52,6 +71,13 @@ public class TbWalletAppController {
|
|
TbPeopleService tbPeopleService;
|
|
TbPeopleService tbPeopleService;
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * 微信支付 Service 对象
|
|
|
|
+ */
|
|
|
|
+ @Autowired
|
|
|
|
+ private WxPayService wxService;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
* 查集合 - 根据条件(参数为空时代表忽略指定条件)
|
|
* 查集合 - 根据条件(参数为空时代表忽略指定条件)
|
|
*
|
|
*
|
|
* @return
|
|
* @return
|
|
@@ -92,32 +118,56 @@ public class TbWalletAppController {
|
|
return AjaxJson.getSuccessData(t);
|
|
return AjaxJson.getSuccessData(t);
|
|
}
|
|
}
|
|
/*
|
|
/*
|
|
- * 服务点提现
|
|
|
|
|
|
+ * 服务点充值
|
|
*/
|
|
*/
|
|
@RequestMapping("topupSave")
|
|
@RequestMapping("topupSave")
|
|
- public AjaxJson topupSave(@RequestParam("amount") Integer amount,@RequestParam("outTradeNo")String outTradeNo,@RequestParam("transactionId") String transactionId) {
|
|
|
|
|
|
+ public AjaxJson topupSave(@RequestParam("amount") Integer amount,@RequestParam("goodsName")String goodsName) {
|
|
//获取登录人
|
|
//获取登录人
|
|
APPLoginUserInfo appLoginInfo = StpAPPUserUtil.getAPPLoginInfo();
|
|
APPLoginUserInfo appLoginInfo = StpAPPUserUtil.getAPPLoginInfo();
|
|
- TbWalletTopup tbWalletTopup = new TbWalletTopup();
|
|
|
|
- Date date = new Date();
|
|
|
|
- tbWalletTopup.setMchid("AAAAAA1111111111AAAAAA");
|
|
|
|
- tbWalletTopup.setOutTradeNo(outTradeNo);
|
|
|
|
- tbWalletTopup.setAmount(String.valueOf(amount/100));
|
|
|
|
- tbWalletTopup.setTransactionId(transactionId);
|
|
|
|
- tbWalletTopup.setPeopleId(appLoginInfo.getFk().toString());
|
|
|
|
- tbWalletTopup.setTopupTime(date);
|
|
|
|
- tbWalletTopup.setCreateTime(date);
|
|
|
|
- tbWalletTopup.setCreateBy(appLoginInfo.getLoginId().toString());
|
|
|
|
- tbWalletTopup.setCreateName(appLoginInfo.getLoginName());
|
|
|
|
- tbWalletTopup.setDeleteStatus(DeleteStatus.DELETE_STATUS_ON.getCode());
|
|
|
|
- boolean ret=tbWalletTopupService.save(tbWalletTopup);
|
|
|
|
- if(ret){
|
|
|
|
- TbPeople tbPeople = tbPeopleService.getById(appLoginInfo.getFk());
|
|
|
|
- tbPeople.setWallet(tbPeople.getWallet()+amount/100);
|
|
|
|
- tbPeopleService.updateById(tbPeople);
|
|
|
|
|
|
+ TbPeople tbPeople = tbPeopleService.getById(appLoginInfo.getFk());
|
|
|
|
+ if(StringUtils.isBlank(tbPeople.getWxOpenId())){
|
|
|
|
+ return AjaxJson.getError("未绑定微信用户!");
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ TbWalletTopup tbWalletTopup = new TbWalletTopup();
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ tbWalletTopup.setMchid(this.wxService.getConfig().getMchId());
|
|
|
|
+ tbWalletTopup.setOutTradeNo(CZ_TABLE_NAME+System.currentTimeMillis());
|
|
|
|
+ tbWalletTopup.setGoodsName(goodsName);
|
|
|
|
+ tbWalletTopup.setAmount(amount.toString());
|
|
|
|
+ tbWalletTopup.setPeopleId(tbPeople.getId().toString());
|
|
|
|
+ tbWalletTopup.setTopupTime(date);
|
|
|
|
+ tbWalletTopup.setCreateTime(date);
|
|
|
|
+ tbWalletTopup.setCreateBy(appLoginInfo.getLoginId().toString());
|
|
|
|
+ tbWalletTopup.setCreateName(appLoginInfo.getLoginName());
|
|
|
|
+
|
|
|
|
+ //调用统一下单接口,并组装生成支付所需参数对象
|
|
|
|
+ WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest();
|
|
|
|
+ // 商品描述
|
|
|
|
+ request.setBody(tbWalletTopup.getGoodsName());
|
|
|
|
+ // 商户订单编号
|
|
|
|
+ request.setOutTradeNo(tbWalletTopup.getOutTradeNo());
|
|
|
|
+ //支付金额
|
|
|
|
+ request.setTotalFee(BaseWxPayRequest.yuanToFen(tbWalletTopup.getAmount()));
|
|
|
|
+ request.setSpbillCreateIp(WebNbUtil.getIP(SpringMVCUtil.getRequest()));
|
|
|
|
+ // 回调地址
|
|
|
|
+ request.setNotifyUrl(wxService.getConfig().getNotifyUrl());
|
|
|
|
+ // 交易类型APP
|
|
|
|
+ request.setTradeType(wxService.getConfig().getTradeType());
|
|
|
|
+ request.setOpenid(tbPeople.getWxOpenId());
|
|
|
|
+ WxPayMpOrderResult data = wxService.createOrder(request);
|
|
|
|
+ // 业务处理
|
|
|
|
+ tbWalletTopup.setTransactionId(data.getPackageValue());
|
|
|
|
+ // 付款中
|
|
|
|
+ tbWalletTopup.setPayStatus(1);
|
|
|
|
+ tbWalletTopupService.save(tbWalletTopup);
|
|
return AjaxJson.getSuccess();
|
|
return AjaxJson.getSuccess();
|
|
- }else{
|
|
|
|
- return AjaxJson.getError("操作失败!");
|
|
|
|
|
|
+ } catch (WxPayException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return AjaxJson.getError("微信支付失败," + e.getReturnMsg());
|
|
|
|
+ }catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return AjaxJson.getError("下单失败," + e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -125,33 +175,112 @@ public class TbWalletAppController {
|
|
* 服务点提现
|
|
* 服务点提现
|
|
*/
|
|
*/
|
|
@RequestMapping("topdownSave")
|
|
@RequestMapping("topdownSave")
|
|
- public AjaxJson topdownSave(@RequestParam("amount") Integer amount,@RequestParam("outTradeNo")String outTradeNo,@RequestParam("transactionId") String transactionId) {
|
|
|
|
|
|
+ public AjaxJson topdownSave(@RequestParam("amount") Integer amount,@RequestParam("goodsName")String goodsName) {
|
|
//获取登录人
|
|
//获取登录人
|
|
APPLoginUserInfo appLoginInfo = StpAPPUserUtil.getAPPLoginInfo();
|
|
APPLoginUserInfo appLoginInfo = StpAPPUserUtil.getAPPLoginInfo();
|
|
TbPeople tbPeople = tbPeopleService.getById(appLoginInfo.getFk());
|
|
TbPeople tbPeople = tbPeopleService.getById(appLoginInfo.getFk());
|
|
- if(tbPeople.getWallet()<amount/100){
|
|
|
|
|
|
+ if (tbPeople.getWallet() < amount) {
|
|
return AjaxJson.getError("余额不足!");
|
|
return AjaxJson.getError("余额不足!");
|
|
}
|
|
}
|
|
- TbWalletTopdown tbWalletTopdown = new TbWalletTopdown();
|
|
|
|
- Date date = new Date();
|
|
|
|
- tbWalletTopdown.setMchid("AAAAAA1111111111AAAAAA");
|
|
|
|
- tbWalletTopdown.setOutTradeNo(outTradeNo);
|
|
|
|
- tbWalletTopdown.setAmount(String.valueOf(amount/100));
|
|
|
|
- tbWalletTopdown.setTransactionId(transactionId);
|
|
|
|
- tbWalletTopdown.setPeopleId(appLoginInfo.getFk().toString());
|
|
|
|
- tbWalletTopdown.setTopdownTime(date);
|
|
|
|
- tbWalletTopdown.setCreateTime(date);
|
|
|
|
- tbWalletTopdown.setCreateBy(appLoginInfo.getLoginId().toString());
|
|
|
|
- tbWalletTopdown.setCreateName(appLoginInfo.getLoginName());
|
|
|
|
- tbWalletTopdown.setDeleteStatus(DeleteStatus.DELETE_STATUS_ON.getCode());
|
|
|
|
- boolean ret=tbWalletTopdownService.save(tbWalletTopdown);
|
|
|
|
- if(ret){
|
|
|
|
- tbPeople.setWallet(tbPeople.getWallet()-amount/100);
|
|
|
|
|
|
+ try {
|
|
|
|
+ TbWalletTopdown tbWalletTopdown = new TbWalletTopdown();
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ tbWalletTopdown.setMchid(this.wxService.getConfig().getMchId());
|
|
|
|
+ tbWalletTopdown.setOutTradeNo(TX_TABLE_NAME + System.currentTimeMillis());
|
|
|
|
+ tbWalletTopdown.setGoodsName(goodsName);
|
|
|
|
+ tbWalletTopdown.setAmount(amount.toString());
|
|
|
|
+ tbWalletTopdown.setPeopleId(tbPeople.getId().toString());
|
|
|
|
+ tbWalletTopdown.setTopdownTime(date);
|
|
|
|
+ tbWalletTopdown.setCreateTime(date);
|
|
|
|
+ tbWalletTopdown.setCreateBy(appLoginInfo.getLoginId().toString());
|
|
|
|
+ tbWalletTopdown.setCreateName(appLoginInfo.getLoginName());
|
|
|
|
+
|
|
|
|
+ //调用企业付款到零钱接口,并组装接口所需参数对象
|
|
|
|
+ EntPayRequest request = new EntPayRequest();
|
|
|
|
+ // 商品描述
|
|
|
|
+ request.setDescription(tbWalletTopdown.getGoodsName());
|
|
|
|
+ // 商户订单编号
|
|
|
|
+ request.setPartnerTradeNo(tbWalletTopdown.getOutTradeNo());
|
|
|
|
+ //支付金额
|
|
|
|
+ request.setAmount(BaseWxPayRequest.yuanToFen(tbWalletTopdown.getAmount()));
|
|
|
|
+ request.setSpbillCreateIp(WebNbUtil.getIP(SpringMVCUtil.getRequest()));
|
|
|
|
+ // 交易类型APP
|
|
|
|
+ request.setCheckName(WxPayConstants.CheckNameOption.FORCE_CHECK);
|
|
|
|
+ request.setReUserName(tbPeople.getBankName());
|
|
|
|
+ request.setOpenid(tbPeople.getWxOpenId());
|
|
|
|
+ EntPayResult data = this.wxService.getEntPayService().entPay(request);
|
|
|
|
+ // 业务处理
|
|
|
|
+ tbWalletTopdown.setTransactionId(data.getPaymentNo());
|
|
|
|
+ // 成功
|
|
|
|
+ tbWalletTopdown.setPayStatus(2);
|
|
|
|
+ tbWalletTopdownService.updateById(tbWalletTopdown);
|
|
|
|
+ tbPeople.setWallet(tbPeople.getWallet()-Double.parseDouble(tbWalletTopdown.getAmount()));
|
|
tbPeopleService.updateById(tbPeople);
|
|
tbPeopleService.updateById(tbPeople);
|
|
return AjaxJson.getSuccess();
|
|
return AjaxJson.getSuccess();
|
|
- }else{
|
|
|
|
- return AjaxJson.getError("操作失败!");
|
|
|
|
|
|
+ } catch (WxPayException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return AjaxJson.getError("微信支付失败," + e.getReturnMsg());
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return AjaxJson.getError("下单失败," + e.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 微信支付回调接口
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "/wxPay/notify", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")
|
|
|
|
+ public void notify(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
+ try {
|
|
|
|
+ request.setCharacterEncoding("UTF-8");
|
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
|
+ response.setContentType("text/html;charset=UTF-8");
|
|
|
|
+ response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
+ InputStream in = request.getInputStream();
|
|
|
|
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
|
+ int len = 0;
|
|
|
|
+ while ((len = in.read(buffer)) != -1) {
|
|
|
|
+ out.write(buffer, 0, len);
|
|
|
|
+ }
|
|
|
|
+ out.close();
|
|
|
|
+ in.close();
|
|
|
|
+ //xml数据
|
|
|
|
+ String reponseXml = new String(out.toByteArray(), "utf-8");
|
|
|
|
+ WxPayOrderNotifyResult result = wxService.parseOrderNotifyResult(reponseXml);
|
|
|
|
+ String resultCode = result.getResultCode();
|
|
|
|
+ String outTradeNo = result.getOutTradeNo();
|
|
|
|
+ if ("FAIL".equalsIgnoreCase(resultCode)) {
|
|
|
|
+ LogUtil.info("订单" + outTradeNo + "支付失败");
|
|
|
|
+ response.getWriter().write(setXml("SUCCESS", "OK"));
|
|
|
|
+ } else if ("SUCCESS".equalsIgnoreCase(resultCode)) {
|
|
|
|
+ LogUtil.info("订单" + outTradeNo + "支付成功");
|
|
|
|
+ // 充值数据处理
|
|
|
|
+ if(outTradeNo.indexOf(CZ_TABLE_NAME)>-1){
|
|
|
|
+ QueryWrapper<TbWalletTopup> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.eq("outTradeNo", outTradeNo);
|
|
|
|
+ TbWalletTopup tbWalletTopup=tbWalletTopupService.list(queryWrapper).get(0);
|
|
|
|
+ tbWalletTopup.setPayStatus(2);
|
|
|
|
+ tbWalletTopupService.updateById(tbWalletTopup);
|
|
|
|
+
|
|
|
|
+ TbPeople tbPeople = tbPeopleService.getById(tbWalletTopup.getPeopleId());
|
|
|
|
+ tbPeople.setWallet(tbPeople.getWallet()+Double.parseDouble(tbWalletTopup.getAmount()));
|
|
|
|
+ tbPeopleService.updateById(tbPeople);
|
|
|
|
+ }
|
|
|
|
+ response.getWriter().write(setXml("SUCCESS", "OK"));
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //返回微信服务
|
|
|
|
+ public static String setXml(String returnCode, String returnMsg) {
|
|
|
|
+ return "<xml><return_code><![CDATA[" + returnCode + "]]></return_code><return_msg><![CDATA[" + returnMsg + "]]></return_msg></xml>";
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|