1 Star 1 Fork 14

tomas/电商平台-支付

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
OrderPayController 6.75 KB
一键复制 编辑 原始数据 按行查看 历史
小半斤拔凉 提交于 2017-06-16 17:11 . 支付接口
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;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/redArmy/dianshangpingtai-zhifu.git
[email protected]:redArmy/dianshangpingtai-zhifu.git
redArmy
dianshangpingtai-zhifu
电商平台-支付
master

搜索帮助