|
|
@ -10,7 +10,9 @@ |
|
|
|
import com.gxwebsoft.common.core.exception.BusinessException; |
|
|
|
import com.gxwebsoft.common.core.utils.RedisUtil; |
|
|
|
import com.gxwebsoft.common.system.entity.Payment; |
|
|
|
import com.gxwebsoft.common.system.param.PaymentParam; |
|
|
|
import com.gxwebsoft.common.system.service.PaymentService; |
|
|
|
import com.gxwebsoft.common.system.service.SettingService; |
|
|
|
import com.gxwebsoft.shop.entity.ShopOrderGoods; |
|
|
|
import com.gxwebsoft.shop.mapper.ShopOrderMapper; |
|
|
|
import com.gxwebsoft.shop.service.ShopOrderGoodsService; |
|
|
@ -56,6 +58,8 @@ |
|
|
|
private ShopOrderGoodsService shopOrderGoodsService; |
|
|
|
@Resource |
|
|
|
private PaymentService paymentService; |
|
|
|
@Resource |
|
|
|
private SettingService settingService; |
|
|
|
|
|
|
|
public static String privateKeyPath = "/Users/gxwebsoft/Downloads/ef7f7e0430cb47019d06b93f885bf95f/apiclient_key.pem"; |
|
|
|
public static String privateCertPath = "/Users/gxwebsoft/JAVA/com.gxwebsoft.core/src/main/resources/cert/apiclient_cert.pem"; |
|
|
@ -99,8 +103,6 @@ |
|
|
|
public HashMap<String, String> createWxOrder(ShopOrder order) { |
|
|
|
// 后台微信支付配置信息
|
|
|
|
final Payment payment = getPayment(order); |
|
|
|
// 微信小程序信息
|
|
|
|
final JSONObject wxConfig = getWxConfig(order); |
|
|
|
// 返回的订单数据
|
|
|
|
final HashMap<String, String> orderInfo = new HashMap<>(); |
|
|
|
// 构建service
|
|
|
@ -116,7 +118,7 @@ |
|
|
|
amount.setTotal(money); |
|
|
|
amount.setCurrency("CNY"); |
|
|
|
request.setAmount(amount); |
|
|
|
request.setAppid(wxConfig.getString("appId")); |
|
|
|
request.setAppid(payment.getAppId()); |
|
|
|
request.setMchid(payment.getMchId()); |
|
|
|
request.setDescription(order.getComments()); |
|
|
|
request.setOutTradeNo(order.getOrderNo()); |
|
|
@ -199,28 +201,24 @@ |
|
|
|
if (ObjectUtil.isNotEmpty(payment)) { |
|
|
|
return payment; |
|
|
|
} |
|
|
|
return paymentService.getOne(new LambdaQueryWrapper<Payment>().eq(Payment::getType, order.getType()).last("LIMIT 1")); |
|
|
|
} |
|
|
|
|
|
|
|
public JSONObject getWxConfig(ShopOrder order) { |
|
|
|
// 微信小程序(微信支付)
|
|
|
|
String key = "mp-weixin:".concat(order.getTenantId().toString()); |
|
|
|
final String string = redisUtil.get(key); |
|
|
|
return JSONObject.parseObject(string); |
|
|
|
final PaymentParam paymentParam = new PaymentParam(); |
|
|
|
paymentParam.setType(order.getPayType()); |
|
|
|
final List<Payment> payments = paymentService.listRel(paymentParam); |
|
|
|
return payments.get(0); |
|
|
|
} |
|
|
|
|
|
|
|
public JsapiServiceExtension getWxService(ShopOrder order) { |
|
|
|
Integer payType = order.getPayType(); |
|
|
|
// Integer payType = order.getPayType();
|
|
|
|
final String uploadPath = config.getUploadPath(); // 服务器本地路径
|
|
|
|
final HashMap<String, String> orderInfo = new HashMap<>(); |
|
|
|
// final HashMap<String, String> orderInfo = new HashMap<>();
|
|
|
|
// 微信小程序(微信支付)
|
|
|
|
String key = "mp-weixin:".concat(order.getTenantId().toString()); |
|
|
|
final String string = redisUtil.get(key); |
|
|
|
// String key = "mp-weixin:".concat(order.getTenantId().toString());
|
|
|
|
// final String string = redisUtil.get(key);
|
|
|
|
// System.out.println("string = " + string);
|
|
|
|
final JSONObject mpWx = JSONObject.parseObject(string); |
|
|
|
// final JSONObject mpWx = JSONObject.parseObject(string);
|
|
|
|
// System.out.println("mpWx = " + mpWx);
|
|
|
|
String key2 = "Payment:".concat(payType.toString()).concat(":").concat(order.getTenantId().toString()); |
|
|
|
final Payment payment = redisUtil.get(key2, Payment.class); |
|
|
|
// String key2 = "Payment:".concat(payType.toString()).concat(":").concat(order.getTenantId().toString());
|
|
|
|
final Payment payment = getPayment(order); |
|
|
|
if (ObjectUtil.isEmpty(payment)) { |
|
|
|
throw new BusinessException("请完成支付配置"); |
|
|
|
} |
|
|
@ -228,12 +226,18 @@ |
|
|
|
String privateKey = uploadPath.concat("/file").concat(payment.getApiclientKey()); // 秘钥证书
|
|
|
|
String apiclientCert = uploadPath.concat("/file").concat(payment.getApiclientCert()); |
|
|
|
String pubKey = uploadPath.concat("/file").concat(payment.getPubKey()); // 公钥证书
|
|
|
|
|
|
|
|
// 开发环境配置
|
|
|
|
if (active.equals("dev")) { |
|
|
|
privateKey = privateKeyPath; |
|
|
|
apiclientCert = wechatpayCertPath; |
|
|
|
} |
|
|
|
|
|
|
|
// 生成环境配置
|
|
|
|
if (active.equals("prod")) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 兼容公钥
|
|
|
|
Config config; |
|
|
|
if (payment.getPubKey() != null && !payment.getPubKey().isEmpty()) { |
|
|
|