|
@@ -83,10 +83,55 @@ public class WalletServiceImpl implements IWalletService {
|
|
|
@Value("${pay.channel-sign}")
|
|
|
private String channelPaySign; //渠道端商户签名
|
|
|
|
|
|
+
|
|
|
+ @Value("${ali-miniApp.appId}")
|
|
|
+ private String aliMiniAppAppId;
|
|
|
+
|
|
|
private static final String REQ_STATUS_SUCCESS = "R0001";
|
|
|
private static final String PAY_RESOURCE = "2"; //2:微信支付
|
|
|
private static final String PAY_RESOURCE_TYPE = "1017"; //2:微信小程序
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject aliPay(BizTypeEnum bizType, String bizId, String openId, int money, String orderRemark) {
|
|
|
+ String reqUrl = baseUrl + "/pay/payMoneyCTB";
|
|
|
+ String appId = aliMiniAppAppId;
|
|
|
+ String payShopNo = userPayShopNo;
|
|
|
+ String paySign = userPaySign;
|
|
|
+ JSONObject params = buildPayOrderReqData(payShopNo, paySign, money, openId, appId, orderRemark, "1", "1014");
|
|
|
+ String result = OkHttpUtil.postJsonParams(reqUrl, params.toJSONString());
|
|
|
+ logger.info("request params:" + params.toJSONString() + " result:" + result);
|
|
|
+ if (StringUtils.isBlank(result)) {
|
|
|
+ LogUtil.error(logger, "创建支付订单接口失败");
|
|
|
+ throw new ServiceException("创建三方支付订单失败");
|
|
|
+ }
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ String code = resultJson.getString("code");
|
|
|
+ String orderNo = resultJson.getString("order_no");
|
|
|
+ String payInfo = resultJson.getString("pay_info");
|
|
|
+ String orderstatus = resultJson.getString("orderstatus");
|
|
|
+ String resultMsg = resultJson.getString("result");
|
|
|
+ if (!REQ_STATUS_SUCCESS.equalsIgnoreCase(code)) {
|
|
|
+ throw new ServiceException(resultMsg);
|
|
|
+ }
|
|
|
+ //保存订单记录
|
|
|
+ PayOrder payOrder = buildPayOrder(params);
|
|
|
+ payOrder.setOrderId(resultJson.getString("shop_order_no"));
|
|
|
+ payOrder.setOrderNo(orderNo);
|
|
|
+ payOrder.setCode(code);
|
|
|
+ payOrder.setBizType(bizType);
|
|
|
+ payOrder.setBizId(bizId);
|
|
|
+ payOrder.setOrderStatus(orderstatus);
|
|
|
+ boolean ret = payOrderService.save(payOrder);
|
|
|
+ if (!ret) {
|
|
|
+ LogUtil.error(logger, "支付订单数据库保存失败.");
|
|
|
+ throw new ServiceException("支付订单保存失败");
|
|
|
+ }
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ data.put("pay_info", payInfo);
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public JSONObject pay(BizTypeEnum bizType, String bizId, String openId, int money,
|
|
|
String orderRemark) {
|
|
@@ -99,7 +144,7 @@ public class WalletServiceImpl implements IWalletService {
|
|
|
payShopNo = userPayShopNo;
|
|
|
paySign = userPaySign;
|
|
|
}
|
|
|
- JSONObject params = buildPayOrderReqData(payShopNo, paySign, money, openId, appId, orderRemark);
|
|
|
+ JSONObject params = buildPayOrderReqData(payShopNo, paySign, money, openId, appId, orderRemark, PAY_RESOURCE, PAY_RESOURCE_TYPE);
|
|
|
String result = OkHttpUtil.postJsonParams(reqUrl, params.toJSONString());
|
|
|
logger.info("request params:" + params.toJSONString() + " result:" + result);
|
|
|
if (StringUtils.isBlank(result)) {
|
|
@@ -225,14 +270,14 @@ public class WalletServiceImpl implements IWalletService {
|
|
|
return payOrder;
|
|
|
}
|
|
|
|
|
|
- private JSONObject buildPayOrderReqData(String shopNo, String sign, int money, String openId, String appId, String orderRemark) {
|
|
|
+ private JSONObject buildPayOrderReqData(String shopNo, String sign, int money, String openId, String appId, String orderRemark,String payResource, String payResourceType) {
|
|
|
|
|
|
JSONObject sendData = new JSONObject();
|
|
|
sendData.put("shop_no" , shopNo);
|
|
|
sendData.put("shop_order_no" , String.valueOf(bizIdGenerator.newId()));
|
|
|
sendData.put("shop_order_time" , DateUtils.getTime());
|
|
|
- sendData.put("pay_resource" , PAY_RESOURCE); //支付来源 1:支付宝 2:微信支付 5:云闪付
|
|
|
- sendData.put("trans_type_code" , PAY_RESOURCE_TYPE); //1017:微信小程序
|
|
|
+ sendData.put("pay_resource" , payResource); //支付来源 1:支付宝 2:微信支付 5:云闪付
|
|
|
+ sendData.put("trans_type_code" , payResourceType); //1017:微信小程序,1014支付宝
|
|
|
sendData.put("transaction_amount" , money);
|
|
|
sendData.put("order_remark" , "");
|
|
|
sendData.put("timestamp" , System.currentTimeMillis());
|
|
@@ -244,7 +289,10 @@ public class WalletServiceImpl implements IWalletService {
|
|
|
|
|
|
sendData.put("auth_code" , openId);
|
|
|
sendData.put("notify_url" , notifyUrl);
|
|
|
- sendData.put("app_id" , appId);
|
|
|
+ // 微信小程序必传appId
|
|
|
+ if ("2".equals(payResource)) {
|
|
|
+ sendData.put("app_id" , appId);
|
|
|
+ }
|
|
|
return sendData;
|
|
|
}
|
|
|
}
|