|
@@ -0,0 +1,759 @@
|
|
|
+package com.comtika.ctkcloud.server.service.comtika.impl;
|
|
|
+
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.DataInputStream;
|
|
|
+import java.io.DataOutputStream;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.comtika.ctkcloud.common.bean.chargeserver.ChargeReqData;
|
|
|
+import com.comtika.ctkcloud.common.bean.order.RechargeOrder;
|
|
|
+import com.comtika.ctkcloud.common.enums.chargerserver.ChargerPayModle;
|
|
|
+import com.comtika.ctkcloud.common.enums.mybank.MyBankRefundType;
|
|
|
+import com.comtika.ctkcloud.common.enums.pay.OrderStatusEnum;
|
|
|
+import com.comtika.ctkcloud.common.result.RespCode;
|
|
|
+import com.comtika.ctkcloud.common.result.RespWrapper;
|
|
|
+import com.comtika.ctkcloud.common.util.IDUtil;
|
|
|
+import com.comtika.ctkcloud.common.util.StringUtil;
|
|
|
+import com.comtika.ctkcloud.server.base.UnifyPayModel;
|
|
|
+import com.comtika.ctkcloud.server.core.ComtikaHttpsUtil;
|
|
|
+import com.comtika.ctkcloud.server.dao.comtika.SysComtikaMerchantDao;
|
|
|
+import com.comtika.ctkcloud.server.dao.pay.PrePayDao;
|
|
|
+import com.comtika.ctkcloud.server.dao.refund.RefundDao;
|
|
|
+import com.comtika.ctkcloud.server.dao.sepAccount.ReceiveDao;
|
|
|
+import com.comtika.ctkcloud.server.entity.DaFeng;
|
|
|
+import com.comtika.ctkcloud.server.entity.MybankPay;
|
|
|
+import com.comtika.ctkcloud.server.entity.comtikawechat.ComtikaRegisterMerchant;
|
|
|
+import com.comtika.ctkcloud.server.entity.comtikawechat.SysComtikaMerchant;
|
|
|
+import com.comtika.ctkcloud.server.entity.mybank.CtkRefund;
|
|
|
+import com.comtika.ctkcloud.server.entity.order.CtkRechargeOrder;
|
|
|
+import com.comtika.ctkcloud.server.entity.sepAccount.CtkReceiveUser;
|
|
|
+import com.comtika.ctkcloud.server.fegin.CustomerService;
|
|
|
+import com.comtika.ctkcloud.server.fegin.OrderNoFeignService;
|
|
|
+import com.comtika.ctkcloud.server.fegin.ServerFeignService;
|
|
|
+import com.comtika.ctkcloud.server.service.comtika.ComtikaMerchantService;
|
|
|
+import com.comtika.ctkcloud.server.util.dafeng.Base64Utils;
|
|
|
+import com.comtika.ctkcloud.server.util.dafeng.RSAUtils;
|
|
|
+import com.comtika.ctkcloud.server.util.http.HTTPUtils;
|
|
|
+@Service
|
|
|
+public class ComtikaMerchantServiceImpl implements ComtikaMerchantService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysComtikaMerchantDao sysComtikaMerchantDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PrePayDao prePayDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ServerFeignService serverFeignService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderNoFeignService orderNoFeignService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CustomerService customerService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RefundDao refundDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ReceiveDao receiveDao;
|
|
|
+
|
|
|
+ //public static String host = "http://127.0.0.1:8888";
|
|
|
+ public static String host = "https://www.comtikaiot.cn/wechatpay";
|
|
|
+
|
|
|
+ public static String weChatRegisterMerchant = "/merchant/weChatRegisterMerchant";
|
|
|
+
|
|
|
+ public static String queryWeChatRegisterMerchant = "/merchant/queryWeChatRegisterbyBusinessCode";
|
|
|
+
|
|
|
+ public static String unifiedOrder = "/wxpay/jsapi/unifiedOrder";
|
|
|
+
|
|
|
+ public static String wxRefund = "/wxpay/jsapi/refund";
|
|
|
+
|
|
|
+ public static String queryRefund = "/wxpay/jsapi/queryRefundByOutOrderNo";
|
|
|
+
|
|
|
+ public static String upload = "/photo/weChatUpload";
|
|
|
+
|
|
|
+ public static String notifyUrl = "https://www.comtikaiot.cn/api/zuul/mybank/comtika/notify";
|
|
|
+
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ @Override
|
|
|
+ public RespWrapper<Object> weChatRegisterMerchant(
|
|
|
+ ComtikaRegisterMerchant comtikaRegisterMerchant) {
|
|
|
+ try {
|
|
|
+ // 参数验证
|
|
|
+ RespWrapper<Object> data = comtikaRegisterMerchant
|
|
|
+ .parameterValidation();
|
|
|
+ if (RespCode.SUCCESS != data.getCode()) {
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+ // 给经营场景赋值
|
|
|
+ comtikaRegisterMerchant.updateSalesScenesType();
|
|
|
+ //赋值支付回调地址
|
|
|
+ comtikaRegisterMerchant.setNotifyUrl(notifyUrl);
|
|
|
+ // 获取请求头
|
|
|
+ Map<String, String> map = requestHeader();
|
|
|
+ String body = JSONObject.toJSONString(comtikaRegisterMerchant);
|
|
|
+ // 调用商户入驻
|
|
|
+ // String httpData =
|
|
|
+ // "{\"code\":0,\"msg\":\"\",\"data\":{\"businessCode\":\"Comtika_454B512D2EDC4F0596D1223CACD99DF51587975799\"},\"success\":true}";
|
|
|
+ String httpData = HTTPUtils.post(host + weChatRegisterMerchant,map, body);
|
|
|
+ RespWrapper<Object> respWrapper = JSONObject.parseObject(httpData,RespWrapper.class);
|
|
|
+ if (RespCode.SUCCESS != respWrapper.getCode()) {
|
|
|
+ return respWrapper;
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(respWrapper.getData().toString());
|
|
|
+ String businessCode = String.valueOf(jsonObject.get("businessCode"));
|
|
|
+ SysComtikaMerchant sysComtikaMerchant = new SysComtikaMerchant();
|
|
|
+ // 给数据库实体对象赋值
|
|
|
+ comtikaRegisterMerchant.updateMerchant(sysComtikaMerchant,businessCode);
|
|
|
+ sysComtikaMerchantDao.insert(sysComtikaMerchant);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return RespWrapper.makeErrorResp("服务器错误");
|
|
|
+ }
|
|
|
+ return RespWrapper.makeSuccessResp("商户入驻成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ @Override
|
|
|
+ public RespWrapper<Object> queryWeChatRegisterMerchant(String businessCode) {
|
|
|
+ try {
|
|
|
+ if (StringUtil.isEmpty(businessCode)) {
|
|
|
+ return RespWrapper.makeFailResp("请求参数有误,请检查!");
|
|
|
+ }
|
|
|
+ SysComtikaMerchant sysComtikaMerchant = new SysComtikaMerchant();
|
|
|
+ sysComtikaMerchant.setBusinessCode(businessCode);
|
|
|
+ sysComtikaMerchant = sysComtikaMerchantDao.templateOne(sysComtikaMerchant);
|
|
|
+ if (null == sysComtikaMerchant) {
|
|
|
+ return RespWrapper.makeFailResp("申请单号不存在,请检查!");
|
|
|
+ }
|
|
|
+ if (sysComtikaMerchant.getRegisterStatus() == 2) {
|
|
|
+ String msg = "已经入驻成功!";
|
|
|
+ Integer registerStatus = sysComtikaMerchant.getRegisterStatus();
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
+ map.put("msg", msg);
|
|
|
+ map.put("registerStatus", registerStatus);
|
|
|
+ return RespWrapper.makeSuccessResp(map);
|
|
|
+ }
|
|
|
+ // 获取请求头
|
|
|
+ Map<String, String> map = requestHeader();
|
|
|
+ // 将businessCode生成json数据
|
|
|
+ Map<String, String> json = new HashMap<String, String>();
|
|
|
+ json.put("businessCode", businessCode);
|
|
|
+ String body = JSONObject.toJSONString(json);
|
|
|
+ System.out.println(body);
|
|
|
+ // 请求服务商平台
|
|
|
+ String httpData = HTTPUtils.post(host + queryWeChatRegisterMerchant, map, body);
|
|
|
+ RespWrapper<Object> respWrapper = JSONObject.parseObject(httpData,RespWrapper.class);
|
|
|
+ if (RespCode.SUCCESS != respWrapper.getCode()) {
|
|
|
+ return respWrapper;
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(respWrapper.getData().toString());
|
|
|
+ String subMchid = jsonObject.getString("subMchid");
|
|
|
+ Integer registerStatus = jsonObject.getInteger("registerStatus");
|
|
|
+ String registerMessage = jsonObject.getString("registerMessage");
|
|
|
+ sysComtikaMerchant.setSubMchId(subMchid);
|
|
|
+ sysComtikaMerchant.setRegisterStatus(registerStatus);
|
|
|
+ sysComtikaMerchant.setRegisterMessage(registerMessage);
|
|
|
+ sysComtikaMerchantDao.updateTemplateById(sysComtikaMerchant);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return RespWrapper.makeErrorResp("服务器错误!");
|
|
|
+ }
|
|
|
+ return RespWrapper.makeSuccessResp("");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RespWrapper<Object> jsapiUnifiedOrder(MybankPay mybankPay,
|
|
|
+ String ip, Long userId) {
|
|
|
+ try {
|
|
|
+ String openId = null;
|
|
|
+ // 获取支付类型
|
|
|
+ UnifyPayModel payModel = UnifyPayModel
|
|
|
+ .valueOf(UnifyPayModel.ONLINE_PAY.getId());
|
|
|
+ String profitSharing = "Y";// 由于是在线支付,默认都是分账的
|
|
|
+ Long startTime = System.currentTimeMillis();
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
+ map.put("streamNo", mybankPay.getStreamNo());
|
|
|
+ map = sysComtikaMerchantDao.queryComtikaMerchant(map);
|
|
|
+ Integer registerStatus = Integer.parseInt(map.get("registerStatus")
|
|
|
+ + "");
|
|
|
+ if (registerStatus == null || registerStatus != 2) {
|
|
|
+ return RespWrapper.makeErrorResp("商户未入住,请联系商户!");
|
|
|
+ }
|
|
|
+ CtkRechargeOrder order = new CtkRechargeOrder();
|
|
|
+ order.setGoodsName("充电" + mybankPay.getTotalFee() * 1.0 / 100 + "元");
|
|
|
+ // 在线充电需要关联至商户
|
|
|
+ order.setMerchantId(Long
|
|
|
+ .parseLong(map.get("merchantId").toString()));
|
|
|
+ // 2分中支付时间 过期时间
|
|
|
+ order.setInvalidTime(startTime + 2 * 1000 * 60);
|
|
|
+ order.setCreateTime(startTime);
|
|
|
+ order.setCustomerId(userId);
|
|
|
+ String merchantNo = map.get("subMchid").toString();
|
|
|
+ // 生成充值订单
|
|
|
+ addRechargeOrder(userId, mybankPay, payModel, order);
|
|
|
+ ChargeReqData chargeReqData = new ChargeReqData();
|
|
|
+ // 生成充电订单
|
|
|
+ addChargeReqData(chargeReqData, mybankPay, order);
|
|
|
+ chargeReqData.setRechargeNo(order.getId());
|
|
|
+ chargeReqData.setUserId(userId);
|
|
|
+ System.out.println("参数内容:" + chargeReqData.toString());
|
|
|
+ RespWrapper<String> startCharge = serverFeignService
|
|
|
+ .startCharge(chargeReqData);
|
|
|
+ if (!startCharge.isSuccess())
|
|
|
+ return RespWrapper.makeFailResp(startCharge.getMsg());
|
|
|
+ // 获取支付人 openId
|
|
|
+ RespWrapper<Map<String, Object>> customer = customerService
|
|
|
+ .queryCustomerById(userId);
|
|
|
+ if (!customer.isSuccess())
|
|
|
+ return RespWrapper.makeFailResp(customer.getMsg());
|
|
|
+ openId = customer.getData().get("openId").toString();
|
|
|
+ RespWrapper<Object> orderData = null;
|
|
|
+ try {
|
|
|
+ orderData = toPaymentApply(openId, ip, mybankPay.getTotalFee(),
|
|
|
+ profitSharing, order.getOrderId(),
|
|
|
+ order.getGoodsName(), merchantNo);
|
|
|
+ if (!orderData.isSuccess())
|
|
|
+ return RespWrapper.makeFailResp(orderData.getMsg());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return RespWrapper.makeErrorResp("调用微信支付失败,请联系管理员!");
|
|
|
+ }
|
|
|
+ return RespWrapper.makeSuccessResp(orderData.getData());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return RespWrapper.makeErrorResp("服务器错误,请重试!");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ private RespWrapper<Object> toPaymentApply(String openId, String ip,
|
|
|
+ Long totalFee, String profitSharing, String orderId,
|
|
|
+ String goodsName, String merchantNo) throws Exception {
|
|
|
+ Map<String, Object> condition = new HashMap<>(7);
|
|
|
+ condition.put("profitSharing", profitSharing);
|
|
|
+ condition.put("subOpenid", openId);
|
|
|
+ condition.put("totalFee", totalFee);
|
|
|
+ condition.put("outOrderNo", orderId);
|
|
|
+ condition.put("body", goodsName);
|
|
|
+ condition.put("spbillCreateIp", ip);
|
|
|
+ condition.put("subMchid", merchantNo);
|
|
|
+ String url = host + unifiedOrder;
|
|
|
+ String httpData = ComtikaHttpsUtil.doPost(url,
|
|
|
+ JSONObject.toJSONString(condition));
|
|
|
+ RespWrapper<Object> data = JSONObject.parseObject(httpData,
|
|
|
+ RespWrapper.class);
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addChargeReqData(ChargeReqData chargeReqData,
|
|
|
+ MybankPay mybankPay, CtkRechargeOrder order) {
|
|
|
+ chargeReqData.setStreamNo(mybankPay.getStreamNo());
|
|
|
+ chargeReqData.setChargerMode(mybankPay.getChargerMode());
|
|
|
+ chargeReqData.setChargerValue(mybankPay.getChargerValue());
|
|
|
+ chargeReqData.setTotalFee(mybankPay.getTotalFee());
|
|
|
+ chargeReqData.setFormId(mybankPay.getFormId());
|
|
|
+ ChargerPayModle payType = mybankPay.getPayType() == 1 ? ChargerPayModle.WX_ONLINE
|
|
|
+ : ChargerPayModle.ALI_ONLIEN;
|
|
|
+ chargeReqData.setPayType(payType.getId());
|
|
|
+ Integer overdue = (int) (order.getInvalidTime() / 60 / 1000);
|
|
|
+ chargeReqData.setOverdue(overdue);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增充值订单
|
|
|
+ *
|
|
|
+ * @param userId
|
|
|
+ * @param mybankPay
|
|
|
+ * @param payModel
|
|
|
+ * @param order
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public void addRechargeOrder(Long userId, MybankPay mybankPay,
|
|
|
+ UnifyPayModel payModel, CtkRechargeOrder order) {
|
|
|
+ // 生成对应订单编号
|
|
|
+ String orderNo = IDUtil.prePayID(mybankPay.getPayType(),
|
|
|
+ payModel.getModeName());
|
|
|
+ // 支付状态
|
|
|
+ order.setStatus(OrderStatusEnum.UN_PAY.getId());
|
|
|
+ // 订单金额
|
|
|
+ order.setGoodsId(mybankPay.getTotalFee());
|
|
|
+ // 订单编号
|
|
|
+ order.setOrderId(orderNo);
|
|
|
+ // 充值模式 在线、余额、智能卡
|
|
|
+ order.setPayModel(payModel.getId());
|
|
|
+ // 支付类型
|
|
|
+ order.setPayType(mybankPay.getPayType());
|
|
|
+ order.setRemark(payModel.getBoby());
|
|
|
+ order.setTotalFee(mybankPay.getTotalFee());
|
|
|
+ // 设置支付渠道,1-网商,2-大风,3-康体佳服务商平台
|
|
|
+ order.setChannelType(3);
|
|
|
+ // 大风发起支付,那么先把订单设置成未确认分账
|
|
|
+ order.setDaFengStatus(0);
|
|
|
+ // order.setCustomerId(userId);
|
|
|
+ // 获取当前充值订单表的id,如果是在线充电,需要把充值订单表的id传递给充电订单服务模块
|
|
|
+ prePayDao.insertTemplate(order, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Map<String, String> requestHeader() {
|
|
|
+ Map<String, String> map = new HashMap<String, String>();
|
|
|
+ map.put("Charsert", "UTF-8");
|
|
|
+ map.put("connection", "Keep-Alive");
|
|
|
+ map.put("Content-Type", "application/json");
|
|
|
+ map.put("Accept", "application/json");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ /*
|
|
|
+ * ComtikaRegisterMerchant comtikaRegisterMerchant = new
|
|
|
+ * ComtikaRegisterMerchant(); comtikaRegisterMerchant.setMerchantId(1L);
|
|
|
+ * comtikaRegisterMerchant.setContactName("1");
|
|
|
+ * comtikaRegisterMerchant.setContactIdNumber("1");
|
|
|
+ * comtikaRegisterMerchant.setContactPhone("1");
|
|
|
+ * comtikaRegisterMerchant.setContactEmail("1");
|
|
|
+ * comtikaRegisterMerchant.setSubjectType("1");
|
|
|
+ * comtikaRegisterMerchant.setSubjectLicenseMediaID("1");
|
|
|
+ * comtikaRegisterMerchant.setSubjectLicenseUrl("1");
|
|
|
+ * comtikaRegisterMerchant.setLicenseNumber("1");
|
|
|
+ * comtikaRegisterMerchant.setMerchantName("1");
|
|
|
+ * comtikaRegisterMerchant.setLegalPerson("1");
|
|
|
+ * comtikaRegisterMerchant.setIdDocType("1");
|
|
|
+ * comtikaRegisterMerchant.setIdCardCopyMediaID("1");
|
|
|
+ * comtikaRegisterMerchant.setIdCardCopyUrl("1");
|
|
|
+ * comtikaRegisterMerchant.setIdCardNationalMediaID("1");
|
|
|
+ * comtikaRegisterMerchant.setIdCardNationalUrl("1");
|
|
|
+ * comtikaRegisterMerchant.setIdCardName("1");
|
|
|
+ * comtikaRegisterMerchant.setIdCardNumber("1");
|
|
|
+ * comtikaRegisterMerchant.setCardPeriodBegin("1");
|
|
|
+ * comtikaRegisterMerchant.setCardPeriodEnd("1");
|
|
|
+ * comtikaRegisterMerchant.setMerchantAbbr("1");
|
|
|
+ * comtikaRegisterMerchant.setServicePhone("1");
|
|
|
+ * comtikaRegisterMerchant.setSalesType("SALES_SCENES_MINI_PROGRAM");
|
|
|
+ * comtikaRegisterMerchant.setMiniProgramSubAppid("1"); List<String> str
|
|
|
+ * = new ArrayList<String>(); str.add("1");
|
|
|
+ * comtikaRegisterMerchant.setMiniProgramPicsMediaID(str);
|
|
|
+ * comtikaRegisterMerchant.setMiniProgramPicsUrl(str);
|
|
|
+ * comtikaRegisterMerchant.setSettlementId("1");
|
|
|
+ * comtikaRegisterMerchant.setQualificationType("1");
|
|
|
+ * comtikaRegisterMerchant
|
|
|
+ * .setBankAccountType("BANK_ACCOUNT_TYPE_CORPORATE");
|
|
|
+ * comtikaRegisterMerchant.setAccountName("1");
|
|
|
+ * comtikaRegisterMerchant.setAccountBank("1");
|
|
|
+ * comtikaRegisterMerchant.setBankAddressCode("1");
|
|
|
+ * comtikaRegisterMerchant.setBankBranchId("1");
|
|
|
+ * comtikaRegisterMerchant.setBankName("1");
|
|
|
+ * comtikaRegisterMerchant.setAccountNumber("1");
|
|
|
+ * comtikaRegisterMerchant.setNotifyUrl("1"); ComtikaMerchantServiceImpl
|
|
|
+ * a = new ComtikaMerchantServiceImpl(); System.out.println(new Date());
|
|
|
+ * System
|
|
|
+ * .out.println(a.weChatRegisterMerchant(comtikaRegisterMerchant));
|
|
|
+ * System.out.println(new Date());
|
|
|
+ */
|
|
|
+
|
|
|
+ ComtikaMerchantServiceImpl a = new ComtikaMerchantServiceImpl();
|
|
|
+ a.queryWeChatRegisterMerchant("111");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void notify(HttpServletResponse response, HttpServletRequest request) {
|
|
|
+ try {
|
|
|
+ String transactionId = request.getParameter("transactionId");
|
|
|
+ String subMchid = request.getParameter("subMchid");
|
|
|
+ String outTradeNo = request.getParameter("outTradeNo");
|
|
|
+ String payTime = request.getParameter("payTime");
|
|
|
+ /** 根据订单编号到数据库查询唯一订单信息 **/
|
|
|
+ RespWrapper<RechargeOrder> data = orderNoFeignService
|
|
|
+ .queryUniqOrderByOrderId(outTradeNo);
|
|
|
+ Integer payModel = null;
|
|
|
+ Boolean flag = false;
|
|
|
+ if (data.isSuccess()) {
|
|
|
+ /** 判断该订单是什么类型,0-在线充电,1-余额充值,2-智能卡充值 **/
|
|
|
+ // 只做在线充电的
|
|
|
+ payModel = data.getData().getPayModel();
|
|
|
+ if (payModel == 0) {
|
|
|
+ RespWrapper<Object> object = orderNoFeignService
|
|
|
+ .myBankNotifyOrder(outTradeNo, data.getData()
|
|
|
+ .getTotalfee(), transactionId);
|
|
|
+ flag = object.isSuccess();
|
|
|
+ }
|
|
|
+ if (flag) {
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
+ map.put("respCode", "0000");
|
|
|
+ map.put("respMsg", "回调成功!");
|
|
|
+ map.put("code", "SUCCESS");
|
|
|
+ String json = JSONObject.toJSONString(map);
|
|
|
+ response.setContentType("application/json;charset=UTF-8");
|
|
|
+ response.getWriter().write(json);
|
|
|
+ }
|
|
|
+ if (payModel != null && payModel == 0 && flag) {
|
|
|
+ /**
|
|
|
+ * 此部分为在线充电,调用下发充电接口.因为开启充电时间比较长。所以先返回给网商,再下发充电..不管开启失败,
|
|
|
+ * 失败会在订单服务退款
|
|
|
+ **/
|
|
|
+ System.out.println("id的参数为:" + data.getData().getId());
|
|
|
+ RespWrapper<Boolean> bl = serverFeignService
|
|
|
+ .onlinePayStartCharger(data.getData().getId());
|
|
|
+ System.out.println(bl.getMsg());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RespWrapper<Object> comtikaPrePay(MybankPay mybankPay, Long userId,
|
|
|
+ String ip) {
|
|
|
+ try {
|
|
|
+ if (mybankPay == null)
|
|
|
+ return RespWrapper.makeFailResp("入参不能为空");
|
|
|
+ if (mybankPay.getTotalFee() < 0)
|
|
|
+ return RespWrapper.makeFailResp("支付金额不能小于最小值");
|
|
|
+ System.out.println("入参:" + mybankPay.toString());
|
|
|
+ // String merchantNo = null;
|
|
|
+ // 查询康体佳的商户号
|
|
|
+ SysComtikaMerchant comtika = new SysComtikaMerchant();
|
|
|
+ comtika.setMerchantId(1L);
|
|
|
+ comtika.setRegisterStatus(2);
|
|
|
+ comtika = sysComtikaMerchantDao.templateOne(comtika);
|
|
|
+ if (comtika == null) {
|
|
|
+ return RespWrapper.makeFailResp("暂时不支持余额充值,请联系管理员!");
|
|
|
+ }
|
|
|
+ Long startTime = System.currentTimeMillis();
|
|
|
+ // 获取支付类型
|
|
|
+ UnifyPayModel payModel = UnifyPayModel.valueOf(mybankPay
|
|
|
+ .getPayModel());
|
|
|
+ CtkRechargeOrder order = new CtkRechargeOrder();
|
|
|
+ // 如果不是在线充电,订单关联到康体佳
|
|
|
+ order.setMerchantId(1L);
|
|
|
+ order.setCustomerId(userId);
|
|
|
+ order.setCreateTime(startTime);
|
|
|
+ // 30分中支付时间 过期时间
|
|
|
+ order.setInvalidTime(startTime + 30 * 1000 * 60);
|
|
|
+ order.setGoodsName("充值" + mybankPay.getTotalFee() * 1.0 / 100 + "元");
|
|
|
+ if (payModel == UnifyPayModel.CARD_PAY) {
|
|
|
+ /** 此部分为智能卡业务 **/
|
|
|
+ if (mybankPay.getId() != null
|
|
|
+ && userId.longValue() != mybankPay.getId()) {
|
|
|
+ order.setGoodsName("他人充值" + mybankPay.getTotalFee() * 1.0
|
|
|
+ / 100 + "元");
|
|
|
+ // 智能卡被充值人id
|
|
|
+ order.setCustomerId(mybankPay.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 获取支付人 openId
|
|
|
+ RespWrapper<Map<String, Object>> customer = customerService
|
|
|
+ .queryCustomerById(userId);
|
|
|
+ if (!customer.isSuccess())
|
|
|
+ return RespWrapper.makeFailResp(customer.getMsg());
|
|
|
+ // 生成订单
|
|
|
+ addRechargeOrder(userId, mybankPay, payModel, order);
|
|
|
+ String openId = customer.getData().get("openId").toString();
|
|
|
+ // 站点id默认1L
|
|
|
+ return toPaymentApply(openId, ip, mybankPay.getTotalFee(), "N",
|
|
|
+ order.getOrderId(), order.getGoodsName(),
|
|
|
+ comtika.getSubMchId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return RespWrapper.makeErrorResp("服务器错误!");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RespWrapper<Object> refundComtika(Long rechargeOrderId,
|
|
|
+ String payOrderId, Long refundAmount, Long merchantId,
|
|
|
+ Long customerId) {
|
|
|
+ try {
|
|
|
+ String refundFlowId = "comtika_tui_"+ System.currentTimeMillis();
|
|
|
+ // 生成退款表数据
|
|
|
+ CtkRefund ctkRefund = new CtkRefund();
|
|
|
+ ctkRefund.setOutRefundNo(refundFlowId);
|
|
|
+ ctkRefund.setMerchantId(merchantId);
|
|
|
+ ctkRefund.setRechargeOrderId(rechargeOrderId);
|
|
|
+ ctkRefund.setRefundFee(refundAmount);
|
|
|
+ ctkRefund.setCreateTime(System.currentTimeMillis());
|
|
|
+ ctkRefund.setChannelType(3);
|
|
|
+ ctkRefund.setCustomerId(customerId);
|
|
|
+ refundDao.insert(ctkRefund, true);
|
|
|
+
|
|
|
+ SysComtikaMerchant comtika = new SysComtikaMerchant();
|
|
|
+ comtika.setMerchantId(ctkRefund.getMerchantId());
|
|
|
+ comtika.setRegisterStatus(2);
|
|
|
+ comtika = sysComtikaMerchantDao.templateOne(comtika);
|
|
|
+ String refundDesc = "结束充电";
|
|
|
+ // 发起退款
|
|
|
+ RespWrapper<Object> result = refund(refundAmount,refundDesc,payOrderId,refundFlowId,comtika.getSubMchId());
|
|
|
+ JSONObject json = JSONObject.parseObject(result.getData().toString());
|
|
|
+ if (result.isSuccess()) {
|
|
|
+ ctkRefund.setStatus(MyBankRefundType.ACCEPTANCE.getId());
|
|
|
+ //康体佳服务商平台受理成功返回的单号
|
|
|
+ String refundOrderId = json.getString("refundId");
|
|
|
+ ctkRefund.setRefundOrderNo(refundOrderId);
|
|
|
+ ctkRefund.setRefundMsg("康体佳服务商平台受理成功");
|
|
|
+ refundDao.updateTemplateById(ctkRefund);
|
|
|
+ return RespWrapper.makeSuccessResp("发起退款成功!");
|
|
|
+ } else {
|
|
|
+ ctkRefund.setStatus(MyBankRefundType.FAIRLY.getId());// 康体佳服务商平台受理失败
|
|
|
+ if (json.get("respMsg") != null) {
|
|
|
+ ctkRefund.setRefundMsg(String.valueOf(json.get("respMsg")));
|
|
|
+ }
|
|
|
+ refundDao.updateTemplateById(ctkRefund);
|
|
|
+ return RespWrapper.makeFailResp("退款失败,失败原因:"+ ctkRefund.getRefundMsg());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ private RespWrapper<Object> refund(Long refundAmount, String refundDesc,
|
|
|
+ String payOrderId, String refundFlowId, String subMchId) throws Exception {
|
|
|
+ Map<String,Object> map = new HashMap<String, Object>();
|
|
|
+ map.put("refundFee", refundAmount);
|
|
|
+ map.put("refundDesc", refundDesc);
|
|
|
+ map.put("transactionId", payOrderId);
|
|
|
+ map.put("outRefundNo", refundFlowId);
|
|
|
+ map.put("subMchid", subMchId);
|
|
|
+ String str = ComtikaHttpsUtil.doPost(host + wxRefund, JSONObject.toJSONString(map));
|
|
|
+ RespWrapper<Object> data = JSONObject.parseObject(str,RespWrapper.class);
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 康体佳服务商平台订单确认发起分账
|
|
|
+ */
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ @Override
|
|
|
+ public RespWrapper<Object> comtikaOrderNotice(CtkRechargeOrder ctk) {
|
|
|
+ try {
|
|
|
+ Map<String,Object> map = new HashMap<String, Object>();
|
|
|
+ map.put("rechargeOrderId", ctk.getId());
|
|
|
+ //根据充值订单id到充电订单查询站点id和商户id
|
|
|
+ map = prePayDao.queryRechargeOrderSiteIdAndMerchantId(map);
|
|
|
+ Long merchantId = Long.parseLong(map.get("merchantId")+"");
|
|
|
+ SysComtikaMerchant sys= new SysComtikaMerchant();
|
|
|
+ sys.setMerchantId(merchantId);
|
|
|
+ //查询康体佳服务商平台商户号
|
|
|
+ sys = sysComtikaMerchantDao.templateOne(sys);
|
|
|
+ CtkReceiveUser ck = new CtkReceiveUser();
|
|
|
+ Integer siteId = Integer.parseInt(map.get("siteId")+"");
|
|
|
+ ck.setSiteId(siteId);
|
|
|
+ ck.setMerchantId(Integer.parseInt(merchantId+""));
|
|
|
+ ck = receiveDao.templateOne(ck);
|
|
|
+ map.clear();
|
|
|
+ map.put("subMchId", sys.getSubMchId());
|
|
|
+ map.put("transactionId", ctk.getPayTransactionId());
|
|
|
+ map.put("groupName", ck.getGroupName());
|
|
|
+ String str = ComtikaHttpsUtil.doPost(ctk.getPayTransactionId(), JSONObject.toJSONString(map));
|
|
|
+ RespWrapper<Object> data = JSONObject.parseObject(str, RespWrapper.class);
|
|
|
+ if(data.isSuccess()){
|
|
|
+ CtkRechargeOrder cro = new CtkRechargeOrder();
|
|
|
+ cro.setId(ctk.getId());
|
|
|
+ cro.setDaFengStatus(1);
|
|
|
+ //如果是分账成功,需要修改订单的状态
|
|
|
+ prePayDao.updateTemplateById(cro);
|
|
|
+ }
|
|
|
+ return RespWrapper.makeSuccessResp("分账成功!");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return RespWrapper.makeErrorResp("服务器错误!");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void comtikaOrderNotice() {
|
|
|
+ try {
|
|
|
+ //1.查找大风在线支付订单,支付成功,并且订单未确认的..
|
|
|
+ List<Map<String,Object>> list = prePayDao.queryComtikaOrder();
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
+ //充电预付金额
|
|
|
+ Long chargeMoney = map.get("chargeMoney") == null? 0L : Long.parseLong(String.valueOf(map.get("chargeMoney")));
|
|
|
+ //充电结算金额
|
|
|
+ Long totalFee = map.get("totalFee") == null? 0L : Long.parseLong(String.valueOf(map.get("totalFee")));
|
|
|
+ //充值订单id
|
|
|
+ Long rechargeNo = Long.parseLong(String.valueOf(map.get("rechargeNo")));
|
|
|
+
|
|
|
+
|
|
|
+ if( chargeMoney.equals(totalFee) ){
|
|
|
+ //如果两个金额相等,那么就是没有退款,就需要向康体佳服务商平台确认订单可以分账
|
|
|
+ CtkRechargeOrder ctk = new CtkRechargeOrder();
|
|
|
+ ctk.setId(rechargeNo);
|
|
|
+ ctk = prePayDao.templateOne(ctk);
|
|
|
+ comtikaOrderNotice(ctk);
|
|
|
+ }else{
|
|
|
+ //如果两个金额不相等,就去查询退款表,看是否退款成功
|
|
|
+ CtkRefund ctkRefund = new CtkRefund();
|
|
|
+ ctkRefund.setRechargeOrderId(rechargeNo);
|
|
|
+ ctkRefund.setStatus(1);
|
|
|
+ ctkRefund = refundDao.templateOne(ctkRefund);
|
|
|
+ if(ctkRefund != null){
|
|
|
+ //comtikaOrderNotice(rechargeNo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ @Override
|
|
|
+ public void queryComtikaRefund(Map<String, Object> map) {
|
|
|
+ try {
|
|
|
+ Integer status = Integer.parseInt(map.get("status").toString());
|
|
|
+ Long id = Long.parseLong(String.valueOf(map.get("id")));
|
|
|
+ Long merchantId = Long.parseLong(map.get("merchantId")+"");
|
|
|
+ Long rechargeOrderId = Long.parseLong(String.valueOf(map.get("rechargeOrderId")));
|
|
|
+ Long refundFee = Long.parseLong(String.valueOf(map.get("refundFee")));
|
|
|
+ CtkRefund ctkRefund = new CtkRefund();
|
|
|
+ ctkRefund.setId(id);
|
|
|
+ if(status == MyBankRefundType.ACCEPTANCE.getId() || status == MyBankRefundType.REFUNDING.getId()){
|
|
|
+ //退款中和受理成功,需要重新发起查询
|
|
|
+ String refundOrderNo = String.valueOf(map.get("refundOrderNo"));
|
|
|
+ if(StringUtil.isEmpty(refundOrderNo))return;
|
|
|
+ Map<String, Object> mapData = new HashMap<String, Object>();
|
|
|
+ mapData.put("refundId", refundOrderNo);
|
|
|
+ String url = host + queryRefund;
|
|
|
+ String str = ComtikaHttpsUtil.doPost(url, JSONObject.toJSONString(mapData));
|
|
|
+ RespWrapper<Object> data = JSONObject.parseObject(str,RespWrapper.class);
|
|
|
+ if(data.isSuccess()){
|
|
|
+ JSONObject json = JSONObject.parseObject(data.getData()+"");
|
|
|
+ Integer refundStatus = json.getInteger("refundStatus");
|
|
|
+ Long refundSuccessTime = null;
|
|
|
+ String refundMessage = json.getString("refundMessage");;
|
|
|
+ if(refundStatus == 1){ //退款成功
|
|
|
+ refundStatus = MyBankRefundType.SUCC.getId();
|
|
|
+ refundSuccessTime = json.getLong("refundSuccessTime");
|
|
|
+ }else if(refundStatus == 2){//退款处理中
|
|
|
+ refundStatus = MyBankRefundType.REFUNDING.getId();
|
|
|
+ }else if(refundStatus == 3 || refundStatus == 4){//退款失败
|
|
|
+ refundStatus = MyBankRefundType.FAIL.getId();
|
|
|
+ }
|
|
|
+ ctkRefund.setStatus(refundStatus);
|
|
|
+ ctkRefund.setGmtRefundment(refundSuccessTime);
|
|
|
+ ctkRefund.setRefundMsg(refundMessage);
|
|
|
+ refundDao.updateTemplateById(ctkRefund);
|
|
|
+ //退款成功后,发起分账
|
|
|
+ if(refundStatus == 1){
|
|
|
+ CtkRechargeOrder ctk = new CtkRechargeOrder();
|
|
|
+ ctk.setId(rechargeOrderId);
|
|
|
+ ctk = prePayDao.templateOne(ctk);
|
|
|
+ Map<String,Object> map1 = new HashMap<String, Object>();
|
|
|
+ map1.put("rechargeOrderId",rechargeOrderId);
|
|
|
+ //根据充值订单id到充电订单查询站点id和商户id
|
|
|
+ map1 = prePayDao.queryRechargeOrderSiteIdAndMerchantId(map1);
|
|
|
+ SysComtikaMerchant sys= new SysComtikaMerchant();
|
|
|
+ sys.setMerchantId(merchantId);
|
|
|
+ //查询康体佳服务商平台商户号
|
|
|
+ sys = sysComtikaMerchantDao.templateOne(sys);
|
|
|
+ CtkReceiveUser ck = new CtkReceiveUser();
|
|
|
+ Integer siteId = Integer.parseInt(map1.get("siteId")+"");
|
|
|
+ ck.setSiteId(siteId);
|
|
|
+ ck.setMerchantId(Integer.parseInt(merchantId+""));
|
|
|
+ ck = receiveDao.templateOne(ck);
|
|
|
+ map1.clear();
|
|
|
+ map1.put("subMchId", sys.getSubMchId());
|
|
|
+ map1.put("transactionId", ctk.getPayTransactionId());
|
|
|
+ map1.put("groupName", ck.getGroupName());
|
|
|
+ map1.put("amount", ctk.getTotalFee() - refundFee);//分账金额等于总金额减去退款金额
|
|
|
+ String str1 = ComtikaHttpsUtil.doPost(ctk.getPayTransactionId(), JSONObject.toJSONString(map));
|
|
|
+ RespWrapper<Object> data1 = JSONObject.parseObject(str1, RespWrapper.class);
|
|
|
+ if(data1.isSuccess()){
|
|
|
+ CtkRechargeOrder cro = new CtkRechargeOrder();
|
|
|
+ cro.setId(ctk.getId());
|
|
|
+ cro.setDaFengStatus(1);
|
|
|
+ //如果是分账成功,需要修改订单的状态
|
|
|
+ prePayDao.updateTemplateById(cro);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ CtkRechargeOrder cro = new CtkRechargeOrder();
|
|
|
+ cro.setId(rechargeOrderId);
|
|
|
+ cro = prePayDao.templateOne(cro);
|
|
|
+ String refundFlowId = "comtika_tui_"+ System.currentTimeMillis();
|
|
|
+ ctkRefund = refundDao.templateOne(ctkRefund);
|
|
|
+ SysComtikaMerchant comtika = new SysComtikaMerchant();
|
|
|
+ comtika.setMerchantId(ctkRefund.getMerchantId());
|
|
|
+ comtika.setRegisterStatus(2);
|
|
|
+ comtika = sysComtikaMerchantDao.templateOne(comtika);
|
|
|
+ String refundDesc = "结束充电";
|
|
|
+ // 发起退款
|
|
|
+ RespWrapper<Object> result = refund(ctkRefund.getRefundFee(),refundDesc,cro.getPayTransactionId(),refundFlowId,comtika.getSubMchId());
|
|
|
+ JSONObject json = JSONObject.parseObject(result.getData().toString());
|
|
|
+ if (result.isSuccess()) {
|
|
|
+ ctkRefund.setStatus(MyBankRefundType.ACCEPTANCE.getId());
|
|
|
+ //康体佳服务商平台受理成功返回的单号
|
|
|
+ String refundOrderId = json.getString("refundId");
|
|
|
+ ctkRefund.setRefundOrderNo(refundOrderId);
|
|
|
+ ctkRefund.setRefundMsg("康体佳服务商平台受理成功");
|
|
|
+ refundDao.updateTemplateById(ctkRefund);
|
|
|
+ } else {
|
|
|
+ ctkRefund.setStatus(MyBankRefundType.FAIRLY.getId());// 康体佳服务商平台受理失败
|
|
|
+ if (json.get("respMsg") != null) {
|
|
|
+ ctkRefund.setRefundMsg(String.valueOf(json.get("respMsg")));
|
|
|
+ }
|
|
|
+ refundDao.updateTemplateById(ctkRefund);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ @Override
|
|
|
+ public RespWrapper<Object> uploadPhoto(MultipartFile file) {
|
|
|
+ try {
|
|
|
+ String url = host + upload;
|
|
|
+ Map<String, Object> json = new HashMap<String, Object>();
|
|
|
+ //String result = ComtikaHttpsUtil.upload(url,file);
|
|
|
+ String result = ComtikaHttpsUtil.upload(url,file);
|
|
|
+ RespWrapper<Object> data = JSONObject.parseObject(result,RespWrapper.class);
|
|
|
+ return data;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return RespWrapper.makeErrorResp("服务器错误,请重试!");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RespWrapper<Object> queryMerchant(Long merchantId) {
|
|
|
+ try {
|
|
|
+ if( null == merchantId){}
|
|
|
+ SysComtikaMerchant sys = new SysComtikaMerchant();
|
|
|
+ sys.setMerchantId(merchantId);
|
|
|
+ sys = sysComtikaMerchantDao.templateOne(sys);
|
|
|
+ return RespWrapper.makeSuccessResp(sys);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return RespWrapper.makeErrorResp("服务器错误!");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|