|
@@ -1,331 +0,0 @@
|
|
|
-package com.miniframe.bisiness.system;
|
|
|
-
|
|
|
-import com.google.gson.Gson;
|
|
|
-import com.miniframe.service.mq.XIMQPayTimeoutQueue;
|
|
|
-import com.miniframe.spring.mq.MFMqUtils;
|
|
|
-import com.miniframe.core.ExecProcessFlow;
|
|
|
-import com.miniframe.core.exception.BusinessException;
|
|
|
-import com.miniframe.core.ext.UtilTools;
|
|
|
-import com.miniframe.generate.appcode.OrderStatus;
|
|
|
-import com.miniframe.generate.appcode.PayType;
|
|
|
-import com.miniframe.generate.appcode.Paystatus;
|
|
|
-import com.miniframe.generate.business.system.model.IEF001BaseModel;
|
|
|
-import com.miniframe.generate.business.pay.model.XP1001BaseModel;
|
|
|
-import com.miniframe.generate.comm.httppayapater.XP1001Client;
|
|
|
-import com.miniframe.generate.comm.pay.A_PAYHEAD;
|
|
|
-import com.miniframe.generate.comm.pay.A_XP1001;
|
|
|
-import com.miniframe.generate.comm.pay.D_XP1001;
|
|
|
-import com.miniframe.model.system.GeneralSet;
|
|
|
-import com.miniframe.model.system.Orders;
|
|
|
-import com.miniframe.model.system.Pay;
|
|
|
-import com.miniframe.model.system.SysUser;
|
|
|
-import com.miniframe.model.system.dao.GeneralSetMapper;
|
|
|
-import com.miniframe.model.system.dao.OrdersMapper;
|
|
|
-import com.miniframe.model.system.dao.PayMapper;
|
|
|
-import com.miniframe.model.system.dao.SysUserMapper;
|
|
|
-import com.miniframe.tools.XIDateTimeUtils;
|
|
|
-import org.json.JSONObject;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-/**
|
|
|
- * 基础系统,“支付下单”逻辑处理(重新生成不覆盖)。
|
|
|
- */
|
|
|
-public class IEF001Service extends IEF001BaseModel implements ExecProcessFlow {
|
|
|
-
|
|
|
- private static final long serialVersionUID = -7051358269847459502L;
|
|
|
- private static final Logger logger = LoggerFactory.getLogger(IEF001Service.class);
|
|
|
-
|
|
|
- /**
|
|
|
- * 基础系统,“支付下单”业务核心处理
|
|
|
- */
|
|
|
- public void transExecute() throws Exception {
|
|
|
-
|
|
|
- String payType = this.getA_ief001().getPayType();
|
|
|
- String payDesc = this.getA_ief001().getPayDesc();
|
|
|
- String orderId = this.getA_ief001().getOrderId();
|
|
|
-
|
|
|
- PayMapper payMapper = UtilTools.getBean(PayMapper.class);
|
|
|
- OrdersMapper ordersMapper = UtilTools.getBean(OrdersMapper.class);
|
|
|
- Orders orderInfo = ordersMapper.selectByPrimaryKey(orderId);
|
|
|
- if (orderInfo == null) {
|
|
|
- throw new BusinessException("EB2100008");
|
|
|
- }
|
|
|
-
|
|
|
- if (!orderInfo.getStatus().equals(OrderStatus.apply.getIndex())) {
|
|
|
- throw new BusinessException("EB2100009");
|
|
|
- }
|
|
|
-
|
|
|
- if (UtilTools.isNotNullAndBlank(orderInfo.getPayId())) {
|
|
|
- Pay payForOrder = payMapper.selectByPrimaryKey(orderInfo.getId());
|
|
|
- //只要不是支付成功的都可以再对该单申请支付
|
|
|
- if (payForOrder != null && payForOrder.getStatus().equals(Paystatus.paysuccess.getIndex())) {
|
|
|
- throw new BusinessException("EB2100009");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- String allAmount = orderInfo.getTotalAmount();
|
|
|
- allAmount = "0.01";//测试用
|
|
|
-
|
|
|
- Float allAmountYuan = Float.parseFloat(allAmount); //数值
|
|
|
-
|
|
|
- XP1001BaseModel model = new XP1001BaseModel();
|
|
|
- XP1001Client client = new XP1001Client();
|
|
|
- // 报文头
|
|
|
- A_PAYHEAD head = new A_PAYHEAD();
|
|
|
- head.setChannelNo("xipayment");
|
|
|
- head.setTransCode("XP1001");
|
|
|
- head.setClientToken(getA_systemhead().getClientToken());
|
|
|
- model.setA_payhead(head);
|
|
|
- // 报文体
|
|
|
- A_XP1001 a_xp1001 = new A_XP1001();
|
|
|
- a_xp1001.setUserId(getA_systemhead().getUserId());
|
|
|
- SysUserMapper userInfoMapper = UtilTools.getBean(SysUserMapper.class);
|
|
|
- SysUser userInfo = userInfoMapper.selectByPrimaryKey(getA_systemhead().getUserId());
|
|
|
- a_xp1001.setMobileNumber(userInfo.getUsermobnub());
|
|
|
-
|
|
|
- a_xp1001.setPackageName("com.xitech.xingben");
|
|
|
-
|
|
|
-
|
|
|
- // 拼接json参数
|
|
|
- String payTypeName = PayType.getPayType(payType).getName();
|
|
|
- String notify_url = "";
|
|
|
- try {
|
|
|
- if (payTypeName.contains(PayType.alipay.getName())) {
|
|
|
- GeneralSet generalSet = UtilTools.getBean(GeneralSetMapper.class).selectByPrimaryKey("pay_alipay_notify_url");
|
|
|
- if (generalSet != null) {
|
|
|
- notify_url = generalSet.getParamValue();
|
|
|
- }
|
|
|
-
|
|
|
- } else if (payTypeName.contains(PayType.wechatpay.getName())) {
|
|
|
- GeneralSet generalSet = UtilTools.getBean(GeneralSetMapper.class).selectByPrimaryKey("pay_wechat_notify_url");
|
|
|
- if (generalSet != null) {
|
|
|
- notify_url = generalSet.getParamValue();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("notify_url", notify_url);
|
|
|
- if (payType.equals(PayType.wechatpayProgram.getIndex())) {// 1: 微信小程序支付
|
|
|
-// jsonObject.put("openid", userInfo.getOpenId());
|
|
|
- a_xp1001.setServerChannel("02");
|
|
|
- jsonObject.put("total_fee", allAmountYuan * 100);
|
|
|
- jsonObject.put("body", payDesc);
|
|
|
- jsonObject.put("attach", orderId);
|
|
|
- jsonObject.put("trade_type", "JSAPI");
|
|
|
- jsonObject.put("attach", PayType.getPayType(payType).getName());
|
|
|
- } else if (payType.equals(PayType.wechatpayApp.getIndex())) {// 微信APP支付
|
|
|
- a_xp1001.setServerChannel("02");
|
|
|
- jsonObject.put("total_fee", allAmountYuan * 100);
|
|
|
- jsonObject.put("body", payDesc);
|
|
|
- jsonObject.put("attach", orderId);
|
|
|
- jsonObject.put("trade_type", "APP");
|
|
|
- jsonObject.put("attach", PayType.getPayType(payType).getName());
|
|
|
-
|
|
|
- } else if (payType.equals(PayType.wechatpay.getIndex())) {// 微信扫码支付
|
|
|
- a_xp1001.setServerChannel("02");
|
|
|
- jsonObject.put("total_fee", allAmountYuan * 100);
|
|
|
- jsonObject.put("body", payDesc);
|
|
|
- jsonObject.put("product_id", orderId);
|
|
|
- jsonObject.put("trade_type", "NATIVE");
|
|
|
- jsonObject.put("attach", PayType.getPayType(payType).getName());
|
|
|
- } else if (payType.equals(PayType.alipay.getIndex())) {// 支付宝扫码支付
|
|
|
-
|
|
|
- a_xp1001.setServerChannel("03");
|
|
|
-
|
|
|
- jsonObject.put("totalAmount", allAmount);
|
|
|
- jsonObject.put("subject", payDesc);
|
|
|
- jsonObject.put("body", orderId);
|
|
|
- jsonObject.put("trade_type", "QR_CODE");//输入QR_CODE 为二维码扫码支付,否则是本地app支付
|
|
|
-
|
|
|
- } else if (payType.equals(PayType.alipayApp.getIndex())) {// 支付宝APP支付
|
|
|
- a_xp1001.setServerChannel("03");
|
|
|
- jsonObject.put("totalAmount", allAmount);
|
|
|
- jsonObject.put("subject", payDesc);
|
|
|
- jsonObject.put("body", orderId);
|
|
|
- jsonObject.put("trade_type", "APP");
|
|
|
- } else {
|
|
|
- throw new BusinessException("EB2100000");
|
|
|
- }
|
|
|
-
|
|
|
- a_xp1001.setJsonString(jsonObject.toString());
|
|
|
- model.setA_xp1001(a_xp1001);
|
|
|
- // 发送请求
|
|
|
- model = client.execute(model);
|
|
|
- D_XP1001 d_xp1001 = model.getD_xp1001();
|
|
|
-
|
|
|
-
|
|
|
- /**=BEGIN============== 下行返回并插入记录 =============== 所有金额打折数据都用数据库查询模式**/
|
|
|
- Pay pay = new Pay();
|
|
|
- pay.setId(UtilTools.getUUid());
|
|
|
- pay.setCat(payType);
|
|
|
- pay.setAmount(allAmountYuan);
|
|
|
-
|
|
|
- pay.setCreateTime(XIDateTimeUtils.getNowDate());
|
|
|
- pay.setUpdateTime(pay.getCreateTime());
|
|
|
- pay.setUid(getA_systemhead().getUserId());
|
|
|
- pay.setOrderId(orderInfo.getId());
|
|
|
-
|
|
|
- String platFormOrderNo = "";
|
|
|
- try {
|
|
|
- platFormOrderNo = new JSONObject(d_xp1001.getJsonString()).getString("out_trade_no");
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error("", e);
|
|
|
- }
|
|
|
-
|
|
|
- pay.setPlatformOrderNo(platFormOrderNo);
|
|
|
-
|
|
|
-
|
|
|
- // 下行赋值
|
|
|
-
|
|
|
- if (UtilTools.isNullOrBlank(platFormOrderNo) || !d_xp1001.getReturn_code().equals("SUCCESS")) {// 失败
|
|
|
- pay.setStatus(Paystatus.orderfail.getIndex());
|
|
|
- payMapper.insertSelective(pay);
|
|
|
- throw new BusinessException("EB2100005");
|
|
|
- } else {
|
|
|
- pay.setStatus(Paystatus.ordersuccess.getIndex());
|
|
|
- payMapper.insertSelective(pay);
|
|
|
-
|
|
|
- orderInfo.setPayId(pay.getId());
|
|
|
- ordersMapper.updateByPrimaryKeySelective(orderInfo);
|
|
|
-
|
|
|
- String payInfo = new JSONObject(d_xp1001.getJsonString()).getString("payinfo");
|
|
|
- getD_ief001().setPayInfo(payInfo);
|
|
|
- getD_ief001().setPayType(payType);
|
|
|
- getD_ief001().setOrderNo(platFormOrderNo);
|
|
|
-
|
|
|
-
|
|
|
- if (payTypeName.contains(PayType.alipay.getName())) {
|
|
|
-
|
|
|
- if (payTypeName.equals(PayType.alipay.getName())) { //只有扫码支付才解析二维码
|
|
|
- Gson gson = new Gson();
|
|
|
- try {
|
|
|
- AlipayPayInfoBean payBean = gson.fromJson(payInfo, AlipayPayInfoBean.class);
|
|
|
- if (null != payBean) {
|
|
|
- this.getD_ief001().setQrUrl(payBean.getAlipay_trade_precreate_response().getQr_code());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } else if (payTypeName.contains(PayType.wechatpay.getName())) {
|
|
|
- this.getD_ief001().setQrUrl(payInfo);
|
|
|
- }
|
|
|
-
|
|
|
- //设置支付超时
|
|
|
- {
|
|
|
- Map<String, String> opDataMap = new HashMap<>();
|
|
|
- opDataMap.put("opIndex", "");
|
|
|
- opDataMap.put("opType", "pay");
|
|
|
- opDataMap.put("opData", pay.getId());
|
|
|
- opDataMap.put("opTime", XIDateTimeUtils.getNowStr());
|
|
|
- if (!MFMqUtils.get(XIMQPayTimeoutQueue.class).sendPayData(UtilTools.obj2Json(opDataMap))) {
|
|
|
- throw new BusinessException("EB8000105");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- /**=END================ 下行返回并插入记录 ===============**/
|
|
|
- }
|
|
|
-
|
|
|
- public class AlipayPayInfoBean {
|
|
|
-
|
|
|
- private Alipay_trade_precreate_response alipay_trade_precreate_response;
|
|
|
- private String sign;
|
|
|
-
|
|
|
- public void setAlipay_trade_precreate_response(Alipay_trade_precreate_response alipay_trade_precreate_response) {
|
|
|
- this.alipay_trade_precreate_response = alipay_trade_precreate_response;
|
|
|
- }
|
|
|
-
|
|
|
- public Alipay_trade_precreate_response getAlipay_trade_precreate_response() {
|
|
|
- return alipay_trade_precreate_response;
|
|
|
- }
|
|
|
-
|
|
|
- public void setSign(String sign) {
|
|
|
- this.sign = sign;
|
|
|
- }
|
|
|
-
|
|
|
- public String getSign() {
|
|
|
- return sign;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public class Alipay_trade_precreate_response {
|
|
|
-
|
|
|
- private String code;
|
|
|
- private String msg;
|
|
|
- private String out_trade_no;
|
|
|
- private String qr_code;
|
|
|
-
|
|
|
- public void setCode(String code) {
|
|
|
- this.code = code;
|
|
|
- }
|
|
|
-
|
|
|
- public String getCode() {
|
|
|
- return code;
|
|
|
- }
|
|
|
-
|
|
|
- public void setMsg(String msg) {
|
|
|
- this.msg = msg;
|
|
|
- }
|
|
|
-
|
|
|
- public String getMsg() {
|
|
|
- return msg;
|
|
|
- }
|
|
|
-
|
|
|
- public void setOut_trade_no(String out_trade_no) {
|
|
|
- this.out_trade_no = out_trade_no;
|
|
|
- }
|
|
|
-
|
|
|
- public String getOut_trade_no() {
|
|
|
- return out_trade_no;
|
|
|
- }
|
|
|
-
|
|
|
- public void setQr_code(String qr_code) {
|
|
|
- this.qr_code = qr_code;
|
|
|
- }
|
|
|
-
|
|
|
- public String getQr_code() {
|
|
|
- return qr_code;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 基础系统,“支付下单”业务前处理
|
|
|
- */
|
|
|
- public void preTransFlow() throws Exception {
|
|
|
- this.validater();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 基础系统,“支付下单”业务后处理
|
|
|
- */
|
|
|
- public void afterTransFlow() throws Exception {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 基础系统,“支付下单”逻辑入口处理方法
|
|
|
- */
|
|
|
- @SuppressWarnings("rawtypes")
|
|
|
- @Override
|
|
|
- public Map execute(Map vars) throws Exception {
|
|
|
- this.setTransMap(vars);
|
|
|
- preTransFlow();// 执行业务开始的规则检查和校验
|
|
|
- transExecute();// 执行核心业务段
|
|
|
- afterTransFlow();// 执行核心逻辑完成后的收尾逻辑
|
|
|
- return this.getTransMap();
|
|
|
- }
|
|
|
-
|
|
|
-}
|