anderx 4 éve%!(EXTRA string=óta)
szülő
commit
26fb182c3b
1 módosított fájl, 42 hozzáadás és 31 törlés
  1. 42 31
      src/main/java/com/kede/wxsdk/service/WxService.java

+ 42 - 31
src/main/java/com/kede/wxsdk/service/WxService.java

@@ -77,21 +77,12 @@ public class WxService {
 				    data.put("out_trade_no", orderNo); // 订单唯一编号, 不允许重复
 				    // 订单金额, 单位分
 				    String amout=p.getAmount().multiply(new BigDecimal(100)).stripTrailingZeros().toPlainString();
-				    data.put("total_fee", amout); 
-				    data.put("spbill_create_ip", ip); // 下单ip
 				    String openId=(String) TokenManager.getVal2Session("openId");
 //				    String openId="oGNT65WX5ysEnCUmAvaXOdIrMswA";
 				    if (StringUtils.isBlank(openId)) {
 				    	throw new BusinessException("无法获取正确的openId");
 					}
-				    data.put("openid", openId); // 微信公众号统一标示openid
-				    data.put("notify_url", notifyUrl); // 订单结果通知, 微信主动回调此接口
-				    data.put("trade_type", "JSAPI"); // 固定填写
-				    LoggerUtils.debug(getClass(), "发起微信支付下单接口, request=%s",data);
-				    Map<String, String> response = wxpay.unifiedOrder(data); // 微信sdk集成方法, 统一下单接口unifiedOrder, 此处请求   MD5加密   加密方式
-				    LoggerUtils.debug(getClass(),"微信支付下单成功, 返回值 response=%s", response);
 				    Order o=new Order();
-				    o.setCreateTime(new Date());
 				    o.setOrderNo(orderNo);
 				    o.setPayAmount(new BigDecimal(0));
 				    o.setPayStatus(0);
@@ -100,27 +91,46 @@ public class WxService {
 				    o.setProjectName(p.getName());
 				    o.setStatus(0);
 				    o.setUid(TokenManager.getUserId());
-				    String prepayId = response.get("prepay_id");
-				    if (prepayId == null) {
-				    	throw new BusinessException("无法获取正确的prepayId");
-				    }
-				    orderService.insert(o);
-				    //  前端调起微信支付必要参数
-				    String packages = "prepay_id=" + prepayId;
-				    Map<String, String> wxPayMap = new HashMap<String, String>();
-				    String uuid=UUID.randomUUID().toString().replace("-", "").toLowerCase();
-				    wxPayMap.put("appId", iWxPayConfig.getAppID());
-				    wxPayMap.put("timeStamp", String.valueOf(new Date().getTime()));
-				    wxPayMap.put("nonceStr", uuid);
-				    wxPayMap.put("package", packages);
-				    wxPayMap.put("signType", "MD5");
-				    // 加密串中包括 appId timeStamp nonceStr package signType 5个参数, 通过sdk WXPayUtil类加密
-				    String sign = WXPayUtil.generateSignature(wxPayMap, iWxPayConfig.getKey());
-				    //  返回给前端调起微信支付的必要参数
-				    map.put("prepay_id", prepayId);
-				    map.put("out_trade_no", orderNo);
-				    map.put("paySign", sign);
-				    map.putAll(wxPayMap);
+				    if (p.getAmount().compareTo(new BigDecimal(0.01))>=0) {
+				    	data.put("total_fee", amout); 
+					    data.put("spbill_create_ip", ip); // 下单ip
+					    data.put("openid", openId); // 微信公众号统一标示openid
+					    data.put("notify_url", notifyUrl); // 订单结果通知, 微信主动回调此接口
+					    data.put("trade_type", "JSAPI"); // 固定填写
+					    LoggerUtils.debug(getClass(), "发起微信支付下单接口, request=%s",data);
+					    Map<String, String> response = wxpay.unifiedOrder(data); // 微信sdk集成方法, 统一下单接口unifiedOrder, 此处请求   MD5加密   加密方式
+					    LoggerUtils.debug(getClass(),"微信支付下单成功, 返回值 response=%s", response);
+					    String prepayId = response.get("prepay_id");
+					    if (prepayId == null) {
+					    	throw new BusinessException("无法获取正确的prepayId");
+					    }
+					    orderService.insert(o);
+					    //  前端调起微信支付必要参数
+					    String packages = "prepay_id=" + prepayId;
+					    Map<String, String> wxPayMap = new HashMap<String, String>();
+					    String uuid=UUID.randomUUID().toString().replace("-", "").toLowerCase();
+					    wxPayMap.put("appId", iWxPayConfig.getAppID());
+					    wxPayMap.put("timeStamp", String.valueOf(new Date().getTime()));
+					    wxPayMap.put("nonceStr", uuid);
+					    wxPayMap.put("package", packages);
+					    wxPayMap.put("signType", "MD5");
+					    // 加密串中包括 appId timeStamp nonceStr package signType 5个参数, 通过sdk WXPayUtil类加密
+					    String sign = WXPayUtil.generateSignature(wxPayMap, iWxPayConfig.getKey());
+					    //  返回给前端调起微信支付的必要参数
+					    map.put("prepay_id", prepayId);
+					    map.put("out_trade_no", orderNo);
+					    map.put("paySign", sign);
+					    map.putAll(wxPayMap);
+					}else {
+						LoggerUtils.debug(getClass(),"订单下单成功, 返回值 amount=%s", p.getAmount());
+						o.setPayStatus(1);
+						orderService.insert(o);
+						map.put("out_trade_no", orderNo);
+						map.put("amount", "0");
+					}
+				   
+				    
+				  
 				} catch (Exception e) {
 					e.printStackTrace();
 					throw new BusinessException("支付异常");
@@ -186,7 +196,7 @@ public class WxService {
 					if (o.getPayStatus()!=1) {
 						Order on=new Order();
 						on.setOrderNo(o.getOrderNo());
-						on.setPayStatus(3);
+						on.setPayStatus(2);
 						orderMapper.updateByPrimaryKeySelective(on);
 					}
 				}catch (Exception e) {
@@ -243,6 +253,7 @@ public class WxService {
 				o.setOrderNo(out_trade_no);
 				o.setPayAmount(new BigDecimal(total_fee));
 				o.setWxOrderNo(transaction_id);
+				o.setPayStatus(1);
 				orderMapper.updateByPrimaryKeySelective(o);
 			}
 		}