支付
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package io.v.nutz.base.annontation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 自定义注解防止表单重复提交
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface RepeatSubmit {
|
||||
/**
|
||||
* 间隔时间(ms),小于此时间视为重复提交
|
||||
*/
|
||||
public int interval() default 5000;
|
||||
|
||||
/**
|
||||
* 提示消息
|
||||
*/
|
||||
public String message() default "请求过于频繁,请稍后再试";
|
||||
}
|
||||
@@ -22,4 +22,8 @@ public class RedisConstant {
|
||||
//健步走小程序TOKEN
|
||||
public final static String REDIS_KEY_WE_APP_ACCESS_TOKEN = "weapp:token:";
|
||||
|
||||
/**
|
||||
* 接口重复提交前缀
|
||||
*/
|
||||
public static final String REPEAT_SUBMIT_PREFIX = PLATFORM_REDIS_PREFIX + "repeat_submit:";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package io.v.nutz.base.exception;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
public class BaseException extends RuntimeException{
|
||||
|
||||
private static final long serialVersionUID = 7192152812384031563L;
|
||||
|
||||
public BaseException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public BaseException(String message, Object... arguments) {
|
||||
super(StrUtil.format(message, arguments));
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package io.v.nutz.base.interceptor.repeatSubmit;
|
||||
|
||||
import io.v.nutz.base.annontation.RepeatSubmit;
|
||||
import org.nutz.aop.MethodInterceptor;
|
||||
import org.nutz.ioc.Ioc;
|
||||
import org.nutz.ioc.aop.SimpleAopMaker;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
@IocBean(name = "$aop_repeatSubmit")
|
||||
public class RepeatSubmitAopConfiguration extends SimpleAopMaker<RepeatSubmit> {
|
||||
|
||||
@Override
|
||||
public List<? extends MethodInterceptor> makeIt(RepeatSubmit repeatSubmit, Method method, Ioc ioc) {
|
||||
return List.of(new RepeatSubmitAopInterceptor(ioc, repeatSubmit, method));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package io.v.nutz.base.interceptor.repeatSubmit;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import io.v.nutz.base.annontation.RepeatSubmit;
|
||||
import io.v.nutz.base.constant.RedisConstant;
|
||||
import io.v.nutz.base.exception.BaseException;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import org.nutz.aop.InterceptorChain;
|
||||
import org.nutz.aop.MethodInterceptor;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
import org.nutz.ioc.Ioc;
|
||||
import org.nutz.mvc.Mvcs;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class RepeatSubmitAopInterceptor implements MethodInterceptor {
|
||||
|
||||
protected Ioc ioc;
|
||||
|
||||
public RepeatSubmitAopInterceptor(Ioc ioc, RepeatSubmit repeatSubmit, Method method) {
|
||||
RedisService redisService = ioc.get(RedisService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void filter(InterceptorChain chain) throws Throwable {
|
||||
Method method = chain.getCallingMethod();
|
||||
RepeatSubmit annotation = method.getAnnotation(RepeatSubmit.class);
|
||||
int interval = annotation.interval();
|
||||
RedisService redisService = Mvcs.getIoc().get(RedisService.class);
|
||||
String source = method.getDeclaringClass().getName() + "#" + method.getName();
|
||||
Object[] args = chain.getArgs();
|
||||
String parameterJson = "";
|
||||
if (ObjectUtil.isNotEmpty(args)) {
|
||||
parameterJson = JSONUtil.toJsonStr(args); // 序列化实际参数
|
||||
}
|
||||
String key = RedisConstant.REPEAT_SUBMIT_PREFIX + ShiroUtil.getUserId() + ":" + source;
|
||||
|
||||
Boolean exists = redisService.exists(key);
|
||||
if (exists) {
|
||||
// 判断
|
||||
String oldParameterJson = redisService.get(key);
|
||||
if (oldParameterJson != null && oldParameterJson.equalsIgnoreCase(parameterJson)) {
|
||||
throw new BaseException(annotation.message());
|
||||
}
|
||||
} else {
|
||||
redisService.setex(key, interval / 1000, parameterJson);
|
||||
}
|
||||
chain.doChain();
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package io.v.nutz.zhgh.memberCost.payment.alipay.controller;
|
||||
package io.v.nutz.base.payment.alipay.controller;
|
||||
|
||||
import io.v.nutz.zhgh.memberCost.payment.alipay.service.AlipayService;
|
||||
import io.v.nutz.base.payment.alipay.service.AlipayService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package io.v.nutz.zhgh.memberCost.payment.alipay.service;
|
||||
package io.v.nutz.base.payment.alipay.service;
|
||||
|
||||
/**
|
||||
* @ClassName AlipayClientConfig
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package io.v.nutz.zhgh.memberCost.payment.alipay.service;
|
||||
package io.v.nutz.base.payment.alipay.service;
|
||||
|
||||
|
||||
import io.v.nutz.base.service.ViService;
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
package io.v.nutz.zhgh.memberCost.payment.alipay.service.impl;
|
||||
package io.v.nutz.base.payment.alipay.service.impl;
|
||||
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayConstants;
|
||||
@@ -7,11 +7,11 @@ import com.alipay.api.domain.AlipayTradeWapPayModel;
|
||||
import com.alipay.api.internal.util.AlipaySignature;
|
||||
import com.alipay.api.request.AlipayTradeWapPayRequest;
|
||||
import com.alipay.api.response.AlipayTradeWapPayResponse;
|
||||
import io.v.nutz.base.payment.alipay.service.AlipayClientConfig;
|
||||
import io.v.nutz.base.payment.alipay.service.AlipayService;
|
||||
import io.v.nutz.base.service.impl.ViServiceImpl;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import io.v.nutz.zhgh.memberCost.payment.alipay.service.AlipayClientConfig;
|
||||
import io.v.nutz.zhgh.memberCost.model.MemberPaymentInfo;
|
||||
import io.v.nutz.zhgh.memberCost.payment.alipay.service.AlipayService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
+3
-1
@@ -1,6 +1,8 @@
|
||||
package io.v.nutz.zhgh.memberCost.payment.enums;
|
||||
package io.v.nutz.base.payment.enums;
|
||||
|
||||
import io.v.nutz.base.annontation.SelectEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 退款状态枚举
|
||||
+3
-1
@@ -1,6 +1,8 @@
|
||||
package io.v.nutz.zhgh.memberCost.payment.enums;
|
||||
package io.v.nutz.base.payment.enums;
|
||||
|
||||
import io.v.nutz.base.annontation.SelectEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 交易渠道枚举
|
||||
+3
-1
@@ -1,6 +1,8 @@
|
||||
package io.v.nutz.zhgh.memberCost.payment.enums;
|
||||
package io.v.nutz.base.payment.enums;
|
||||
|
||||
import io.v.nutz.base.annontation.SelectEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
|
||||
/**
|
||||
+3
-1
@@ -1,6 +1,8 @@
|
||||
package io.v.nutz.zhgh.memberCost.payment.enums;
|
||||
package io.v.nutz.base.payment.enums;
|
||||
|
||||
import io.v.nutz.base.annontation.SelectEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 交易类型枚举
|
||||
@@ -0,0 +1,30 @@
|
||||
package io.v.nutz.base.payment.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author zzr
|
||||
* @name:WxPayResultCode
|
||||
* @Date 2025/3/10 10:27
|
||||
* @注释 微信支付返回码
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum WxPayResultCode {
|
||||
|
||||
SUCCESS(200, "操作成功"),
|
||||
APPID_MCHID_NOT_MATCH(400, "商户ID和服务号或企业微信号不匹配"),
|
||||
INVALID_REQUEST(400, "无效请求"),
|
||||
MCH_NOT_EXISTS(400, "商户号不存在"),
|
||||
PARAM_ERROR(400, "参数错误"),
|
||||
SIGN_ERROR(401, "签名错误"),
|
||||
NO_AUTH(403, "商户无权限"),
|
||||
OUT_TRADE_NO_USED(403, "商户订单号重复"),
|
||||
FREQUENCY_LIMITED(429, "频率超限"),
|
||||
SYSTEM_ERROR(500, "系统错误");
|
||||
|
||||
final int code;
|
||||
final String msg;
|
||||
}
|
||||
+6
-2
@@ -1,6 +1,10 @@
|
||||
package io.v.nutz.zhgh.memberCost.payment.model;
|
||||
package io.v.nutz.base.payment.model;
|
||||
|
||||
import io.v.nutz.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@@ -83,7 +87,7 @@ public class PaymentTransaction extends BaseModel {
|
||||
@Column
|
||||
@Comment("退款金额")
|
||||
@ColDefine(customType = "decimal")
|
||||
private String refundAmount;
|
||||
private BigDecimal refundAmount;
|
||||
|
||||
@Column
|
||||
@Comment("订单描述")
|
||||
+5
-1
@@ -1,6 +1,10 @@
|
||||
package io.v.nutz.zhgh.memberCost.payment.model;
|
||||
package io.v.nutz.base.payment.model;
|
||||
|
||||
import io.v.nutz.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package io.v.nutz.zhgh.memberCost.payment.wxpay.bean;
|
||||
package io.v.nutz.base.payment.wxpay.bean;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
+7
-6
@@ -1,6 +1,7 @@
|
||||
package io.v.nutz.zhgh.memberCost.payment.wxpay.service;
|
||||
package io.v.nutz.base.payment.wxpay.service;
|
||||
|
||||
import io.v.nutz.zhgh.memberCost.payment.wxpay.vo.WxPayNeedParamVo;
|
||||
import io.v.nutz.base.payment.wxpay.vo.WxPayNeedParamVo;
|
||||
import io.v.nutz.base.result.Result;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -21,7 +22,7 @@ public interface WxPayCommonService {
|
||||
* 注意Amount的总价total是int类型,会自动乘以0.01,例如传递100元,会自动转换为1元
|
||||
* @return
|
||||
*/
|
||||
String nativePay(WxPayNeedParamVo paramVo);
|
||||
Result nativePay(WxPayNeedParamVo paramVo);
|
||||
|
||||
|
||||
/**
|
||||
@@ -31,7 +32,7 @@ public interface WxPayCommonService {
|
||||
* JsAPI支付,需要传递openId,请自行获取
|
||||
* @return
|
||||
*/
|
||||
String jsApiPay(WxPayNeedParamVo paramVo);
|
||||
Result jsApiPay(WxPayNeedParamVo paramVo);
|
||||
|
||||
/**
|
||||
* WAP支付,返回支付参数
|
||||
@@ -39,7 +40,7 @@ public interface WxPayCommonService {
|
||||
* 注意Amount的总价total是int类型,会自动乘以0.01,例如传递100元,会自动转换为1元
|
||||
* @return
|
||||
*/
|
||||
String wapPay(WxPayNeedParamVo paramVo);
|
||||
Result wapPay(WxPayNeedParamVo paramVo);
|
||||
|
||||
|
||||
/**
|
||||
@@ -56,7 +57,7 @@ public interface WxPayCommonService {
|
||||
* @param outTradeNo 商户订单号
|
||||
* @return
|
||||
*/
|
||||
String refund(String transactionId, String outTradeNo);
|
||||
Result refund(String transactionId, String outTradeNo);
|
||||
|
||||
|
||||
/**
|
||||
+88
-29
@@ -1,4 +1,4 @@
|
||||
package io.v.nutz.zhgh.memberCost.payment.wxpay.service.impl;
|
||||
package io.v.nutz.base.payment.wxpay.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
@@ -19,16 +19,29 @@ import com.ijpay.wxpay.WxPayApi;
|
||||
import com.ijpay.wxpay.enums.WxDomainEnum;
|
||||
import com.ijpay.wxpay.enums.v3.BasePayApiEnum;
|
||||
import com.ijpay.wxpay.model.v3.*;
|
||||
import io.v.nutz.zhgh.memberCost.payment.wxpay.bean.WxPayV3Bean;
|
||||
import io.v.nutz.zhgh.memberCost.payment.wxpay.service.WxPayCommonService;
|
||||
import io.v.nutz.zhgh.memberCost.payment.wxpay.vo.WxPayNeedParamVo;
|
||||
import io.v.nutz.base.payment.enums.TradingChannelEnum;
|
||||
import io.v.nutz.base.payment.enums.TradingTypeEnum;
|
||||
import io.v.nutz.base.payment.enums.WxPayResultCode;
|
||||
import io.v.nutz.base.payment.model.PaymentTransaction;
|
||||
import io.v.nutz.base.payment.wxpay.bean.WxPayV3Bean;
|
||||
import io.v.nutz.base.payment.wxpay.service.WxPayCommonService;
|
||||
import io.v.nutz.base.payment.wxpay.vo.WxPayNeedParamVo;
|
||||
import io.v.nutz.base.result.Result;
|
||||
import io.v.nutz.sys.models.User;
|
||||
import io.v.nutz.sys.services.SysUserService;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.random.R;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
@@ -50,14 +63,15 @@ public class WxPayCommonServiceImpl implements WxPayCommonService {
|
||||
// 判断下单接口成功返回码
|
||||
private final static int OK = 200;
|
||||
|
||||
// 1666930980 商户号
|
||||
// 微信V3必要的支付参数,后期优化
|
||||
private final static WxPayV3Bean WX_PAY_V3_BEAN = new WxPayV3Bean(
|
||||
"ww3eda050a1b5ad96e",
|
||||
"src/main/java/io/v/nutz/zhgh/memberCost/wxpay/pem/apiclient_key.pem",
|
||||
"src/main/java/io/v/nutz/zhgh/memberCost/wxpay/pem/apiclient_key.pem",
|
||||
"src/main/java/io/v/nutz/zhgh/memberCost/wxpay/pem/apiclient_cert.pem",
|
||||
"src/main/java/io/v/nutz/zhgh/memberCost/wxpay/pem/apiclient_cert.pem",
|
||||
"src/main/java/io/v/nutz/zhgh/memberCost/wxpay/pem/wechatpay.pem",
|
||||
"src/main/java/io/v/nutz/base/payment/wxpay/pem/apiclient_key.pem",
|
||||
"src/main/java/io/v/nutz/base/payment/wxpay/wxpay/pem/apiclient_key.pem",
|
||||
"src/main/java/io/v/nutz/base/payment/wxpay/pem/apiclient_cert.pem",
|
||||
"src/main/java/io/v/nutz/base/payment/wxpay/pem/apiclient_cert.pem",
|
||||
"src/main/java/io/v/nutz/base/payment/wxpay/pem/wechatpay.pem",
|
||||
"1666930980",
|
||||
"",
|
||||
"4ebd020883285d698c44ec50939c0967",
|
||||
@@ -65,9 +79,12 @@ public class WxPayCommonServiceImpl implements WxPayCommonService {
|
||||
"");
|
||||
|
||||
// 自定义参数,内容是统一的,但会被多次调用,直接声明
|
||||
String serialNo;
|
||||
String platSerialNo;
|
||||
String payNotifyUrl = WX_PAY_V3_BEAN.getDomain().concat("/wxPay/notifyMessage");
|
||||
private String serialNo;
|
||||
private String platSerialNo;
|
||||
private final String payNotifyUrl = WX_PAY_V3_BEAN.getDomain().concat("/wxPay/notifyMessage");
|
||||
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
|
||||
/**
|
||||
* 微信扫描二维码支付
|
||||
@@ -76,7 +93,7 @@ public class WxPayCommonServiceImpl implements WxPayCommonService {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String nativePay(WxPayNeedParamVo paramVo) {
|
||||
public Result nativePay(WxPayNeedParamVo paramVo) {
|
||||
try {
|
||||
// 商户订单号,存储当前用户的订单
|
||||
String outTradeNo = PayKit.generateStr();
|
||||
@@ -113,20 +130,25 @@ public class WxPayCommonServiceImpl implements WxPayCommonService {
|
||||
// 下单返回数据
|
||||
String result = response.getBody();
|
||||
|
||||
if (result != null) {
|
||||
// 向数据库插入订单记录
|
||||
}
|
||||
JSONObject jsonObject = JSONUtil.parseObj(result);
|
||||
|
||||
return result;
|
||||
if (response.getStatus() == OK) {
|
||||
// 统一下单成功,向数据库插入订单记录
|
||||
insertTradingOrder(paramVo, outTradeNo, result);
|
||||
return Result.success("请在三分钟内完成支付,超时将自动取消订单").addData(result);
|
||||
} else {
|
||||
WxPayResultCode code = WxPayResultCode.valueOf(WxPayResultCode.class, jsonObject.getStr("code"));
|
||||
return Result.error(code.getMsg());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("系统异常", e);
|
||||
return e.getMessage();
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String jsApiPay(WxPayNeedParamVo paramVo) {
|
||||
public Result jsApiPay(WxPayNeedParamVo paramVo) {
|
||||
try {
|
||||
// 商户订单号,存储当前用户的订单
|
||||
String outTradeNo = PayKit.generateStr();
|
||||
@@ -166,18 +188,19 @@ public class WxPayCommonServiceImpl implements WxPayCommonService {
|
||||
log.info("唤起支付参数:{}", map);
|
||||
// 唤起支付成功,向数据库插入订单参数
|
||||
|
||||
return JSONUtil.toJsonStr(map);
|
||||
return Result.success(JSONUtil.toJsonStr(map));
|
||||
}
|
||||
return JSONUtil.toJsonStr(response);
|
||||
// return JSONUtil.toJsonStr(response);
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
log.error("系统异常", e);
|
||||
return e.getMessage();
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String wapPay(WxPayNeedParamVo paramVo) {
|
||||
public Result wapPay(WxPayNeedParamVo paramVo) {
|
||||
try {
|
||||
// 商户订单号,存储当前用户的订单
|
||||
String outTradeNo = PayKit.generateStr();
|
||||
@@ -215,12 +238,13 @@ public class WxPayCommonServiceImpl implements WxPayCommonService {
|
||||
log.info("verifySignature: {}", verifySignature);
|
||||
if (response.getStatus() == OK && verifySignature) {
|
||||
String body = response.getBody();
|
||||
return JSONUtil.toJsonStr(body);
|
||||
return Result.success(JSONUtil.toJsonStr(body));
|
||||
}
|
||||
return JSONUtil.toJsonStr(response);
|
||||
// return JSONUtil.toJsonStr(response);
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
log.error("系统异常", e);
|
||||
return e.getMessage();
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +302,7 @@ public class WxPayCommonServiceImpl implements WxPayCommonService {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String refund(String transactionId, String outTradeNo) {
|
||||
public Result refund(String transactionId, String outTradeNo) {
|
||||
try {
|
||||
String outRefundNo = PayKit.generateStr();
|
||||
log.info("商户退款单号: {}", outRefundNo);
|
||||
@@ -324,11 +348,11 @@ public class WxPayCommonServiceImpl implements WxPayCommonService {
|
||||
log.info("退款响应 {}", response);
|
||||
|
||||
if (verifySignature) {
|
||||
return response.getBody();
|
||||
return Result.success(response.getBody());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("系统异常", e);
|
||||
return e.getMessage();
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -476,4 +500,39 @@ public class WxPayCommonServiceImpl implements WxPayCommonService {
|
||||
DateTime dateTime = DateUtil.date(currentTimeMillis);
|
||||
return DateUtil.format(dateTime, "yyyy-MM-dd'T'HH:mm:ssXXX");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 公共方法,插入交易订单
|
||||
* @param paramVo 交易必填参数Vo
|
||||
* @param outTradeNo 商户交易号
|
||||
* @param result 下单返回结构
|
||||
*/
|
||||
private void insertTradingOrder(WxPayNeedParamVo paramVo, String outTradeNo, String result){
|
||||
User user = sysUserService.dao().fetch(User.class, Cnd.where("id", "=", ShiroUtil.getUserId()));
|
||||
PaymentTransaction transaction = new PaymentTransaction();
|
||||
transaction.setId(R.UU32());
|
||||
transaction.setMchId(WX_PAY_V3_BEAN.getMchId());
|
||||
transaction.setOutTradeNo(outTradeNo);
|
||||
transaction.setTradingOrderNo(null);
|
||||
transaction.setTradingChannel(TradingChannelEnum.WX_PAY.name());
|
||||
transaction.setTradingType(TradingTypeEnum.PAYMENT.name());
|
||||
transaction.setUserId(user.getId());
|
||||
transaction.setLoginName(user.getLoginname());
|
||||
transaction.setUserName(user.getUsername());
|
||||
transaction.setUnitName(user.getUnitname());
|
||||
transaction.setUnionName(user.getUnionname());
|
||||
// 获取订单金额
|
||||
int total = paramVo.getAmount().getTotal();
|
||||
BigDecimal bigDecimalValue = new BigDecimal(String.valueOf(total));
|
||||
BigDecimal resultTotal = bigDecimalValue.divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP);
|
||||
transaction.setTradingAmount(resultTotal);
|
||||
transaction.setIsRefund(false);
|
||||
transaction.setRefundAmount(null);
|
||||
transaction.setDescription(paramVo.getDescription());
|
||||
transaction.setAttach(paramVo.getAttach());
|
||||
transaction.setOpenId(null);
|
||||
transaction.setResultJson(result);
|
||||
sysUserService.dao().insert(transaction);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package io.v.nutz.zhgh.memberCost.payment.wxpay.vo;
|
||||
package io.v.nutz.base.payment.wxpay.vo;
|
||||
|
||||
import com.ijpay.wxpay.model.v3.Amount;
|
||||
import com.ijpay.wxpay.model.v3.Payer;
|
||||
@@ -0,0 +1,33 @@
|
||||
package io.v.nutz.base.utils;
|
||||
|
||||
import org.nutz.json.JsonFormat;
|
||||
import org.nutz.lang.Encoding;
|
||||
import org.nutz.mvc.view.UTF8JsonView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author wizzer@qq.com
|
||||
*/
|
||||
public class WebUtil {
|
||||
|
||||
public static String AjaxEncode = Encoding.UTF8;
|
||||
|
||||
public static boolean isAjax(HttpServletRequest req) {
|
||||
String value = req.getHeader("X-Requested-With");
|
||||
return value != null && "XMLHttpRequest".equalsIgnoreCase(value.trim());
|
||||
}
|
||||
|
||||
public static void rendAjaxResp(HttpServletRequest req, HttpServletResponse resp, Object re) {
|
||||
try {
|
||||
if (AjaxEncode != null) {
|
||||
resp.setCharacterEncoding(AjaxEncode);
|
||||
}
|
||||
(new UTF8JsonView(JsonFormat.compact())).render(req, resp, re);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.v.nutz.web.commons.proc;
|
||||
|
||||
import io.v.nutz.base.exception.BaseException;
|
||||
import io.v.nutz.base.result.Result;
|
||||
import io.v.nutz.base.utils.WebUtil;
|
||||
import org.nutz.integration.shiro.NutShiro;
|
||||
import org.nutz.ioc.IocException;
|
||||
import org.nutz.log.Log;
|
||||
@@ -27,13 +29,24 @@ public class WkFailProcessor extends ViewProcessor {
|
||||
String uri = Mvcs.getRequestPath(ac.getRequest());
|
||||
log.warn(String.format("Error@%s :", uri), ac.getError());
|
||||
}
|
||||
if (ac.getError() instanceof IocException) {
|
||||
Throwable e = ac.getError();
|
||||
if (e instanceof IocException) {
|
||||
if (NutShiro.isAjax(ac.getRequest())) {
|
||||
NutShiro.rendAjaxResp(ac.getRequest(), ac.getResponse(), Result.error(Mvcs.getMessage(ac.getRequest(), "system.exception")));
|
||||
} else {
|
||||
ac.getRequest().setAttribute("original_request_uri",ac.getRequest().getRequestURI());
|
||||
new ForwardView(errorUri).render(ac.getRequest(), ac.getResponse(), Mvcs.getMessage(ac.getRequest(), "system.exception"));
|
||||
}
|
||||
} else if (e instanceof BaseException) {
|
||||
if (WebUtil.isAjax(ac.getRequest())) {
|
||||
// WebUtil.rendAjaxResp(ac.getRequest(), ac.getResponse(), Result.error(ResultCode.FAILURE.getCode(), !log.isDebugEnabled() ? ResultCode.FAILURE.getMsg() : e.getMessage()));
|
||||
WebUtil.rendAjaxResp(ac.getRequest(), ac.getResponse(), Result.error(400, e.getMessage()));
|
||||
} else {
|
||||
ac.getRequest().setAttribute("original_request_uri", ac.getRequest().getRequestURI());
|
||||
ac.getRequest().setAttribute("error_message", Mvcs.getMessage(ac.getRequest(), "业务异常"));
|
||||
// new ForwardView(errorUri).render(ac.getRequest(), ac.getResponse(), null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
super.process(ac);
|
||||
}
|
||||
|
||||
+17
-2
@@ -1,6 +1,9 @@
|
||||
package io.v.nutz.zhgh.memberCost.controller;
|
||||
|
||||
import io.v.nutz.zhgh.memberCost.payment.wxpay.service.WxPayCommonService;
|
||||
import com.ijpay.wxpay.model.v3.Amount;
|
||||
import io.v.nutz.base.annontation.RepeatSubmit;
|
||||
import io.v.nutz.base.payment.wxpay.service.WxPayCommonService;
|
||||
import io.v.nutz.base.payment.wxpay.vo.WxPayNeedParamVo;
|
||||
import io.v.nutz.zhgh.memberCost.service.MemberPaymentService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
@@ -29,12 +32,24 @@ public class MemberPaymentMineController {
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/membercost/mine/index.html")
|
||||
@RequiresPermissions("member.payment.project")
|
||||
@RequiresPermissions("member.payment.mine")
|
||||
public void index() {
|
||||
}
|
||||
|
||||
|
||||
@At
|
||||
public Object pageData(){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@At
|
||||
@RepeatSubmit
|
||||
public Object pcOrderPay(){
|
||||
WxPayNeedParamVo paramVo = new WxPayNeedParamVo();
|
||||
paramVo.setDescription("会费缴纳支付");
|
||||
paramVo.setAttach("");
|
||||
paramVo.setAmount(new Amount().setTotal(1));
|
||||
return wxPayCommonService.nativePay(paramVo);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user