|
@@ -5,7 +5,6 @@ import cn.hutool.http.ContentType;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.ijpay.core.IJPayHttpResponse;
|
|
|
-import com.ijpay.core.enums.AuthTypeEnum;
|
|
|
import com.ijpay.core.enums.RequestMethodEnum;
|
|
|
import com.ijpay.core.kit.HttpKit;
|
|
|
import com.ijpay.core.kit.PayKit;
|
|
@@ -17,26 +16,21 @@ import com.ijpay.wxpay.enums.v3.BasePayApiEnum;
|
|
|
import com.ijpay.wxpay.model.v3.Amount;
|
|
|
import com.ijpay.wxpay.model.v3.Payer;
|
|
|
import com.ijpay.wxpay.model.v3.UnifiedOrderModel;
|
|
|
-import com.ruoyi.common.annotation.Log;
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
-import com.ruoyi.common.enums.BusinessType;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
-import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.web.work.api.config.BaseController;
|
|
|
import com.ruoyi.web.work.domain.Pay;
|
|
|
-import com.ruoyi.web.work.domain.Recharge;
|
|
|
import com.ruoyi.web.work.domain.User;
|
|
|
-import com.ruoyi.web.work.domain.dto.CompanyPayDto;
|
|
|
import com.ruoyi.web.work.domain.dto.PayDto;
|
|
|
-import com.ruoyi.web.work.domain.dto.PayStateDto;
|
|
|
-import com.ruoyi.web.work.service.ICompanyService;
|
|
|
import com.ruoyi.web.work.service.IPayService;
|
|
|
-import com.ruoyi.web.work.service.IRechargeService;
|
|
|
import com.ruoyi.web.work.service.IUserService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
+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.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -58,70 +52,17 @@ public class UserPayController extends BaseController {
|
|
|
@Autowired
|
|
|
private IUserService userService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private IRechargeService rechargeService;
|
|
|
|
|
|
@Autowired
|
|
|
private IPayService payService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private ICompanyService companyService;
|
|
|
|
|
|
/**
|
|
|
- * PC扫码支付
|
|
|
- *
|
|
|
* @param dto
|
|
|
* @return
|
|
|
*/
|
|
|
- @Log(title = "微信充值", businessType = BusinessType.PAY)
|
|
|
- @PostMapping("/companyPay")
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public AjaxResult companyPay(@Validated @RequestBody CompanyPayDto dto) {
|
|
|
- try {
|
|
|
- String orderNum = PayKit.generateStr();
|
|
|
- UnifiedOrderModel unifiedOrderModel = new UnifiedOrderModel();
|
|
|
- unifiedOrderModel.setAppid(wxPayV3Bean.getAppId());
|
|
|
- unifiedOrderModel.setMchid(wxPayV3Bean.getMchId());
|
|
|
- unifiedOrderModel.setDescription("企业账户充值");
|
|
|
- unifiedOrderModel.setOut_trade_no(orderNum);
|
|
|
- unifiedOrderModel.setTime_expire(DateTimeZoneUtil.dateToTimeZone(System.currentTimeMillis() + 1000 * 60 * 3));
|
|
|
- unifiedOrderModel.setAttach("企业账户充值");
|
|
|
- unifiedOrderModel.setNotify_url(wxPayV3Bean.getDomain().concat("/app/wxPay/companyNotify"));
|
|
|
- unifiedOrderModel.setAmount(new Amount().setTotal(dto.getMoney().multiply(new BigDecimal(100)).intValue()));
|
|
|
- IJPayHttpResponse response = WxPayApi.v3(RequestMethodEnum.POST, WxDomainEnum.CHINA.toString(), BasePayApiEnum.NATIVE_PAY.toString(), wxPayV3Bean.getMchId(), getSerialNumber(), null, wxPayV3Bean.getKeyPath(), JSONUtil.toJsonStr(unifiedOrderModel), AuthTypeEnum.RSA.getCode());
|
|
|
- boolean verifySignature = WxPayKit.verifySignature(response, wxPayV3Bean.getPlatformCertPath());
|
|
|
- if (response.getStatus() == 200 && verifySignature) {
|
|
|
- //保存订单信息
|
|
|
- Recharge recharge = new Recharge();
|
|
|
- recharge.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
|
|
|
- recharge.setState(0);
|
|
|
- recharge.setType(1);
|
|
|
- recharge.setIdent(dto.getIdent());
|
|
|
- recharge.setNums(orderNum);
|
|
|
- recharge.setMoney(dto.getMoney());
|
|
|
- recharge.setVersion(System.currentTimeMillis());
|
|
|
- recharge.setOpBy(SecurityUtils.getLoginUser().getUser().getNickName());
|
|
|
- recharge.setUserId(SecurityUtils.getLoginUser().getUser().getUserId());
|
|
|
- if (!rechargeService.save(recharge)) {
|
|
|
- return AjaxResult.error("充值失败,请联系平台或者转账充值");
|
|
|
- }
|
|
|
- return AjaxResult.success(response.getBody());
|
|
|
- }
|
|
|
- return AjaxResult.error("支付异常,请联系平台或者转账充值");
|
|
|
- } catch (Exception e) {
|
|
|
- throw new ServiceException(e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- @GetMapping("/payState")
|
|
|
- public AjaxResult payState(@Validated PayStateDto dto) {
|
|
|
- return AjaxResult.success(rechargeService.selectByIdent(dto.getIdent()) == null ? false : true);
|
|
|
- }
|
|
|
- /**
|
|
|
- * @param dto
|
|
|
- * @return
|
|
|
- */
|
|
|
- @PostMapping("/jsApiPay")
|
|
|
- public AjaxResult jsApiPay(@Validated @RequestBody PayDto dto) {
|
|
|
+ @PostMapping("/pay")
|
|
|
+ public AjaxResult pay(@Validated @RequestBody PayDto dto) {
|
|
|
try {
|
|
|
String orderNum = PayKit.generateStr();
|
|
|
UnifiedOrderModel unifiedOrderModel = new UnifiedOrderModel();
|
|
@@ -132,7 +73,7 @@ public class UserPayController extends BaseController {
|
|
|
unifiedOrderModel.setTime_expire(DateTimeZoneUtil.dateToTimeZone(System.currentTimeMillis() + 1000 * 60 * 3));
|
|
|
unifiedOrderModel.setAttach("账户充值");
|
|
|
unifiedOrderModel.setAmount(new Amount().setTotal(dto.getMoney().multiply(new BigDecimal(100)).intValue()));
|
|
|
- unifiedOrderModel.setNotify_url(wxPayV3Bean.getDomain().concat("/app/wxPay/payNotify"));
|
|
|
+ unifiedOrderModel.setNotify_url(wxPayV3Bean.getDomain().concat("/app/wxPay/notify"));
|
|
|
unifiedOrderModel.setPayer(new Payer().setOpenid(getUser().getOpenId()));
|
|
|
IJPayHttpResponse response = WxPayApi.v3(RequestMethodEnum.POST, WxDomainEnum.CHINA.toString(), BasePayApiEnum.JS_API_PAY.toString(), wxPayV3Bean.getMchId(), getSerialNumber(), null, wxPayV3Bean.getKeyPath(), JSONUtil.toJsonStr(unifiedOrderModel));
|
|
|
System.out.println("统一下单响应:" + response);
|
|
@@ -146,6 +87,8 @@ public class UserPayController extends BaseController {
|
|
|
pay.setUserId(getUser().getId());
|
|
|
pay.setMoney(dto.getMoney());
|
|
|
pay.setState(0);
|
|
|
+ pay.setType(0);
|
|
|
+ pay.setTitle("在线充值");
|
|
|
pay.setVersion(System.currentTimeMillis());
|
|
|
pay.setNums(orderNum);
|
|
|
if (!payService.save(pay)) {
|
|
@@ -160,7 +103,7 @@ public class UserPayController extends BaseController {
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
- @PostMapping(value = "/payNotify")
|
|
|
+ @PostMapping(value = "/notify")
|
|
|
public void payNotify(HttpServletRequest request, HttpServletResponse response) {
|
|
|
Map<String, String> map = new HashMap<>(12);
|
|
|
try {
|
|
@@ -202,6 +145,7 @@ public class UserPayController extends BaseController {
|
|
|
throw new ServiceException(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 获取证书序列号
|
|
|
*
|