ximon-admin/src/main/java/com/sandu/ximon/admin/controller/C3mOrderController.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,41 @@ package com.sandu.ximon.admin.controller; import com.sandu.common.domain.ResponseVO; import com.sandu.common.util.ResponseUtil; import com.sandu.ximon.admin.service.C3mOrderService; import lombok.AllArgsConstructor; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.Map; /** * @Author liuhaonan * @Date 2022/3/22 14:10 * @Version 1.0 */ @RestController @AllArgsConstructor @RequestMapping("/v1/c3mOrder") public class C3mOrderController { private final C3mOrderService c3mOrderService; /** * 鿬¾ * * @param params * @return */ @PostMapping("/refond") public ResponseVO<Object> refond(@RequestBody Map params) { // c3mOrderService.orderRefund( (String)params.get("outTradeNo"), // (Double)params.get("refundAmount")); return ResponseUtil.success(c3mOrderService.orderRefund((String) params.get("outTradeNo"), (Double) params.get("refundAmount"))); } } ximon-admin/src/main/java/com/sandu/ximon/admin/controller/UsrPayConfigController.java
@@ -8,7 +8,7 @@ import com.sandu.ximon.admin.param.AlipayConfigParam; import com.sandu.ximon.admin.param.WxpayConfigParam; import com.sandu.ximon.admin.pay.alipay.UsrAlipayConfigService; import com.sandu.ximon.admin.pay.alipay.UsrWxPayConfigService; import com.sandu.ximon.admin.pay.wxpay.UsrWxPayConfigService; import com.sandu.ximon.dao.domain.AliConfigEntity; import com.sandu.ximon.dao.domain.WxConfigEntity; import lombok.AllArgsConstructor; @@ -31,6 +31,7 @@ /** * æ¯ä»å®é 置添å * * @param configParam * @return */ @@ -41,17 +42,19 @@ /** * æ¯ä»å®é ç½®æ´æ¹ * * @param configId * @param configParam * @return */ @PostMapping("/updateAliPayConfig/{configId}") public ResponseVO<Object> updateAliPayConfig(@PathVariable Integer configId, @RequestBody AlipayConfigParam configParam) { return ResponseUtil.success(alipayConfigService.updateAliPayConfig(configId,configParam)); return ResponseUtil.success(alipayConfigService.updateAliPayConfig(configId, configParam)); } /** * æ¯ä»å®é ç½®å é¤ * * @param configId * @return */ @@ -61,7 +64,6 @@ } /** * * @param poleId * @return */ @@ -71,17 +73,18 @@ } /** *é 置详æ * é 置详æ * * @param configId * @return */ @GetMapping("/getAliPayConfigById/{configId}") public ResponseVO<Object> getAliPayConfigById(@PathVariable Integer configId) { if(configId==null){ if (configId == null) { throw new BusinessException("idè½ä¸ºç©º"); } AliConfigEntity byId = alipayConfigService.getById(configId); if(byId==null){ if (byId == null) { throw new BusinessException("é ç½®idé误æé ç½®ä¸åå¨"); } return ResponseUtil.success(byId); @@ -91,15 +94,13 @@ @GetMapping("/aliConfigList") public ResponseVO<Object> aliConfigList(BaseConditionVO baseConditionVO , @RequestParam(value = "keyword", required = false) String keyword) { return ResponseUtil.success(alipayConfigService.configList(baseConditionVO,keyword)); return ResponseUtil.success(alipayConfigService.configList(baseConditionVO, keyword)); } /** * wxé 置添å * * @param configParam * @return */ @@ -110,17 +111,19 @@ /** * wxé ç½®æ´æ¹ * * @param configId * @param configParam * @return */ @PostMapping("/updateWxPayConfig/{configId}") public ResponseVO<Object> updateAliPayConfig(@PathVariable Long configId, @RequestBody WxpayConfigParam configParam) { return ResponseUtil.success(wxPayConfigService.updateWxPayConfig(configId,configParam)); return ResponseUtil.success(wxPayConfigService.updateWxPayConfig(configId, configParam)); } /** * wxé ç½®å é¤ * * @param configId * @return */ @@ -130,7 +133,6 @@ } /** * * @param poleId * @return */ @@ -140,17 +142,18 @@ } /** *é 置详æ * é 置详æ * * @param configId * @return */ @GetMapping("/getWxPayConfigById/{configId}") public ResponseVO<Object> getWxPayConfigById(@PathVariable Integer configId) { if(configId==null){ if (configId == null) { throw new BusinessException("idè½ä¸ºç©º"); } WxConfigEntity byId = wxPayConfigService.getById(configId); if(byId==null){ if (byId == null) { throw new BusinessException("é ç½®idé误æé ç½®ä¸åå¨"); } return ResponseUtil.success(byId); @@ -161,13 +164,8 @@ public ResponseVO<Object> WxConfigList(BaseConditionVO baseConditionVO , @RequestParam(value = "keyword", required = false) String keyword) { PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); return ResponseUtil.success(wxPayConfigService.configList(baseConditionVO,keyword)); return ResponseUtil.success(wxPayConfigService.configList(baseConditionVO, keyword)); } } ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wx/WxFastPayService.java
ÎļþÃû´Ó sandu-common/src/main/java/com/sandu/common/third/pay/wx/WxFastPayService.java ÐÞ¸Ä @@ -1,4 +1,4 @@ package com.sandu.common.third.pay.wx; package com.sandu.ximon.admin.pay.wx; import cn.hutool.core.codec.Base64; import cn.hutool.crypto.SecureUtil; @@ -13,15 +13,15 @@ import com.github.binarywang.wxpay.service.WxPayService; import com.sandu.common.execption.BusinessException; import com.sandu.common.util.IpUtil; import com.sandu.common.util.ResponseUtil; import com.sandu.ximon.admin.pay.wxpay.UsrWxPayConfigService; import com.sandu.ximon.dao.domain.WxConfigEntity; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.Map; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.*; /** * @author chenjiantian @@ -32,6 +32,9 @@ @AllArgsConstructor public class WxFastPayService { private final com.github.binarywang.wxpay.service.WxPayService wxPayService; //private final WxPayProperties wxPayProperties; public static final String WECHAT_ORDER_PAY_CALLBACK_URL = "http://49.235.239.118:20012/callback/pay/wechatCallback"; /** * appæ¯ä» @@ -121,7 +124,7 @@ * @param callbackUrl * @return */ public boolean refundOrder(WxPayService wxPayService, String orderId,String refundSn, Integer refundFee, String callbackUrl) { public boolean refundOrder(WxPayService wxPayService, String orderId, String refundSn, Integer refundFee, String callbackUrl) { WxPayRefundRequest refundRequest = new WxPayRefundRequest(); refundRequest.setOutTradeNo(orderId); refundRequest.setOutRefundNo(refundSn); @@ -142,11 +145,12 @@ } } /** * çæäºç»´ç 仿¬¾ */ public String generateQRCodePay(WxPayService wxPayService, String body, String orderId, int totalFee, String callbackUrl) { String orderId, int totalFee, String callbackUrl) { WxPayUnifiedOrderRequest wxPayUnifiedOrderRequest = new WxPayUnifiedOrderRequest(); wxPayUnifiedOrderRequest.setBody(body); wxPayUnifiedOrderRequest.setOutTradeNo(orderId); @@ -173,4 +177,51 @@ throw new BusinessException("微信æ¯ä»å¤±è´¥ï¼" + e.getErrCodeDes()); } } /** * 鿬¾ * @param totalAmount * @param refundAmount * @param outTradeNo * @param poleId * @return */ public boolean refund(Double totalAmount, Double refundAmount, String outTradeNo, Long poleId) { WxConfigEntity wxConfig = UsrWxPayConfigService.getBean().getConfigByPoleId(poleId); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); String refundNo = sdf.format(new Date()); WxPayRefundRequest refundRequest = new WxPayRefundRequest(); refundRequest.setOutTradeNo(outTradeNo); refundRequest.setOutRefundNo(refundNo); refundRequest.setTotalFee(Integer.valueOf(parseWxAmount((totalAmount + "")))); refundRequest.setRefundFee(Integer.valueOf(parseWxAmount((refundAmount + "")))); try { WxPayRefundResult wxPayRefundResult = wxPayService.refund(refundRequest); if (WxPayConstants.ResultCode.SUCCESS.equals(wxPayRefundResult.getResultCode())) { return true; } else { log.error("å¾®ä¿¡éæ¬¾å¤±è´¥ï¼{}", wxPayRefundResult.getErrCodeDes()); throw new BusinessException("å¾®ä¿¡éæ¬¾å¤±è´¥ï¼" + wxPayRefundResult.getErrCodeDes()); } } catch (WxPayException e) { log.error("å¾®ä¿¡éæ¬¾å¤±è´¥ï¼{}", e.getErrCodeDes()); throw new BusinessException("å¾®ä¿¡éæ¬¾å¤±è´¥ï¼" + e.getErrCodeDes()); } } /** * 转æ¢ä¸ºå¾®ä¿¡éé¢(å) * * @param normalAmount 0.01å * @return */ public static String parseWxAmount(String normalAmount) { // ä¿ç2ä½å°æ° double totalAmountDouble = Double.parseDouble(new DecimalFormat("#.00").format( Double.parseDouble(normalAmount))); String amount = (totalAmountDouble * 100) + ""; amount = amount.substring(0, amount.indexOf(".")); return amount; } } ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wx/WxPayConfiguration.java
ÎļþÃû´Ó sandu-common/src/main/java/com/sandu/common/third/pay/wx/WxPayConfiguration.java ÐÞ¸Ä @@ -1,4 +1,4 @@ package com.sandu.common.third.pay.wx; package com.sandu.ximon.admin.pay.wx; import com.github.binarywang.wxpay.config.WxPayConfig; import com.github.binarywang.wxpay.service.WxPayService; ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wx/WxPayProperties.java
ÎļþÃû´Ó sandu-common/src/main/java/com/sandu/common/third/pay/wx/WxPayProperties.java ÐÞ¸Ä @@ -1,4 +1,4 @@ package com.sandu.common.third.pay.wx; package com.sandu.ximon.admin.pay.wx; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wxpay/UsrWxPayConfigService.java
ÎļþÃû´Ó ximon-admin/src/main/java/com/sandu/ximon/admin/pay/alipay/UsrWxPayConfigService.java ÐÞ¸Ä @@ -1,4 +1,4 @@ package com.sandu.ximon.admin.pay.alipay; package com.sandu.ximon.admin.pay.wxpay; import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ximon-admin/src/main/java/com/sandu/ximon/admin/service/C3mChargingChargeService.java
@@ -45,6 +45,11 @@ return true; } /** * æå ¥è´¹ç * @param c3 * @return */ public boolean initCharge(C3mChargingChargeParam c3) { C3mChargingCharge charge = new C3mChargingCharge(); BeanUtil.copyProperties(c3, charge); @@ -53,6 +58,10 @@ return save(charge); } /** * èªå¨æå ¥é»è®¤è´¹ç * @param c3Id */ public void initCharge(Integer c3Id) { List<C3mChargingCharge> chargeList = getChargeByC3Id(c3Id); if (chargeList.size() == 0) { ximon-admin/src/main/java/com/sandu/ximon/admin/service/C3mOrderService.java
@@ -1,7 +1,9 @@ package com.sandu.ximon.admin.service; import com.sandu.common.execption.BusinessException; import com.sandu.common.service.impl.BaseServiceImpl; import com.sandu.common.third.pay.wx.WxFastPayService; import com.sandu.ximon.admin.pay.wx.WxFastPayService; import com.sandu.ximon.admin.security.SecurityUtils; import com.sandu.ximon.admin.utils.AliPayUtils; import com.sandu.ximon.dao.domain.C3mOrder; import com.sandu.ximon.dao.enums.OrderStatus; @@ -24,8 +26,13 @@ private final C3mOrderMapper c3mOrderMapper; private final WxFastPayService fastPayService; public boolean orderRefund(String outTradeNo, Double refundAmount, Long userId, String username) { public boolean orderRefund(String outTradeNo, Double refundAmount/*, Long userId, String username*/) { Long userId = SecurityUtils.getUserId(); String username = SecurityUtils.getUsername(); C3mOrder orderByOutTradeNo = c3mOrderMapper.getOrderByOutTradeNo(outTradeNo); if (orderByOutTradeNo.getTotalAmount() < refundAmount) { throw new BusinessException("鿬¾éé¢é误,ä¸è½å¤§äºä»æ¬¾éé¢"); } if (null == orderByOutTradeNo) { return false; } else { @@ -47,12 +54,12 @@ C3mOrder.getRefundAmount()); } else if (C3mOrder.getOrderType().equals(OrderType.WXPAY.getCode())) { // è¿è¡å¾®ä¿¡é款 // b = WxPayUtils.getBean().wxRefund( // C3mOrder.getTotalAmount(), // C3mOrder.getRefundAmount(), // C3mOrder.getOutTradeNo(), // C3mOrder.getPoleId() // ); b = fastPayService.refund( C3mOrder.getTotalAmount(), C3mOrder.getRefundAmount(), C3mOrder.getOutTradeNo(), C3mOrder.getPoleId() ); } C3mOrder.setRefundTimestamp(new Date().getTime()); C3mOrder.setRefundMsg(msg); ximon-admin/src/main/java/com/sandu/ximon/admin/utils/AliPayUtils.java
@@ -11,8 +11,8 @@ import com.sandu.ximon.admin.config.AlipayConfig; import com.sandu.ximon.admin.pay.alipay.UsrAlipayConfigService; import com.sandu.ximon.dao.domain.AliConfigEntity; import com.sandu.ximon.dao.domain.WxConfigEntity; import lombok.AllArgsConstructor; import java.text.SimpleDateFormat; import java.util.Date; @@ -23,23 +23,23 @@ public static boolean alipayQuery(String out_trade_no, Long streetlightId) { AliConfigEntity WxConfigEntity = UsrAlipayConfigService.getBean().getConfigByPoleId(streetlightId);// è·å客æ·çæ¯ä»å®é ç½® String checkStr = ConfigCheckUtils.checkAlipayConfig(WxConfigEntity); if( checkStr != null){ AliConfigEntity aliConfigEntity = UsrAlipayConfigService.getBean().getConfigByPoleId(streetlightId);// è·å客æ·çæ¯ä»å®é ç½® String checkStr = ConfigCheckUtils.checkAlipayConfig(aliConfigEntity); if (checkStr != null) { LogUtils.error("æ¥è¯¢å¤±è´¥"); return false; } //è·å¾åå§åçAlipayClient AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, WxConfigEntity.getAppId(), WxConfigEntity.getPrivateKey(), AlipayConfig.format, AlipayConfig.charset, WxConfigEntity. aliConfigEntity.getAppId(), aliConfigEntity.getPrivateKey(), AlipayConfig.format, AlipayConfig.charset, aliConfigEntity. getPublicKey(), AlipayConfig.sign_type); //设置请æ±åæ° AlipayTradeQueryRequest alipayRequest = new AlipayTradeQueryRequest(); //åæ·è®¢åå·ï¼åæ·ç½ç«è®¢åç³»ç»ä¸å¯ä¸è®¢åå· alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\"}"); alipayRequest.setBizContent("{\"out_trade_no\":\"" + out_trade_no + "\"}"); //è¯·æ± String result = null; @@ -48,19 +48,19 @@ } catch (AlipayApiException e) { e.printStackTrace(); } Map map = (Map) new Gson().fromJson(result,Map.class).get("alipay_trade_query_response"); Map map = (Map) new Gson().fromJson(result, Map.class).get("alipay_trade_query_response"); if (map.get("sub_msg") != null) { if ("交æä¸åå¨".equals(map.get("sub_msg"))) { return false; } } if(map.get("trade_status")==null){ if (map.get("trade_status") == null) { return false; } if("TRADE_SUCCESS".equals(map.get("trade_status"))){ if ("TRADE_SUCCESS".equals(map.get("trade_status"))) { // String payTime = (String) map.get("send_pay_date"); return true; }else if("TRADE_CLOSED".equals(map.get("trade_status"))){ } else if ("TRADE_CLOSED".equals(map.get("trade_status"))) { LogUtils.error("交æå·²å ³é(æ¯ä»å®)"); return false; } @@ -68,32 +68,32 @@ } /** * æ¯ä»å®é款æ¥å£ * * @return */ public static boolean alipayrefund(Long streetlightId, String out_trade_no, Double refundAmount) { String out_trade_no, Double refundAmount) { //LogService.getBean().log((long)0, ServerTask.SERVER_TASK,"鿬¾æä½",null,"{ è¿è¡æ¯ä»å®é款:"+out_trade_no+" }"); //鿬¾éé¢ï¼ä¸è½å¤§äºè®¢åæ»éé¢ String refund_amount = refundAmount+""; String refund_amount = refundAmount + ""; //鿬¾çåå 说æ String refund_reason = "å çµæ¡©é款"; //æ è¯ä¸æ¬¡é款请æ±ï¼åä¸ç¬äº¤æå¤æ¬¡é款éè¦ä¿è¯å¯ä¸ï¼å¦éé¨å鿬¾ï¼åæ¤åæ°å¿ ä¼ ã String out_request_no = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); String out_request_no = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); AliConfigEntity WxConfigEntity = UsrAlipayConfigService.getBean().getConfigByPoleId(streetlightId); //æ¾å°æ¯åªä¸ªå®¢æ·çå çµæ¡© 就鿬¾ç»è° String checkStr = ConfigCheckUtils.checkAlipayConfig(WxConfigEntity); if( checkStr != null){ AliConfigEntity AliConfigEntity = UsrAlipayConfigService.getBean().getConfigByPoleId(streetlightId); //æ¾å°æ¯åªä¸ªå®¢æ·çå çµæ¡© 就鿬¾ç»è° String checkStr = ConfigCheckUtils.checkAlipayConfig(AliConfigEntity); if (checkStr != null) { return false; } // SDK å ¬å ±è¯·æ±ç±»ï¼å å«å ¬å ±è¯·æ±åæ°ï¼ä»¥åå°è£ äºç¾åä¸éªç¾ï¼å¼åè æ éå ³æ³¨ç¾åä¸éªç¾ AlipayClient client = new DefaultAlipayClient(AlipayConfig.gatewayUrl, WxConfigEntity.getAppId(), WxConfigEntity.getPrivateKey(), AlipayConfig.format, AlipayConfig.charset, WxConfigEntity.getPublicKey(), AlipayConfig.sign_type); AlipayClient client = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AliConfigEntity.getAppId(), AliConfigEntity.getPrivateKey(), AlipayConfig.format, AlipayConfig.charset, AliConfigEntity.getPublicKey(), AlipayConfig.sign_type); AlipayTradeRefundRequest alipay_request = new AlipayTradeRefundRequest(); AlipayTradeRefundModel model = new AlipayTradeRefundModel(); model.setOutTradeNo(out_trade_no); @@ -110,13 +110,13 @@ e.printStackTrace(); } // System.out.println(alipay_response.getBody()); if("10000".equals(alipay_response.getCode())){ if ("10000".equals(alipay_response.getCode())) { // 鿬¾æå // LogService.getBean().log((long)0, ServerTask.SERVER_TASK,"鿬¾æä½",null,"{ è¿è¡æ¯ä»å®é款(æå):"+out_trade_no+",鿬¾éé¢:"+refundAmount+" }"); // LogService.getBean().log((long)0, ServerTask.SERVER_TASK,"鿬¾æä½",null,"{ è¿è¡æ¯ä»å®é款(æå):"+out_trade_no+",鿬¾éé¢:"+refundAmount+" }"); return true; } //ä¿å鿬¾éé¢å鿬¾åå·ï¼å°è®¢åç¶æç½®ä¸ºå®æï¼RFERRORï¼ï¼ä¿åå°æ°æ®åº // LogService.getBean().log((long)0, ServerTask.SERVER_TASK,"鿬¾æä½",null,"{ è¿è¡æ¯ä»å®é款(失败):"+out_trade_no+",鿬¾éé¢:"+refundAmount+",reason: "+ JSON.toJSONString(alipay_response)+" }"); // LogService.getBean().log((long)0, ServerTask.SERVER_TASK,"鿬¾æä½",null,"{ è¿è¡æ¯ä»å®é款(失败):"+out_trade_no+",鿬¾éé¢:"+refundAmount+",reason: "+ JSON.toJSONString(alipay_response)+" }"); return false; }