lyhzzz 2 năm trước cách đây
mục cha
commit
58e31752a4

+ 1 - 66
src/main/java/com/fdkankan/sale/controller/pay/OrderWechatPayController.java

@@ -52,77 +52,12 @@ public class OrderWechatPayController  extends BaseController {
     IRepairLogService repairLogService;
 
     @ResponseBody
-    @RequestMapping(value = "/wechatMobilePay", method = RequestMethod.POST)
+    @RequestMapping(value = "/wechatPay", method = RequestMethod.POST)
     public ResultData wechatMobilePay(@RequestBody WechatMobileParam param) throws Exception {
         return ResultData.ok(wechatPayService.wechatMobilePay(param, UrlUtils.getIpAddr(request)));
     }
 
 
-    @GetMapping(value = "/wechatPreJsPay")
-    @ResponseBody
-    public ResultData wechatPreJsPay(String repairId,String openId) throws Exception {
-        // 这个url链接地址和参数皆不能变
-        try {
-            if(StringUtils.isBlank(repairId)){
-                throw new com.fdkankan.sale.exception.BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
-            }
-            Repair repair = repairService.getById(repairId);
-            if(repair == null){
-                throw new com.fdkankan.sale.exception.BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
-            }
-            if(repair.getStatus() != 9 && repair.getStatus() != 4){
-                throw new com.fdkankan.sale.exception.BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
-            }
-            RepairPay repairPay = repairPayService.getByRepairId(repairId,1);
-            if(repairPay != null  ){
-                throw new BusinessException(ResultCode.ORDER_PAY_ERROR);
-            }
-            String orderSn = null;
-
-            BigDecimal amount = BigDecimal.ZERO;
-            String subject = null;
-            Integer orderType = null;
-            if(repair.getStatus() == 9){
-                amount = priceListService.getAmountByRepairId(repairId);
-                orderSn = "se_s"+ DateUtil.getDate(DateUtil.repairIdFmt);
-                subject = "维修订单";
-                orderType = 0;
-            }
-            if(repair.getStatus() == 3){
-                amount = priceListService.getRobAmountByRepairId(repairId);
-                orderSn = "se_c"+DateUtil.getDate(DateUtil.repairIdFmt);
-                subject = "取消维修订单";
-                orderType = 1;
-            }
-
-            repairPay = new RepairPay();
-            repairPay.setRepairId(repairId);
-            repairPay.setPayType(1);
-            repairPay.setOrderSn(orderSn);
-            repairPay.setPayAmount(amount);
-            repairPay.setOrderType(orderType);
-            repairPayService.save(repairPay);
-
-            amount =amount .multiply(new BigDecimal(100));
-            Map<String, String> resp = wechatPayService.wechatPay(orderSn,subject, subject+subject, amount, UrlUtils.getIpAddr(request), openId);
-            String timeStamp = String.valueOf(System.currentTimeMillis() / 1000);
-
-            WxPayBean wxPayBean = new WxPayBean();
-            wxPayBean.setAppId(resp.get("appid"));
-            wxPayBean.setTimeStamp(timeStamp);
-            wxPayBean.setNonceStr(resp.get("nonce_str"));
-            wxPayBean.setPrepayId(resp.get("prepay_id"));
-            wxPayBean.setPaySign(resp.get("paySign"));
-            return ResultData.ok(wxPayBean);
-
-        }catch (Exception e){
-            log.debug("获取access_token发生异常",e);
-        }
-
-        return ResultData.ok();
-    }
-
-
     @RequestMapping(value = "/wechatPay/notify", method = RequestMethod.POST)
     public void callback() {
         wechatPayService.callBack(request,response);

+ 10 - 3
src/main/java/com/fdkankan/sale/pay/wx/WechatPayService.java

@@ -14,6 +14,7 @@ import com.fdkankan.sale.service.IRepairLogService;
 import com.fdkankan.sale.service.IRepairPayService;
 import com.fdkankan.sale.service.IRepairService;
 import com.fdkankan.sale.util.DateUtil;
+import com.fdkankan.sale.util.UrlUtils;
 import com.fdkankan.sale.vo.request.WechatMobileParam;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -25,6 +26,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.BufferedOutputStream;
 import java.math.BigDecimal;
 import java.net.URLEncoder;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Random;
@@ -84,7 +86,10 @@ public class WechatPayService {
 
         BigDecimal totalFee = amount.multiply(new BigDecimal(100));
         String body = subject;
-        return this.wechatH5Pay(param.getRepairId(),orderSn, subject, body, totalFee, ip);
+        if(param.getWxPayType() == 0){
+            return this.wechatH5Pay(param.getRepairId(),orderSn, subject, body, totalFee, ip);
+        }
+        return this.wechatPay(orderSn,subject, subject+subject, amount, ip, param.getOpenId());
     }
 
     public JSONObject wechatH5Pay(String repairId,String orderSn, String subject, String body, BigDecimal totalFee, String ipAddress) throws Exception {
@@ -105,7 +110,7 @@ public class WechatPayService {
 
         String mweb_url = "";
         Map<String, String> resp = WXPay.unifiedOrder(data);
-        log.info("微信支付{}",resp);
+        log.warn("wechatPay" + resp);
         String return_code = resp.get("return_code");
         String return_msg = resp.get("return_msg");
         if ("SUCCESS".equals(return_code) && "OK".equals(return_msg)) {
@@ -139,16 +144,18 @@ public class WechatPayService {
         Map<String, String> resp = WXPay.unifiedOrder(data);
         log.warn("wechatPay" + resp);
 
+        String timeStamp = String.valueOf(System.currentTimeMillis() / 1000);
         Map<String, String> sign = new HashMap<>();
         sign.put("package", "prepay_id="+resp.get("prepay_id"));
         sign.put("appId", WXPayDefaultConfig.appId);
-        sign.put("timeStamp",String.valueOf(System.currentTimeMillis() / 1000));
+        sign.put("timeStamp",timeStamp);
         sign.put("nonceStr", resp.get("nonce_str"));
         sign.put("signType", "MD5");
         String paySign = WXPayUtil.generateSignature(sign, WXPayDefaultConfig.key);
 
         resp.put("signType", "MD5");
         resp.put("paySign", paySign);
+        resp.put("timeStamp",timeStamp);
         log.warn("wechatPay" + resp);
         return resp;
     }

+ 2 - 0
src/main/java/com/fdkankan/sale/vo/request/WechatMobileParam.java

@@ -6,4 +6,6 @@ import lombok.Data;
 public class WechatMobileParam {
     private String repairId;
     private String orderSn;
+    private Integer wxPayType; // 0 微信h5支付,1微信JSAPI
+    private String openId;
 }