|
|
@@ -9,7 +9,7 @@ import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.dromara.backstage.payment.config.WechatPayConfig;
|
|
|
+import org.dromara.backstage.config.ThirdPayConfig;
|
|
|
import org.dromara.backstage.payment.domain.bo.PayOrderBo;
|
|
|
import org.dromara.backstage.payment.domain.bo.PurseInOutBo;
|
|
|
import org.dromara.backstage.payment.domain.vo.PayOrderVo;
|
|
|
@@ -18,6 +18,7 @@ import org.dromara.common.core.domain.R;
|
|
|
import org.dromara.common.core.enums.BalanceUpdateEnum;
|
|
|
import org.dromara.common.core.enums.CreditStatusEnum;
|
|
|
import org.dromara.common.core.enums.CreditTypeEnum;
|
|
|
+import org.dromara.common.core.enums.PayStatusEnum;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.text.MessageFormat;
|
|
|
@@ -40,15 +41,15 @@ import java.util.Map;
|
|
|
public class ThirdPayBusiness {
|
|
|
private final IPayOrderService payOrderService;
|
|
|
private final PayOrderBusiness payOrderBusiness;
|
|
|
- private final WechatPayConfig wechatPayConfig;
|
|
|
- //private final PayServiceManager manager;
|
|
|
+ private final ThirdPayConfig thirdPayConfig;
|
|
|
|
|
|
/**
|
|
|
* 生成充值收款二维码
|
|
|
+ *
|
|
|
* @param bo 充值订单
|
|
|
* @return 二维码信息
|
|
|
*/
|
|
|
- public R<Map<String,String>> createCollectQrCode(PayOrderBo bo) throws Exception {
|
|
|
+ public R<Map<String, String>> createCollectQrCode(PayOrderBo bo) throws Exception {
|
|
|
R<PayOrderVo> result = createThirdPayOrder(bo);
|
|
|
if (R.isError(result)) {
|
|
|
return R.fail(result.getMsg());
|
|
|
@@ -69,7 +70,7 @@ public class ThirdPayBusiness {
|
|
|
* @param bo 订单信息
|
|
|
* @return 处理结果
|
|
|
*/
|
|
|
- public R<PayOrderVo> payCallBackHandler(PayOrderBo bo){
|
|
|
+ public R<PayOrderVo> payCallBackHandler(PayOrderBo bo) {
|
|
|
// 1.设置支付订单的支付状态
|
|
|
R<PayOrderVo> result = setOrderPayResult(bo);
|
|
|
if (R.isError(result)) {
|
|
|
@@ -103,6 +104,7 @@ public class ThirdPayBusiness {
|
|
|
|
|
|
/**
|
|
|
* 生成第三方支付订单
|
|
|
+ *
|
|
|
* @param bo 订单信息
|
|
|
* @return 订单信息
|
|
|
*/
|
|
|
@@ -116,6 +118,7 @@ public class ThirdPayBusiness {
|
|
|
|
|
|
/**
|
|
|
* 第三方支付订单入账
|
|
|
+ *
|
|
|
* @param bo 订单信息
|
|
|
* @return 入账结果
|
|
|
*/
|
|
|
@@ -141,6 +144,7 @@ public class ThirdPayBusiness {
|
|
|
|
|
|
/**
|
|
|
* 更新订单的支付状态
|
|
|
+ *
|
|
|
* @param bo 订单信息
|
|
|
* @return 更新结果
|
|
|
*/
|
|
|
@@ -165,6 +169,7 @@ public class ThirdPayBusiness {
|
|
|
|
|
|
/**
|
|
|
* 更新订单的入账状态
|
|
|
+ *
|
|
|
* @param bo 订单信息
|
|
|
* @return 更新结果
|
|
|
*/
|
|
|
@@ -177,27 +182,42 @@ public class ThirdPayBusiness {
|
|
|
return R.ok(vo);
|
|
|
}
|
|
|
|
|
|
- public R<Map<String,String>> createWechatQrCode(PayOrderVo vo) throws Exception {
|
|
|
- String sendUrl = "http://localhost:8083/pay/qrCode";
|
|
|
- vo.setBackUrl("http://localhost:8001/dev-api/self/teacher/api/v1/wechat/recharge/result/");
|
|
|
- HttpRequest req = HttpUtil.createPost(sendUrl);
|
|
|
+ /**
|
|
|
+ * 生成微信的二维码
|
|
|
+ * @param vo 订单信息
|
|
|
+ * @return 二维码
|
|
|
+ */
|
|
|
+ public R<Map<String, String>> createWechatQrCode(PayOrderVo vo) {
|
|
|
+ String qrCodeUrl = thirdPayConfig.getPayApi() + "qrCode";
|
|
|
+ vo.setBackUrl(thirdPayConfig.getRechargeBackUrl() + vo.getOrderId());
|
|
|
+ HttpRequest req = HttpUtil.createPost(qrCodeUrl);
|
|
|
req.body(JSONUtil.toJsonStr(vo));
|
|
|
- try(HttpResponse res = req.execute()){
|
|
|
+ try (HttpResponse res = req.execute()) {
|
|
|
JSONObject object = JSONUtil.parseObj(res.body());
|
|
|
String resCode = object.getStr("code");
|
|
|
- String resMessage = object.getStr("message");
|
|
|
String resData = object.getStr("data");
|
|
|
if (ObjectUtil.equals(resCode, "200")) {
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
- map.put("orderSn",vo.getOrderId().toString());
|
|
|
+ map.put("orderSn", vo.getOrderId().toString());
|
|
|
map.put("qrCode", resData);
|
|
|
|
|
|
return R.ok(map);
|
|
|
}
|
|
|
- return R.fail(String.format("[生成微信收款码错误]-[%s]",resMessage));
|
|
|
- }catch (Exception e){
|
|
|
- log.error("[生成微信收款码错误]-[{0}]",e);
|
|
|
+ return R.fail(String.format("[生成微信收款码错误]-[%s]", object));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("[生成微信收款码错误]-[{0}]", e);
|
|
|
return R.fail("[生成微信收款码错误]");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public R<Void> queryOrderPayResult(String orderSn) {
|
|
|
+ PayOrderVo vo = payOrderService.queryById(Long.valueOf(orderSn));
|
|
|
+ if (ObjectUtil.isEmpty(vo)) {
|
|
|
+ return R.fail(String.format("[无此订单]-[订单号:%s]", orderSn));
|
|
|
+ }
|
|
|
+ if (ObjectUtil.equals(vo.getPayStatus(), PayStatusEnum.SUCCESS.code().toString())) {
|
|
|
+ return R.ok(String.format("[订单已支付]-[订单号:%s]", orderSn));
|
|
|
+ }
|
|
|
+ return R.fail(String.format("[订单待支付]-[订单号:%s]", orderSn));
|
|
|
+ }
|
|
|
}
|