充值支付 (未完成)
This commit is contained in:
parent
a8025c2f24
commit
c3ede05af0
|
|
@ -40,8 +40,8 @@ public class WxPayDriver {
|
||||||
* @author fzr
|
* @author fzr
|
||||||
* @return WxPayService
|
* @return WxPayService
|
||||||
*/
|
*/
|
||||||
public static WxPayService handler(String terminal) {
|
public static WxPayService handler(Integer terminal) {
|
||||||
if (String.valueOf(ClientEnum.OA.getCode()).equalsIgnoreCase(terminal)) {
|
if (ClientEnum.OA.getCode() == terminal) {
|
||||||
resetConfig("oa");
|
resetConfig("oa");
|
||||||
} else {
|
} else {
|
||||||
resetConfig("mnp");
|
resetConfig("mnp");
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import com.mdd.common.enums.HttpEnum;
|
||||||
import com.mdd.common.exception.LoginException;
|
import com.mdd.common.exception.LoginException;
|
||||||
import com.mdd.common.mapper.user.UserMapper;
|
import com.mdd.common.mapper.user.UserMapper;
|
||||||
import com.mdd.common.util.StringUtils;
|
import com.mdd.common.util.StringUtils;
|
||||||
import io.swagger.models.auth.In;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
@ -46,13 +45,13 @@ public class LikeFrontInterceptor implements HandlerInterceptor {
|
||||||
@NonNull Object handler) throws Exception {
|
@NonNull Object handler) throws Exception {
|
||||||
|
|
||||||
// 判断请求接口
|
// 判断请求接口
|
||||||
|
response.setContentType("application/json;charset=utf-8");
|
||||||
String reqUri = request.getRequestURI();
|
String reqUri = request.getRequestURI();
|
||||||
if (!(handler instanceof HandlerMethod) || !reqUri.startsWith("/api")) {
|
if (!(handler instanceof HandlerMethod) || !reqUri.startsWith("/api")) {
|
||||||
return HandlerInterceptor.super.preHandle(request, response, handler);
|
return HandlerInterceptor.super.preHandle(request, response, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 记录当前平台
|
// 记录当前平台
|
||||||
response.setContentType("application/json;charset=utf-8");
|
|
||||||
String terminal = request.getHeader("terminal");
|
String terminal = request.getHeader("terminal");
|
||||||
LikeFrontThreadLocal.put("terminal", StringUtils.isEmpty(terminal) ? "1" : terminal);
|
LikeFrontThreadLocal.put("terminal", StringUtils.isEmpty(terminal) ? "1" : terminal);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,13 @@ package com.mdd.front.controller;
|
||||||
|
|
||||||
import com.mdd.common.aop.NotLogin;
|
import com.mdd.common.aop.NotLogin;
|
||||||
import com.mdd.common.core.AjaxResult;
|
import com.mdd.common.core.AjaxResult;
|
||||||
|
import com.mdd.front.LikeFrontThreadLocal;
|
||||||
import com.mdd.front.service.IPayService;
|
import com.mdd.front.service.IPayService;
|
||||||
|
import com.mdd.front.validate.PayPrepayValidate;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.models.auth.In;
|
||||||
|
import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
@ -25,8 +30,12 @@ public class PayController {
|
||||||
*/
|
*/
|
||||||
@NotLogin
|
@NotLogin
|
||||||
@PostMapping("/prepay")
|
@PostMapping("/prepay")
|
||||||
public AjaxResult<Object> prepay() throws Exception {
|
public AjaxResult<Object> prepay(@Validated @RequestBody PayPrepayValidate payPrepayValidate) throws Exception {
|
||||||
iPayService.prepay();
|
String scene = payPrepayValidate.getScene();
|
||||||
|
Integer orderId = payPrepayValidate.getOrderId();
|
||||||
|
Integer terminal = LikeFrontThreadLocal.getTerminal();
|
||||||
|
|
||||||
|
iPayService.prepay(scene, orderId, terminal);
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -35,6 +44,8 @@ public class PayController {
|
||||||
*
|
*
|
||||||
* @return AjaxResult<Object>
|
* @return AjaxResult<Object>
|
||||||
*/
|
*/
|
||||||
|
@NotLogin
|
||||||
|
@PostMapping("/notifyMnp")
|
||||||
public AjaxResult<Object> notifyMnp() {
|
public AjaxResult<Object> notifyMnp() {
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,8 @@ import com.mdd.front.service.IRechargeService;
|
||||||
import com.mdd.front.validate.RechargeValidate;
|
import com.mdd.front.validate.RechargeValidate;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.models.auth.In;
|
import io.swagger.models.auth.In;
|
||||||
import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,6 @@ package com.mdd.front.service;
|
||||||
*/
|
*/
|
||||||
public interface IPayService {
|
public interface IPayService {
|
||||||
|
|
||||||
void prepay() throws Exception;
|
void prepay(String scene, Integer orderId, Integer terminal) throws Exception;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,45 +1,65 @@
|
||||||
package com.mdd.front.service.impl;
|
package com.mdd.front.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request;
|
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request;
|
||||||
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderV3Result;
|
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderV3Result;
|
||||||
import com.github.binarywang.wxpay.bean.result.enums.TradeTypeEnum;
|
import com.github.binarywang.wxpay.bean.result.enums.TradeTypeEnum;
|
||||||
import com.github.binarywang.wxpay.service.WxPayService;
|
import com.github.binarywang.wxpay.service.WxPayService;
|
||||||
|
import com.mdd.common.entity.RechargeOrder;
|
||||||
|
import com.mdd.common.mapper.RechargeOrderMapper;
|
||||||
import com.mdd.common.plugin.wechat.WxPayDriver;
|
import com.mdd.common.plugin.wechat.WxPayDriver;
|
||||||
|
import com.mdd.common.util.RequestUtils;
|
||||||
import com.mdd.front.service.IPayService;
|
import com.mdd.front.service.IPayService;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PayServiceImpl implements IPayService {
|
public class PayServiceImpl implements IPayService {
|
||||||
|
|
||||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
@Resource
|
||||||
|
RechargeOrderMapper rechargeOrderMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prepay() throws Exception {
|
public void prepay(String scene, Integer orderId, Integer terminal) throws Exception {
|
||||||
|
RechargeOrder rechargeOrder = rechargeOrderMapper.selectOne(
|
||||||
|
new QueryWrapper<RechargeOrder>()
|
||||||
|
.eq("id", orderId)
|
||||||
|
.last("limit 1"));
|
||||||
|
|
||||||
WxPayService wxPayService = WxPayDriver.handler("1");
|
String orderSn = rechargeOrder.getOrderSn();
|
||||||
|
Integer orderAmount = 1;
|
||||||
|
String orderDesc = "余额充值";
|
||||||
|
|
||||||
String sn = "sn" + System.currentTimeMillis() / 1000;
|
// 失效时间
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||||
Long expireTime = System.currentTimeMillis() + 60 * 1000;
|
Long expireTime = System.currentTimeMillis() + 60 * 1000;
|
||||||
String timeExpire = format.format(expireTime) + "+08:00";
|
String timeExpire = format.format(expireTime) + "+08:00";
|
||||||
|
|
||||||
// 订单信息
|
// 订单信息
|
||||||
WxPayUnifiedOrderV3Request wxPayUnifiedOrderV3Request = new WxPayUnifiedOrderV3Request();
|
WxPayUnifiedOrderV3Request wxPayUnifiedOrderV3Request = new WxPayUnifiedOrderV3Request();
|
||||||
wxPayUnifiedOrderV3Request.setOutTradeNo(sn);
|
wxPayUnifiedOrderV3Request.setOutTradeNo(orderSn);
|
||||||
wxPayUnifiedOrderV3Request.setNotifyUrl("https://www.likeadmin.cn");
|
wxPayUnifiedOrderV3Request.setDescription(orderDesc);
|
||||||
wxPayUnifiedOrderV3Request.setDescription("充值");
|
|
||||||
wxPayUnifiedOrderV3Request.setTimeExpire(timeExpire);
|
wxPayUnifiedOrderV3Request.setTimeExpire(timeExpire);
|
||||||
|
wxPayUnifiedOrderV3Request.setNotifyUrl(RequestUtils.uri() + "/api/pay/notifyMnp");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 订单金额
|
// 订单金额
|
||||||
WxPayUnifiedOrderV3Request.Amount amount = new WxPayUnifiedOrderV3Request.Amount();
|
WxPayUnifiedOrderV3Request.Amount amount = new WxPayUnifiedOrderV3Request.Amount();
|
||||||
amount.setTotal(1);
|
amount.setTotal(orderAmount);
|
||||||
amount.setCurrency("CNY");
|
amount.setCurrency("CNY");
|
||||||
wxPayUnifiedOrderV3Request.setAmount(amount);
|
wxPayUnifiedOrderV3Request.setAmount(amount);
|
||||||
|
|
||||||
// 付款人
|
// 付款人员
|
||||||
WxPayUnifiedOrderV3Request.Payer payer = new WxPayUnifiedOrderV3Request.Payer();
|
WxPayUnifiedOrderV3Request.Payer payer = new WxPayUnifiedOrderV3Request.Payer();
|
||||||
payer.setOpenid("");
|
payer.setOpenid("");
|
||||||
|
|
||||||
|
// 发起订单
|
||||||
|
WxPayService wxPayService = WxPayDriver.handler(terminal);
|
||||||
wxPayUnifiedOrderV3Request.setPayer(payer);
|
wxPayUnifiedOrderV3Request.setPayer(payer);
|
||||||
WxPayUnifiedOrderV3Result.JsapiResult jsapiResult = wxPayService.createOrderV3(TradeTypeEnum.JSAPI, wxPayUnifiedOrderV3Request);
|
WxPayUnifiedOrderV3Result.JsapiResult jsapiResult = wxPayService.createOrderV3(TradeTypeEnum.JSAPI, wxPayUnifiedOrderV3Request);
|
||||||
System.out.println(jsapiResult);
|
System.out.println(jsapiResult);
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,15 @@ public class RechargeServiceImpl implements IRechargeService {
|
||||||
@Resource
|
@Resource
|
||||||
RechargeOrderMapper rechargeOrderMapper;
|
RechargeOrderMapper rechargeOrderMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建充值订单
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param terminal 设备端
|
||||||
|
* @param rechargeValidate 参数
|
||||||
|
* @return Map<String, Object>
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> placeOrder(Integer userId, Integer terminal, RechargeValidate rechargeValidate) {
|
public Map<String, Object> placeOrder(Integer userId, Integer terminal, RechargeValidate rechargeValidate) {
|
||||||
RechargeOrder order = new RechargeOrder();
|
RechargeOrder order = new RechargeOrder();
|
||||||
|
|
@ -38,7 +47,7 @@ public class RechargeServiceImpl implements IRechargeService {
|
||||||
rechargeOrderMapper.insert(order);
|
rechargeOrderMapper.insert(order);
|
||||||
|
|
||||||
Map<String, Object> response = new LinkedHashMap<>();
|
Map<String, Object> response = new LinkedHashMap<>();
|
||||||
response.put("id", order.getId());
|
response.put("orderId", order.getId());
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,14 +58,14 @@ public class RechargeServiceImpl implements IRechargeService {
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
private String randMakeOrderSn() {
|
private String randMakeOrderSn() {
|
||||||
String date = TimeUtils.timestampToDate(System.currentTimeMillis()/1000, "YmdHis");
|
String date = TimeUtils.timestampToDate(System.currentTimeMillis()/1000, "yyyyMMddHHmmss");
|
||||||
String sn;
|
String sn;
|
||||||
while (true) {
|
while (true) {
|
||||||
sn = date + ToolUtils.randomInt(12);
|
sn = date + ToolUtils.randomInt(12);
|
||||||
RechargeOrder snModel = rechargeOrderMapper.selectOne(
|
RechargeOrder snModel = rechargeOrderMapper.selectOne(
|
||||||
new QueryWrapper<RechargeOrder>()
|
new QueryWrapper<RechargeOrder>()
|
||||||
.select("id")
|
.select("id")
|
||||||
.eq("sn", sn)
|
.eq("order_sn", sn)
|
||||||
.last("limit 1"));
|
.last("limit 1"));
|
||||||
if (snModel == null) {
|
if (snModel == null) {
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.mdd.front.validate;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ApiModel("预支付订单参数")
|
||||||
|
public class PayPrepayValidate implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private String scene;
|
||||||
|
|
||||||
|
private Integer orderId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
package com.mdd.front.validate;
|
package com.mdd.front.validate;
|
||||||
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.models.auth.In;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue