|
@@ -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;
|
|
|
}
|
|
|
}
|