修改诺干问题
This commit is contained in:
parent
446dd75191
commit
c5de12d144
|
@ -146,6 +146,17 @@ public class AlipayController {
|
||||||
|
|
||||||
// User loginUser = userService.getLoginUser(request);
|
// User loginUser = userService.getLoginUser(request);
|
||||||
// String miniOpenId = loginUser.getOpenId();
|
// 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/Lbv8h4RevGPHqyFIKB3fX7bHRlBB8hCnyX+zj4T/K50LEoZmo4tpVCv7YmRkyGRoF0QwaMgbo3bkaaCZeQnuPeZFaqyhszcJL1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3XEVBpBUs5Cv5INN4L+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());
|
User byId = userService.getById(pay.getUserId());
|
||||||
ThrowUtils.throwIf(byId.getOpenId() == null, ErrorCode.NOT_FOUND_ERROR, "不是小程序用户");
|
ThrowUtils.throwIf(byId.getOpenId() == null, ErrorCode.NOT_FOUND_ERROR, "不是小程序用户");
|
||||||
|
|
||||||
|
@ -158,7 +169,7 @@ public class AlipayController {
|
||||||
throw new BusinessException(ErrorCode.NO_AUTH, "你不是该订单用户!");
|
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);
|
log.info("tradeNo:" + tradeNo);
|
||||||
return ResultUtils.success(tradeNo);
|
return ResultUtils.success(tradeNo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,9 +219,10 @@ public class BusinessController {
|
||||||
|
|
||||||
@ApiOperation(value = "获取当前登录商家")
|
@ApiOperation(value = "获取当前登录商家")
|
||||||
@GetMapping("/current")
|
@GetMapping("/current")
|
||||||
public BaseResponse<BusinessVO> getLoginBusiness(HttpServletRequest request){
|
public BaseResponse<BusinessVO> 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));
|
return ResultUtils.success(businessService.getBusinessVO(business));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,9 +67,8 @@ public class CommoditiesController {
|
||||||
//校验
|
//校验
|
||||||
commoditiesService.validCommodities(commodities,false);
|
commoditiesService.validCommodities(commodities,false);
|
||||||
//添加商家id
|
//添加商家id
|
||||||
Business loginBusiness = businessService.getLoginBusiness(request);
|
// Business loginBusiness = businessService.getLoginBusiness(request);
|
||||||
Long businessId = loginBusiness.getId();
|
commodities.setBusinessId(commoditiesAddRequest.getBusinessId());
|
||||||
commodities.setBusinessId(businessId);
|
|
||||||
//保存商品信息
|
//保存商品信息
|
||||||
Long commoditiesId = commoditiesService.addCommodities(commodities);
|
Long commoditiesId = commoditiesService.addCommodities(commodities);
|
||||||
//中间表中添加数据
|
//中间表中添加数据
|
||||||
|
@ -93,8 +92,8 @@ public class CommoditiesController {
|
||||||
}
|
}
|
||||||
Long commoditiesId = commoditiesDeleteRequest.getId();
|
Long commoditiesId = commoditiesDeleteRequest.getId();
|
||||||
//获取商家id
|
//获取商家id
|
||||||
Business business = businessService.getLoginBusiness(request);
|
// Business business = businessService.getLoginBusiness(request);
|
||||||
Long businessId = business.getId();
|
Long businessId = commoditiesDeleteRequest.getBusinessId();
|
||||||
//校验商品是不是当前登录商家的
|
//校验商品是不是当前登录商家的
|
||||||
LambdaQueryWrapper<Commodities> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<Commodities> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(Commodities::getId, commoditiesId);
|
wrapper.eq(Commodities::getId, commoditiesId);
|
||||||
|
@ -127,8 +126,8 @@ public class CommoditiesController {
|
||||||
//校验
|
//校验
|
||||||
commoditiesService.validCommodities(commodities, true);
|
commoditiesService.validCommodities(commodities, true);
|
||||||
//添加商家id
|
//添加商家id
|
||||||
Business loginBusiness = businessService.getLoginBusiness(request);
|
// Business loginBusiness = businessService.getLoginBusiness(request);
|
||||||
Long businessId = loginBusiness.getId();
|
Long businessId = commoditiesUpdateRequest.getBusinessId();
|
||||||
commodities.setBusinessId(businessId);
|
commodities.setBusinessId(businessId);
|
||||||
//更新商品
|
//更新商品
|
||||||
Boolean updateDishes = commoditiesService.updateCommodities(commodities);
|
Boolean updateDishes = commoditiesService.updateCommodities(commodities);
|
||||||
|
@ -155,8 +154,8 @@ public class CommoditiesController {
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取商家id
|
//获取商家id
|
||||||
Business loginBusiness = businessService.getLoginBusiness(request);
|
// Business loginBusiness = businessService.getLoginBusiness(request);
|
||||||
Long businessId = loginBusiness.getId();
|
Long businessId = commoditiesUpdateRequest.getBusinessId();
|
||||||
//更新状态
|
//更新状态
|
||||||
UpdateWrapper<Commodities> updateWrapper = new UpdateWrapper<>();
|
UpdateWrapper<Commodities> updateWrapper = new UpdateWrapper<>();
|
||||||
updateWrapper.eq("id",id);
|
updateWrapper.eq("id",id);
|
||||||
|
|
|
@ -15,6 +15,6 @@ public class CommoditiesDeleteRequest implements Serializable {
|
||||||
*/
|
*/
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
private Long businessId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package com.cj.jiaqingjiayi.service;
|
package com.cj.jiaqingjiayi.service;
|
||||||
|
|
||||||
|
import com.alipay.api.AlipayClient;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
public interface AliPayService {
|
public interface AliPayService {
|
||||||
|
|
||||||
String createPayment(String orderId, String miniOpenId, BigDecimal amount);
|
String createPayment(String orderId, String miniOpenId, BigDecimal amount, AlipayClient alipayClient);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.cj.jiaqingjiayi.service.impl;
|
||||||
|
|
||||||
|
|
||||||
import com.alipay.api.AlipayApiException;
|
import com.alipay.api.AlipayApiException;
|
||||||
|
import com.alipay.api.AlipayClient;
|
||||||
import com.alipay.api.domain.AlipayTradeCreateModel;
|
import com.alipay.api.domain.AlipayTradeCreateModel;
|
||||||
import com.alipay.api.request.AlipayTradeCreateRequest;
|
import com.alipay.api.request.AlipayTradeCreateRequest;
|
||||||
import com.alipay.api.response.AlipayTradeCreateResponse;
|
import com.alipay.api.response.AlipayTradeCreateResponse;
|
||||||
|
@ -37,9 +38,9 @@ public class AlipayServiceImpl implements AliPayService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public synchronized String createPayment(String orderId, String miniOpenId, BigDecimal amount) {
|
public synchronized String createPayment(String orderId, String miniOpenId, BigDecimal amount, AlipayClient alipayClient) {
|
||||||
//创建客户
|
|
||||||
AlipayClients clients = new AlipayClients();
|
|
||||||
//AlipayClient client = clients.alipayClient();
|
//AlipayClient client = clients.alipayClient();
|
||||||
//创建交易请求
|
//创建交易请求
|
||||||
AlipayTradeCreateRequest aliRequest = new AlipayTradeCreateRequest();
|
AlipayTradeCreateRequest aliRequest = new AlipayTradeCreateRequest();
|
||||||
|
@ -71,7 +72,6 @@ public class AlipayServiceImpl implements AliPayService {
|
||||||
model.setTotalAmount(String.valueOf(amount));
|
model.setTotalAmount(String.valueOf(amount));
|
||||||
model.setSubject(subject);
|
model.setSubject(subject);
|
||||||
model.setProductCode("JSAPI_PAY");
|
model.setProductCode("JSAPI_PAY");
|
||||||
model.setSellerId("2088721034640726");
|
|
||||||
model.setBuyerId("2088722034659383");
|
model.setBuyerId("2088722034659383");
|
||||||
model.setOpAppId("2021004144652242");
|
model.setOpAppId("2021004144652242");
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ public class AlipayServiceImpl implements AliPayService {
|
||||||
aliRequest.setBizModel(model);
|
aliRequest.setBizModel(model);
|
||||||
String trade_no = null;
|
String trade_no = null;
|
||||||
try {
|
try {
|
||||||
AlipayTradeCreateResponse response = clients.alipayClient().execute(aliRequest);
|
AlipayTradeCreateResponse response = alipayClient.execute(aliRequest);
|
||||||
trade_no = response.getTradeNo();
|
trade_no = response.getTradeNo();
|
||||||
if (trade_no == null) {
|
if (trade_no == null) {
|
||||||
throw new BusinessException(ErrorCode.NULL_ERROR, "未获取到trade_no");
|
throw new BusinessException(ErrorCode.NULL_ERROR, "未获取到trade_no");
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user