代码拉取完成,页面将自动刷新
同步操作将从 小半斤拔凉/电商平台-支付 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package com.uzengroup.jkd.portal.controller;
import java.util.Date;
import java.util.HashMap;
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.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.uzengroup.jkd.cache.portal.impl.ProductByIdCacheManager;
import com.uzengroup.jkd.core.Constants;
import com.uzengroup.jkd.core.Constants.PaymentType;
import com.uzengroup.jkd.core.model.OrderPaymentTypeRecord;
import com.uzengroup.jkd.core.model.WeChatAppConfig;
import com.uzengroup.jkd.core.service.OrderManager;
import com.uzengroup.jkd.core.service.OrderPaymentTypeRecordManager;
import com.uzengroup.jkd.core.util.DateUtil;
import com.uzengroup.jkd.core.util.StringUtil;
import com.uzengroup.jkd.portal.BaseController;
import com.uzengroup.jkd.portal.PortalConstants;
import com.uzengroup.jkd.portal.interceptor.LoginInterceptor;
import com.uzengroup.jkd.portal.util.AliPayUtil;
import com.uzengroup.jkd.portal.util.MatrixToImageWriterUtil;
import com.uzengroup.jkd.portal.util.RequestUtil;
import com.uzengroup.jkd.portal.util.WeiXinPayUtil;
@Controller
@RequestMapping("/api/pay/")
public class OrderPayController extends BaseController{
@Autowired
private OrderManager orderManager;
@Autowired
private ProductByIdCacheManager productByIdCacheManager;
@Autowired
OrderPaymentTypeRecordManager orderPaymentTypeRecordManager;
/**
* 订单支付支付
* @param request
* @return
*/
@LoginInterceptor(value=LoginInterceptor.LOGIN, contType=LoginInterceptor.CONT_JOSN_TYPE)
@RequestMapping(value="/orderPay")
public @ResponseBody Map<String, Object> orderPay(final HttpServletRequest request ,final HttpServletResponse response) {
Map<String, Object> resultMap = new HashMap<String, Object> ();
Long orderId = StringUtil.nullToLong(request.getParameter("orderId"));
String payType = StringUtil.null2Str(request.getParameter("payType"));
response.setHeader("Access-Control-Allow-Origin", "*");
try{
String body = "订单支付";
String outTradeNo = "";
String clientIp = RequestUtil.getClientIp(request);
// 是否微信请求
boolean isWebRequest = RequestUtil.isWeixin(request);
Integer paymentType = 0;
Long weChatConfigId = null;
if(StringUtil.compareObject(payType, "weixin")){
// 微信支付
int orderTotal = 0;
String notifyURL = RequestUtil.getRequestURL(request) + "/api/order/wxpayNotify.msp";
String openId = StringUtil.null2Str(request.getSession().getAttribute(PortalConstants.SESSION_CURRENT_OPEN_ID));
Map<String, String> orderPayInfoMap = new HashMap<String, String>();
WeChatAppConfig weChatAppConfig = null;
if(isWebRequest){
//微页面-微信公众号支付
weChatAppConfig = Constants.WECHAT_APP_CONFIG_MAP.get(StringUtil.null2Str("test"));
orderPayInfoMap = WeiXinPayUtil.getWeixinH5PayInfo(weChatAppConfig, outTradeNo, openId, notifyURL, orderTotal, body, clientIp);
if(orderPayInfoMap != null && !StringUtil.isNull(orderPayInfoMap.get("code_url"))){
//跨号支付
String codeUrl = StringUtil.null2Str(orderPayInfoMap.get("code_url"));
if(StringUtil.isNull(codeUrl)){
resultMap.put(PortalConstants.CODE, PortalConstants.CODE_ERROR);
resultMap.put(PortalConstants.MSG, "支付失败");
resultMap.put(PortalConstants.SYSTEMTIME, DateUtil.getCurrentTime());
return resultMap;
}
//生成二维码图片,并返回地址
String filePath = MatrixToImageWriterUtil.saveMatrixImage(codeUrl);
if(StringUtil.isNull(filePath)){
resultMap.put(PortalConstants.CODE, PortalConstants.CODE_ERROR);
resultMap.put(PortalConstants.MSG, "支付失败");
resultMap.put(PortalConstants.SYSTEMTIME, DateUtil.getCurrentTime());
return resultMap;
}
String requestURL = RequestUtil.getRequestURL(request);
filePath = requestURL + filePath;
Map<String, String> paramMap = new HashMap<String, String>();
paramMap.put("imagePath", filePath);
paramMap.put("isOther", "1"); //是否跨号支付
resultMap.put("orderPayInfo", paramMap);
resultMap.put(PortalConstants.CODE, PortalConstants.CODE_SUCCESS);
resultMap.put(PortalConstants.MSG, "拉取支付信息成功");
resultMap.put(PortalConstants.SYSTEMTIME, DateUtil.getCurrentTime());
return resultMap;
}else{
orderPayInfoMap.put("isOther", "0"); //是否跨号支付
}
}else{
weChatAppConfig = Constants.WECHAT_APP_CONFIG_MAP.get(StringUtil.null2Str("app_client"));
orderPayInfoMap = WeiXinPayUtil.getWeixinAppPayInfo(weChatAppConfig, outTradeNo, openId, notifyURL, orderTotal, body, clientIp);
}
resultMap.put("orderPayInfo", orderPayInfoMap);
paymentType = PaymentType.PAYMENT_TYPE_WECHAT;
weChatConfigId = weChatAppConfig.getConfigId();
}else{
String orderTotal = "";
String notifyURL = RequestUtil.getRequestURL(request) + "/api/order/alipayNotify.msp";
String returnURL = RequestUtil.getRequestURL(request) + "/api/order/alipayNotify.msp";
if(isWebRequest){
//浏览器支付宝支付
String orderPayURL = RequestUtil.getRequestURL(request) + "/wap/pay.html?orderNo=" + outTradeNo;
resultMap.put("orderPayInfo", orderPayURL);
}else{
//客户端支付宝支付
String orderPayInfo = AliPayUtil.getAliPayAppInfo(AliPayUtil.ALI_PAY_CLT_APP_TYPE, outTradeNo, orderTotal, body, notifyURL, returnURL);
resultMap.put("orderPayInfo", orderPayInfo);
}
paymentType = PaymentType.PAYMENT_TYPE_ALIPAY;
}
//记录客户端调用支付方式
OrderPaymentTypeRecord record = new OrderPaymentTypeRecord();
record.setOrderId(orderId);
record.setPaymentType(paymentType);
record.setWeChatConfigId(weChatConfigId);
record.setCreateTime(new Date());
record.setUpdateTime(new Date());
record.setSyncNumber(0);
orderPaymentTypeRecordManager.save(record);
resultMap.put(PortalConstants.CODE, PortalConstants.CODE_SUCCESS);
resultMap.put(PortalConstants.MSG, "拉取支付信息成功");
resultMap.put(PortalConstants.SYSTEMTIME, DateUtil.getCurrentTime());
return resultMap;
}catch(Exception e){
e.printStackTrace();
}
resultMap.put(PortalConstants.CODE, PortalConstants.CODE_ERROR);
resultMap.put(PortalConstants.MSG, this.getText("获取支付失败"));
resultMap.put(PortalConstants.SYSTEMTIME, DateUtil.getCurrentTime());
return resultMap;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。