• 大小: 15KB
    文件类型: .7z
    金币: 1
    下载: 0 次
    发布日期: 2021-05-09
  • 语言: Java
  • 标签: 微信支付  

资源简介

该资源为java接入微信和支付宝支付的后端代码,参考blog:http://blog.csdn.net/lawsonjin/article/details/78732252

资源截图

代码片段和文件信息

package cn.xcdm.bag.controller;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jdom.JDOMException;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeAppPayModel;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import cn.xcdm.bag.common.SystemValue;
import cn.xcdm.bag.po.Orders;
import cn.xcdm.bag.service.CouponService;
import cn.xcdm.bag.service.OrdersService;
import cn.xcdm.bag.service.UserService;
import cn.xcdm.bag.util.GsonUtils;
import cn.xcdm.bag.util.ResponseUtils;
import cn.xcdm.bag.util.Result;
import cn.xcdm.bag.util.SnowflakeIdWorker;
import cn.xcdm.bag.wechatpay.ConstantUtil;
import cn.xcdm.bag.wechatpay.Md5Util;
import cn.xcdm.bag.wechatpay.PrepayIdRequestHandler;
import cn.xcdm.bag.wechatpay.WXUtil;
import cn.xcdm.bag.wechatpay.xmlUtil;

@Controller
@ResponseBody
@RequestMapping(value = “v1“)
public class PayController {
protected static final Log logger = LogFactory.getLog(PayController.class);
@Autowired
private OrdersService orderService;
@Autowired
private UserService userService;
@Autowired
private CouponService couponService;

/**
 * 支付通用接口
 * 
 * @param HowToPay
 * @param orderId
 * @param forWhat
 * @param payMoney
 * @param req
 * @return
 */
@RequestMapping(value = “/auth/pay/common“)
public String commonPay(@RequestParam(value = “HowToPay“ required = true) String HowToPay
@RequestParam(value = “orderId“ required = false) String orderId
@RequestParam(value = “forWhat“ required = true) String forWhat
@RequestParam(value = “payMoney“ required = false) String payMoney HttpServletRequest req
HttpServletResponse res) {
if (StringUtils.equals(“alipay“ HowToPay)) { // 支付宝 逻辑
Orders orders = new Orders();
Result result = new Result();
String oldPhone = (String) req.getAttribute(“oldPhone“);

if (StringUtils.equals(“bag“ forWhat)) { // 存包逻辑
orders = orderService.selectOrdersInfoByOrderId(orderId);
if (orders == null) {
result.setCode(400);
result.setMsg(“订单号不存在“);

评论

共有 条评论