| | |
| | | import com.alipay.api.response.AlipayTradeRefundResponse; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.jpay.ext.kit.PaymentKit; |
| | | import com.jpay.weixin.api.WxPayApi; |
| | | import com.ruoyi.common.core.constant.SecurityConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.enums.OrderStatusEnum; |
| | |
| | | import com.ruoyi.order.domain.Paylog; |
| | | import com.ruoyi.order.mapper.OrderMapper; |
| | | import com.ruoyi.order.mapper.PaylogMapper; |
| | | import com.ruoyi.order.service.IOrderService; |
| | | import com.ruoyi.order.service.IPaylogService; |
| | | import com.ruoyi.order.util.MD5AndKL; |
| | | import com.ruoyi.order.util.SinataUtil; |
| | | import com.ruoyi.order.util.alipay.config.AlipayConfig; |
| | | import com.ruoyi.order.util.alipay.util.PayDemoActivity; |
| | |
| | | import com.ruoyi.system.api.domain.dto.updMembeOneDTO; |
| | | import com.ruoyi.system.api.feignClient.AuctionClient; |
| | | import com.ruoyi.system.api.feignClient.MemberClient; |
| | | import com.ruoyi.system.api.feignClient.OrderClient; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.PrintWriter; |
| | | import java.math.BigDecimal; |
| | | import java.security.SignatureException; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Optional; |
| | | import java.util.Set; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.Assert; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | String body; |
| | | try { |
| | | if(judgeContainsStr(orderNO)){ |
| | | price= Double.valueOf(1); |
| | | LambdaQueryWrapper<Order> wrapper1= Wrappers.lambdaQuery(); |
| | | wrapper1.eq(Order::getOrderNo,orderNO); |
| | | wrapper1.eq(Order::getDelFlag,0); |
| | | Order page1 = OrderMapper.selectOne(wrapper1); |
| | | price=page1.getTotalAmount().doubleValue(); |
| | | body = " 订单支付"; |
| | | subject = " 订单支付"; |
| | | Map<String, Object> map = new HashMap<String, Object>(); |
| | |
| | | public static R<Map<String, Object>> wxpay(Integer apptype, String outTradeNo, String body,String openId, Double price, |
| | | HttpServletRequest request) { |
| | | // 获取预支付接口返回参数 |
| | | Map<String, Object> map = new HashMap<String, Object>(); |
| | | Map<String, Object> map1 = new HashMap<String, Object>(); |
| | | Map<String, Object> appPayMap = new HashMap<String, Object>(); |
| | | try { |
| | | // 构建接口请求参数 |
| | |
| | | System.out.println(result); |
| | | System.out.println("WxpayController.createOrder__result:\n" + result); |
| | | // 获取预支付接口返回参数 |
| | | map = XMLParser.getMapFromXML(result); |
| | | map1 = XMLParser.getMapFromXML(result); |
| | | System.out.println("WxpayController.createOrder__result:\n" + result); |
| | | // 捕获预支付接口错误提示 |
| | | if ("FAIL".equals(map.get("result_code")) || "FAIL".equals(map.get("return_code"))) { |
| | | return R.fail(String.valueOf(map.get("return_msg"))); |
| | | if ("FAIL".equals(map1.get("result_code")) || "FAIL".equals(map1.get("return_code"))) { |
| | | return R.fail(String.valueOf(map1.get("return_msg"))); |
| | | } |
| | | |
| | | // 对获取预支付返回接口参数进行封装(生成支付订单接口数据) |
| | | /* // 对获取预支付返回接口参数进行封装(生成支付订单接口数据) |
| | | AppPayReqData appPay = new AppPayReqData(apptype, (String) map.get("appid"), (String) map.get("mch_id"), |
| | | (String) map.get("prepay_id"), unifiedorderReqData.getNonce_str()); |
| | | (String) map.get("prepay_id"), unifiedorderReqData.getNonce_str());*/ |
| | | |
| | | HashMap<String, Object> map1 = new HashMap<>(); |
| | | map1.put("timeStamp", appPay.getTimestamp()); |
| | | map1.put("nonceStr", appPay.getNoncestr()); |
| | | map1.put("package", "prepay_id=" + appPay.getPrepayid()); |
| | | map1.put("signType", "RSA"); |
| | | map1.put("paySign", appPay.getSign()); |
| | | UUID uuid = UUID.randomUUID(); |
| | | String nonceStr = uuid.toString().replaceAll("-", ""); |
| | | //商品描述 String body = "XX商城-支付订单"; |
| | | // 创建hashmap(用户获得签名) |
| | | SortedMap<String, String> paraMap = new TreeMap<>(); |
| | | //设置请求参数(小程序ID) |
| | | paraMap.put("appid", unifiedorderReqData.getAppid()); |
| | | //设置请求参数(商户号) |
| | | paraMap.put("mch_id", unifiedorderReqData.getMch_id()); |
| | | //设置请求参数(随机字符串) |
| | | paraMap.put("nonce_str", nonceStr); |
| | | //设置请求参数(商品描述) |
| | | paraMap.put("body", unifiedorderReqData.getBody()); |
| | | //设置请求参数(商户订单号) |
| | | paraMap.put("out_trade_no", unifiedorderReqData.getOut_trade_no()); |
| | | //设置请求参数(总金额) |
| | | paraMap.put("total_fee", unifiedorderReqData.getTotal_fee().toString()); |
| | | //设置请求参数(通知地址) |
| | | paraMap.put("notify_url", unifiedorderReqData.getNotify_url()); |
| | | //设置请求参数(交易类型) |
| | | paraMap.put("trade_type", String.valueOf(WxPayApi.TradeType.JSAPI)); |
| | | |
| | | paraMap.put("openid", unifiedorderReqData.getOpenid()); |
| | | |
| | | //设置请求参数(openid)(在接口文档中 该参数 是否必填项 但是一定要注意 如果交易类型设置成'JSAPI'则必须传入openid) |
| | | //MD5运算生成签名,这里是第一次签名,用于调用统一下单接口 |
| | | String sign = PaymentKit.createSign(paraMap, "E10ADC3949BA59ABBE56E057F20F883E"); |
| | | paraMap.put("sign", sign); |
| | | //统一下单,向微信api发送数据 |
| | | //转成xml |
| | | String xmlResult = WxPayApi.pushOrder(false, paraMap); |
| | | Map<String, String> map = PaymentKit.xmlToMap(xmlResult); |
| | | //返回状态码 |
| | | String returnCode = map.get("return_code"); |
| | | /* Assert.isTrue("SUCCESS".equals(returnCode), getMsgByCode(returnCode));*/ |
| | | |
| | | //返回给小程序端需要的参数 |
| | | Map<String, Object> returnMap = new HashMap<>(20); |
| | | |
| | | String prepay_id = map.get("prepay_id"); |
| | | //重新进行签名后返回给前端 |
| | | returnMap.put("appId", map.get("appid")); |
| | | returnMap.put("nonceStr", map.get("nonce_str")); |
| | | returnMap.put("package", "prepay_id=" + prepay_id); |
| | | returnMap.put("timeStamp", new Date().getTime() + ""); |
| | | returnMap.put("signType", "MD5"); |
| | | String signature = weixinSignature(returnMap, "E10ADC3949BA59ABBE56E057F20F883E"); |
| | | |
| | | returnMap.put("prepay_id", prepay_id); |
| | | returnMap.put("mch_id", map.get("mch_id")); |
| | | returnMap.put("trade_type", map.get("trade_type")); |
| | | |
| | | returnMap.put("sign", signature); |
| | | returnMap.put("err_code_des", map.get("err_code_des")); |
| | | // 对获取预支付返回接口参数进行封装(生成支付订单接口数据) |
| | | return R.ok(map1); |
| | | return R.ok(returnMap); |
| | | } catch (Exception e) { |
| | | System.out.println("统一下单_API_处理异常!"); |
| | | e.printStackTrace(); |
| | |
| | | return R.fail("统一下单失败"); |
| | | } |
| | | |
| | | private static String weixinSignature(Map<String, Object> map, String privateKey) { |
| | | try { |
| | | Set<Map.Entry<String, Object>> entries = map.entrySet(); |
| | | List<Map.Entry<String, Object>> infoIds = new ArrayList<Map.Entry<String, Object>>(entries); |
| | | // 对所有传入参数按照字段名的 ASCII 码从小到大排序(字典序) |
| | | Collections.sort(infoIds, new Comparator<Map.Entry<String, Object>>() { |
| | | public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) { |
| | | return (o1.getKey()).toString().compareTo(o2.getKey()); |
| | | } |
| | | }); |
| | | // 构造签名键值对的格式 |
| | | StringBuilder sb = new StringBuilder(); |
| | | for (Map.Entry<String, Object> item : infoIds) { |
| | | if (item.getKey() != null || item.getKey() != "") { |
| | | String key = item.getKey(); |
| | | Object val = item.getValue(); |
| | | if (!(val == "" || val == null)) { |
| | | sb.append(key + "=" + val + "&"); |
| | | } |
| | | } |
| | | } |
| | | sb.append("key=" + privateKey); |
| | | String sign = MD5AndKL.MD5Encode(sb.toString(), "UTF-8").toUpperCase(); //注:MD5签名方式 |
| | | return sign; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |