huanglizhi 1 vuosi sitten
vanhempi
sitoutus
37954460b5

+ 28 - 11
module-erp/src/main/java/com/hys/app/controller/erp/use/PayController.java

@@ -2,11 +2,15 @@ package com.hys.app.controller.erp.use;
 
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
 import com.github.binarywang.wxpay.exception.WxPayException;
 import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
 import com.hys.app.framework.exception.ServiceException;
+import com.hys.app.framework.util.JsonUtil;
 import com.hys.app.framework.util.ScriptUtil;
 import com.hys.app.model.erp.dos.OrderCustomerFee;
 import com.hys.app.model.erp.dos.OrderDO;
@@ -31,6 +35,7 @@ import java.math.BigDecimal;
 import java.net.UnknownHostException;
 import java.time.LocalDateTime;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -118,25 +123,37 @@ public class PayController {
         return "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[解析失败]]></return_msg></xml>";
     }
 
-    @GetMapping("getOpenIdCode/{orderId}")
-    public String getOpenIdCode(@PathVariable Long orderId) throws UnsupportedEncodingException {
-        String openIdCode = wxPayServiceMy.getOpenIdCode(orderId);
-        System.out.println("授权地址+“--------------------------------------------------------"+openIdCode);
-        return wxPayServiceMy.getOpenIdCode(orderId);
+    @PostMapping("getOpenIdCode/{orderId}")
+    public String getOpenIdCode(@PathVariable Long orderId, @RequestBody @Validated Map map) throws UnsupportedEncodingException {
+        String openIdCode = wxPayServiceMy.getOpenIdCode(orderId,map.get("ip").toString());
+        System.out.println("授权地址+“--------------------------------------------------------"+openIdCode+"ip-----------------"+map.get("ip").toString());
+        return wxPayServiceMy.getOpenIdCode(orderId,map.get("ip").toString());
     }
 
     @GetMapping("/weixin/callback/openidCode")
-    public void handleWeixinCallback(@RequestParam("code") String code, @RequestParam("state") String state, HttpSession session) {
+    public String handleWeixinCallback(@RequestParam("code") String code, @RequestParam("state") String state, HttpSession session) {
 
+        Map<String, Object> map = JsonUtil.toMap(state);
         System.out.println("回调来了啊    code="+code+"111111111111111111111111111111111111111111111state="+state);
-        if (!state.equals((String) session.getAttribute("WEIXIN_OAUTH_STATE"))) {
-            log.error("用户授权,state错误");
-        }
-        OrderDO aDo = orderManager.getById(state);
+//        if (!state.equals((String) session.getAttribute("WEIXIN_OAUTH_STATE"))) {
+//            log.error("用户授权,state错误");
+//        }
+        OrderDO aDo = orderManager.getById(Long.valueOf(map.get("orderId").toString()));
         if (ObjectUtil.isNull(aDo)) {
             log.error("用户授权完成后未找到订单信息:" + state);
         }
-        aDo.setOpenId(wxPayServiceMy.getOpenId(code));
+        String openId = wxPayServiceMy.getOpenId(code);
+        aDo.setOpenId(openId);
         orderManager.updateById(aDo);
+
+        double price ;
+        List<OrderCustomerFee> list = orderCustomerFeeManager.list(new LambdaQueryWrapper<OrderCustomerFee>().eq(OrderCustomerFee::getOrderId, aDo.getId()));
+        if (CollectionUtil.isNotEmpty(list)) {
+             price = new BigDecimal(aDo.getRealPrice()).add(list.stream().map(OrderCustomerFee::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add)).multiply(new BigDecimal(1 + aDo.getTaxRate() * 0.01)).doubleValue();
+        } else {
+            price =aDo.getRealPrice() * (1 + aDo.getTaxRate() * 0.01);
+        }
+        System.out.println( "redirect:"+map.get("ip").toString()+"#/payType?id="+aDo.getId()+"&sn="+aDo.getSn()+"&price="+price);
+        return   "redirect:"+map.get("ip").toString()+"#/payType?id="+aDo.getId()+"&sn="+aDo.getSn()+"&price="+price+"&openid="+openId;
     }
 }

+ 0 - 2
module-erp/src/main/java/com/hys/app/model/erp/dto/PayTypeUrl.java

@@ -24,7 +24,5 @@ public class PayTypeUrl {
     @NotNull(message = "订单ID不能为空")
     private Long orderId;
 
-
-
 }
 

+ 5 - 2
module-erp/src/main/java/com/hys/app/pay/wx/WxPayServiceMy.java

@@ -88,10 +88,13 @@ public class WxPayServiceMy {
         }
     }
 
-    public String getOpenIdCode(Long orderId) throws UnsupportedEncodingException {
+    public String getOpenIdCode(Long orderId,String ip) throws UnsupportedEncodingException {
         String oAuth2Url = wxConfig.getOAuth2Url();
+        Map<String, Object> map = new HashMap<>();
+        map.put("orderId",orderId);
+        map.put("ip",ip);
         return String.format("https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect",
-                wxConfig.getAppId(), URLEncoder.encode(wxConfig.getOAuth2Url(), "UTF-8"), "snsapi_base", orderId);
+                wxConfig.getAppId(), URLEncoder.encode(wxConfig.getOAuth2Url(), "UTF-8"), "snsapi_base", JSONUtil.toJsonStr(map));
 
     }
 

+ 1 - 1
server/src/main/resources/application-local.yml

@@ -87,4 +87,4 @@ wxpay:
   notifyUrl: https://api.raycos.net/index.html
   subMchId: 1639506733
   secret: 13803c1b0d911e023c7da0b300cbce89
-  oAuth2Url: https://api.raycos.net/index.html
+  oAuth2Url: https://api.raycos.net/admin/erp/pay/weixin/callback/openidCode