diff --git a/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/controller/AlipayController.java b/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/controller/AlipayController.java index 1ac2569..1ac67fc 100644 --- a/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/controller/AlipayController.java +++ b/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/controller/AlipayController.java @@ -146,6 +146,17 @@ public class AlipayController { // User loginUser = userService.getLoginUser(request); // String miniOpenId = loginUser.getOpenId(); + String privateKey = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC7rWG3si4XQlDEHjSe/ot98aCn/R25fCSiCBIUTTA6Wy3Gs5lk1XERw1N6loq8u9zR8vTQwzLnFmepwJx2sMLHGfJT3F6Y7Lx0z7gLYksMe+LIAfc+KYsfs0IyDvoKvwsm7XAzl8AYiqk1/p2dxc5etdvkLO7bXquyCDOclR3lL9NBgbJ6tH0fvcVd3RPmZk5Tb2hfn5JK1s/tAanbvFtKhLNCwX8qZp25+AfPakx2tRZkSgjh+fjA6ZElUnwq9ftHy16vfSmnX3C3LuDSKduo3EBkDhpGjTD5+zOs8tKGofW2gn347ouzXWnTz71ftzVwAgFUcOh4Ib0GVC9SKZBrAgMBAAECggEBAJEK8R8/tEFDfhnjYjWScYm3KLtLciJ8n+8dn6NS+DfRabJL8PutvUHGHAj8uWIdKg6T3sJMaVWQyjK16fYMq6umENLg17cGFquMMSeTIn8Wa3C5nDPNdXjdWAZJ7tJJTTwbeoBVAh+1YgqZqYRacCBgGf3hAARHyRfBIOodkEojc4oyzlbUGOz+Ee6/b+A9BZd84YWkbg/KlD9mlqSAYSGCKBM9nd8l1YIvr/4OgBn679x+A8pB8i5kGxP4fertZl2mkt75LigJ3Ab/vwoHDj1AuPjlUIce+PcTdxHqgNtIJSDWbop70BGPp0XQE9BRefPIPQfS9+2LO+eFeo4ESeECgYEA+DzH4cLoMYG9Hfq9IIbQyq6VJeip4/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qcEXZZO8Ziyxel7CqgHDx5dFn1meHDFWTajbWN/0TWSzvYAOKrlrS3LjjwbDzTr3BQzH84TLbLkBaMVGEUkJZUrVVkiN3XEVBpBUs5Cv5INN4L+UJ4kDy1u6LICzUVSSrQmHItuA+YiFHZ/WVJ18jISn0W7YZVyRqTo2sQIDAQAB"; + AlipayConfig alipayConfig = new AlipayConfig(); + alipayConfig.setServerUrl("https://openapi-sandbox.dl.alipaydev.com/gateway.do"); + alipayConfig.setAppId("2021004144652242"); + alipayConfig.setPrivateKey(privateKey); + alipayConfig.setFormat("json"); + alipayConfig.setAlipayPublicKey(alipayPublicKey); + alipayConfig.setCharset("UTF-8"); + alipayConfig.setSignType("RSA2"); + AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig); User byId = userService.getById(pay.getUserId()); ThrowUtils.throwIf(byId.getOpenId() == null, ErrorCode.NOT_FOUND_ERROR, "不是小程序用户"); @@ -158,7 +169,7 @@ public class AlipayController { throw new BusinessException(ErrorCode.NO_AUTH, "你不是该订单用户!"); } - String tradeNo = aliPayService.createPayment(String.valueOf(order.getId()), byId.getOpenId(), order.getTotalPrice()); + String tradeNo = aliPayService.createPayment(String.valueOf(order.getId()), byId.getOpenId(), order.getTotalPrice(), alipayClient); log.info("tradeNo:" + tradeNo); return ResultUtils.success(tradeNo); } diff --git a/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/controller/BusinessController.java b/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/controller/BusinessController.java index e6892c1..51e177b 100644 --- a/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/controller/BusinessController.java +++ b/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/controller/BusinessController.java @@ -219,9 +219,10 @@ public class BusinessController { @ApiOperation(value = "获取当前登录商家") @GetMapping("/current") - public BaseResponse getLoginBusiness(HttpServletRequest request){ + public BaseResponse getLoginBusiness(@RequestParam Long businessId, HttpServletRequest request){ //获取登录态 - Business business = businessService.getLoginBusiness(request); +// Business business = businessService.getLoginBusiness(request); + Business business = businessService.getById(businessId); return ResultUtils.success(businessService.getBusinessVO(business)); } diff --git a/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/controller/CommoditiesController.java b/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/controller/CommoditiesController.java index 441a829..d29525b 100644 --- a/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/controller/CommoditiesController.java +++ b/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/controller/CommoditiesController.java @@ -67,9 +67,8 @@ public class CommoditiesController { //校验 commoditiesService.validCommodities(commodities,false); //添加商家id - Business loginBusiness = businessService.getLoginBusiness(request); - Long businessId = loginBusiness.getId(); - commodities.setBusinessId(businessId); +// Business loginBusiness = businessService.getLoginBusiness(request); + commodities.setBusinessId(commoditiesAddRequest.getBusinessId()); //保存商品信息 Long commoditiesId = commoditiesService.addCommodities(commodities); //中间表中添加数据 @@ -93,8 +92,8 @@ public class CommoditiesController { } Long commoditiesId = commoditiesDeleteRequest.getId(); //获取商家id - Business business = businessService.getLoginBusiness(request); - Long businessId = business.getId(); +// Business business = businessService.getLoginBusiness(request); + Long businessId = commoditiesDeleteRequest.getBusinessId(); //校验商品是不是当前登录商家的 LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(Commodities::getId, commoditiesId); @@ -127,8 +126,8 @@ public class CommoditiesController { //校验 commoditiesService.validCommodities(commodities, true); //添加商家id - Business loginBusiness = businessService.getLoginBusiness(request); - Long businessId = loginBusiness.getId(); +// Business loginBusiness = businessService.getLoginBusiness(request); + Long businessId = commoditiesUpdateRequest.getBusinessId(); commodities.setBusinessId(businessId); //更新商品 Boolean updateDishes = commoditiesService.updateCommodities(commodities); @@ -155,8 +154,8 @@ public class CommoditiesController { } //获取商家id - Business loginBusiness = businessService.getLoginBusiness(request); - Long businessId = loginBusiness.getId(); +// Business loginBusiness = businessService.getLoginBusiness(request); + Long businessId = commoditiesUpdateRequest.getBusinessId(); //更新状态 UpdateWrapper updateWrapper = new UpdateWrapper<>(); updateWrapper.eq("id",id); diff --git a/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/model/request/Commodities/CommoditiesDeleteRequest.java b/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/model/request/Commodities/CommoditiesDeleteRequest.java index 4b7eab2..d160ed9 100644 --- a/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/model/request/Commodities/CommoditiesDeleteRequest.java +++ b/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/model/request/Commodities/CommoditiesDeleteRequest.java @@ -15,6 +15,6 @@ public class CommoditiesDeleteRequest implements Serializable { */ private Long id; - + private Long businessId; } diff --git a/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/service/AliPayService.java b/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/service/AliPayService.java index 2fa436f..2cdd2a5 100644 --- a/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/service/AliPayService.java +++ b/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/service/AliPayService.java @@ -1,8 +1,10 @@ package com.cj.jiaqingjiayi.service; +import com.alipay.api.AlipayClient; + import java.math.BigDecimal; public interface AliPayService { - String createPayment(String orderId, String miniOpenId, BigDecimal amount); + String createPayment(String orderId, String miniOpenId, BigDecimal amount, AlipayClient alipayClient); } diff --git a/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/service/impl/AlipayServiceImpl.java b/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/service/impl/AlipayServiceImpl.java index 455950a..e5eea1f 100644 --- a/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/service/impl/AlipayServiceImpl.java +++ b/project/jiaqingjiayi/src/main/java/com/cj/jiaqingjiayi/service/impl/AlipayServiceImpl.java @@ -2,6 +2,7 @@ package com.cj.jiaqingjiayi.service.impl; import com.alipay.api.AlipayApiException; +import com.alipay.api.AlipayClient; import com.alipay.api.domain.AlipayTradeCreateModel; import com.alipay.api.request.AlipayTradeCreateRequest; import com.alipay.api.response.AlipayTradeCreateResponse; @@ -37,9 +38,9 @@ public class AlipayServiceImpl implements AliPayService { @Override @Transactional(rollbackFor = Exception.class) - public synchronized String createPayment(String orderId, String miniOpenId, BigDecimal amount) { - //创建客户 - AlipayClients clients = new AlipayClients(); + public synchronized String createPayment(String orderId, String miniOpenId, BigDecimal amount, AlipayClient alipayClient) { + + //AlipayClient client = clients.alipayClient(); //创建交易请求 AlipayTradeCreateRequest aliRequest = new AlipayTradeCreateRequest(); @@ -71,7 +72,6 @@ public class AlipayServiceImpl implements AliPayService { model.setTotalAmount(String.valueOf(amount)); model.setSubject(subject); model.setProductCode("JSAPI_PAY"); - model.setSellerId("2088721034640726"); model.setBuyerId("2088722034659383"); model.setOpAppId("2021004144652242"); @@ -80,7 +80,7 @@ public class AlipayServiceImpl implements AliPayService { aliRequest.setBizModel(model); String trade_no = null; try { - AlipayTradeCreateResponse response = clients.alipayClient().execute(aliRequest); + AlipayTradeCreateResponse response = alipayClient.execute(aliRequest); trade_no = response.getTradeNo(); if (trade_no == null) { throw new BusinessException(ErrorCode.NULL_ERROR, "未获取到trade_no"); diff --git a/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/controller/AlipayController.class b/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/controller/AlipayController.class index bbaeaa0..2b3edef 100644 Binary files a/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/controller/AlipayController.class and b/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/controller/AlipayController.class differ diff --git a/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/controller/CommoditiesController.class b/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/controller/CommoditiesController.class index 83d5e65..c7fcdee 100644 Binary files a/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/controller/CommoditiesController.class and b/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/controller/CommoditiesController.class differ diff --git a/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/model/request/Commodities/CommoditiesDeleteRequest.class b/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/model/request/Commodities/CommoditiesDeleteRequest.class index 1bc789c..460b20e 100644 Binary files a/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/model/request/Commodities/CommoditiesDeleteRequest.class and b/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/model/request/Commodities/CommoditiesDeleteRequest.class differ diff --git a/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/service/AliPayService.class b/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/service/AliPayService.class index 2a93feb..bac11b4 100644 Binary files a/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/service/AliPayService.class and b/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/service/AliPayService.class differ diff --git a/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/service/impl/AlipayServiceImpl.class b/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/service/impl/AlipayServiceImpl.class index b73de3a..3844080 100644 Binary files a/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/service/impl/AlipayServiceImpl.class and b/project/jiaqingjiayi/target/classes/com/cj/jiaqingjiayi/service/impl/AlipayServiceImpl.class differ