Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.chaozhanggui.system.cashierservice.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.chaozhanggui.system.cashierservice.annotation.LimitSubmit;
|
||||
import com.chaozhanggui.system.cashierservice.service.PayService;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
@@ -40,8 +41,17 @@ public class PayController {
|
||||
return Result.fail("订单号不允许为空");
|
||||
}
|
||||
|
||||
if (!map.containsKey("payType")) {
|
||||
return Result.fail("支付类型不允许为空");
|
||||
}
|
||||
|
||||
String payType = map.get("payType");
|
||||
if (StrUtil.isEmpty(payType)) {
|
||||
return Result.fail("支付类型不允许为空");
|
||||
}
|
||||
|
||||
try {
|
||||
return payService.payOrder(openId, map.get("orderId"), IpUtil.getIpAddr(request));
|
||||
return payService.payOrder(openId, map.get("orderId"), payType, IpUtil.getIpAddr(request));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -77,6 +87,8 @@ public class PayController {
|
||||
String userId = "";
|
||||
if (environment.equals("wx") && payType.equals("wechatPay")) {
|
||||
userId = TokenUtil.parseParamFromToken(token).getString("openId");
|
||||
} else if("aliPay".equals(payType)){
|
||||
userId = TokenUtil.parseParamFromToken(token).getString("openId");
|
||||
} else {
|
||||
userId = TokenUtil.parseParamFromToken(token).getString("userId");
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ public class TbMerchantThirdApply implements Serializable {
|
||||
|
||||
private String smallAppid;
|
||||
|
||||
private String alipaySmallAppid;
|
||||
|
||||
private String storeId;
|
||||
|
||||
|
||||
@@ -117,4 +119,12 @@ public class TbMerchantThirdApply implements Serializable {
|
||||
public void setStoreId(String storeId) {
|
||||
this.storeId = storeId;
|
||||
}
|
||||
|
||||
public String getAlipaySmallAppid() {
|
||||
return alipaySmallAppid;
|
||||
}
|
||||
|
||||
public void setAlipaySmallAppid(String alipaySmallAppid) {
|
||||
this.alipaySmallAppid = alipaySmallAppid;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.chaozhanggui.system.cashierservice.service;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||
@@ -35,7 +36,6 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -167,9 +167,29 @@ public class PayService {
|
||||
this.shopSongOrderService = shopSongOrderService;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result payOrderTest(String openId, String orderId, String payType, String ip) throws Exception {
|
||||
//thirdUrl;
|
||||
String appId = "66e3dd399a7621f45a6293c1";
|
||||
String reqbody = "茉莉蜜茶";
|
||||
BigDecimal money = new BigDecimal("0.10");
|
||||
long amount = money.setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue();
|
||||
payType = "ALIPAY";
|
||||
String smallAppid = "2021004145625815";
|
||||
openId = "2088812533865205";
|
||||
ip = "1.80.208.76";
|
||||
String timesSS = DateUtils.getsdfTimesSS();
|
||||
String storeId = "S2409148611";
|
||||
//callFSTBack
|
||||
//null
|
||||
String appToken = "jVQs9aBIFOj1mh2ioDp5RLiNBLcQoRnhniH9xlyc3ZKmDcwOpDargyEIYASCePtbA4hyJ5aeH841HfBA4rEKFsxl5AJjGcQa7qT28qU0SPN6v9dNzKYK1eTyvSw6mNBh";
|
||||
PublicResp<WxScanPayResp> wxScanPayResp = thirdPayService.scanpay(thirdUrl, appId, reqbody, reqbody, amount, payType, smallAppid, openId, ip, timesSS, storeId, callFSTBack, null, appToken);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return Result.success(CodeEnum.SUCCESS, mapper.readTree(wxScanPayResp.getObjData().getPayInfo()));
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result payOrder(String openId, String orderId, String ip) throws Exception {
|
||||
public Result payOrder(String openId, String orderId, String payType, String ip) throws Exception {
|
||||
|
||||
if (ObjectUtil.isEmpty(openId) || Objects.isNull(openId)) {
|
||||
return Result.fail("付款用户[userId]参数不能为空");
|
||||
@@ -203,6 +223,9 @@ public class PayService {
|
||||
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
|
||||
return Result.fail("支付通道不存在");
|
||||
}
|
||||
if ("aliPay".equals(payType) && StrUtil.isBlank(thirdApply.getAlipaySmallAppid())) {
|
||||
return Result.fail("店铺未配置支付宝小程序appId");
|
||||
}
|
||||
|
||||
String userId = String.valueOf(TokenUtil.getUserId());
|
||||
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId);
|
||||
@@ -212,8 +235,12 @@ public class PayService {
|
||||
payment.setAmount(orderInfo.getOrderAmount());
|
||||
payment.setPaidAmount(orderInfo.getPayAmount());
|
||||
payment.setHasRefundAmount(BigDecimal.ZERO);
|
||||
if ("wechatPay".equals(payType)) {
|
||||
payment.setPayName("微信支付");
|
||||
payment.setPayType("wechatPay");
|
||||
} else if ("aliPay".equals(payType)) {
|
||||
payment.setPayName("支付宝支付");
|
||||
}
|
||||
payment.setPayType(payType);
|
||||
payment.setReceived(payment.getAmount());
|
||||
payment.setChangeFee(BigDecimal.ZERO);
|
||||
payment.setMemberId(orderInfo.getMemberId());
|
||||
@@ -222,6 +249,12 @@ public class PayService {
|
||||
payment.setCreatedAt(System.currentTimeMillis());
|
||||
tbOrderPaymentMapper.insert(payment);
|
||||
} else {
|
||||
if (payType.equals("wechatPay")) {
|
||||
payment.setPayName("微信支付");
|
||||
} else if (payType.equals("aliPay")) {
|
||||
payment.setPayName("支付宝支付");
|
||||
}
|
||||
payment.setPayType(payType);
|
||||
payment.setUpdatedAt(System.currentTimeMillis());
|
||||
tbOrderPaymentMapper.updateByPrimaryKey(payment);
|
||||
}
|
||||
@@ -280,10 +313,25 @@ public class PayService {
|
||||
reqbody = body.toString();
|
||||
}
|
||||
|
||||
PublicResp<WxScanPayResp> publicResp = thirdPayService.scanpay(thirdUrl, thirdApply.getAppId(),
|
||||
reqbody, reqbody,
|
||||
String smallAppid = thirdApply.getSmallAppid();
|
||||
if ("aliPay".equals(payType)){
|
||||
smallAppid = thirdApply.getAlipaySmallAppid();
|
||||
}
|
||||
String convertPayType = "aliPay".equals(payType) ? "ALIPAY" : "WECHAT";
|
||||
PublicResp<WxScanPayResp> publicResp = thirdPayService.scanpay(thirdUrl,
|
||||
thirdApply.getAppId(),
|
||||
reqbody,
|
||||
reqbody,
|
||||
payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),
|
||||
"WECHAT", thirdApply.getSmallAppid(), openId, ip, DateUtils.getsdfTimesSS(), thirdApply.getStoreId(), callFSTBack, null, thirdApply.getAppToken());
|
||||
convertPayType,
|
||||
smallAppid,
|
||||
openId,
|
||||
ip,
|
||||
DateUtils.getsdfTimesSS(),
|
||||
thirdApply.getStoreId(),
|
||||
callFSTBack,
|
||||
null,
|
||||
thirdApply.getAppToken());
|
||||
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
|
||||
if ("000000".equals(publicResp.getCode())) {
|
||||
WxScanPayResp wxScanPayResp = publicResp.getObjData();
|
||||
@@ -527,6 +575,11 @@ public class PayService {
|
||||
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
|
||||
return Result.fail("支付通道不存在");
|
||||
}
|
||||
|
||||
if ("aliPay".equals(payType) && StrUtil.isBlank(thirdApply.getAlipaySmallAppid())) {
|
||||
return Result.fail("店铺未配置支付宝小程序appId");
|
||||
}
|
||||
|
||||
StringBuffer body = new StringBuffer();
|
||||
body.append(orderInfo.getProName());
|
||||
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderInfo.getOrderNo());
|
||||
@@ -604,14 +657,19 @@ public class PayService {
|
||||
} else {
|
||||
reqbody = body.toString();
|
||||
}
|
||||
String smallAppid = thirdApply.getSmallAppid();
|
||||
if ("aliPay".equals(payType)){
|
||||
smallAppid = thirdApply.getAlipaySmallAppid();
|
||||
}
|
||||
String convertPayType = "aliPay".equals(payType) ? "ALIPAY" : "WECHAT";
|
||||
PublicResp<WxScanPayResp> publicResp = thirdPayService.scanpay(
|
||||
thirdUrl,
|
||||
thirdApply.getAppId(),
|
||||
reqbody,
|
||||
reqbody,
|
||||
payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),
|
||||
"WECHAT",
|
||||
thirdApply.getSmallAppid(),
|
||||
convertPayType,
|
||||
smallAppid,
|
||||
userId,
|
||||
ip,
|
||||
// orderInfo.getOrderNo(),
|
||||
@@ -1243,7 +1301,6 @@ public class PayService {
|
||||
producer.putOrderCollect(jsonObject.toJSONString());
|
||||
|
||||
|
||||
|
||||
JSONObject baObj = new JSONObject();
|
||||
baObj.put("userId", tbShopUser.getUserId());
|
||||
baObj.put("shopId", tbShopUser.getShopId());
|
||||
@@ -1285,7 +1342,6 @@ public class PayService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Result paySongOrder(String openId, String shopId, Integer orderId, String ip, TbMerchantThirdApply thirdApply) throws JsonProcessingException {
|
||||
if (ObjectUtil.isEmpty(openId) || Objects.isNull(openId)) {
|
||||
return Result.fail("付款用户[openId]参数不能为空");
|
||||
|
||||
@@ -11,13 +11,14 @@
|
||||
<result column="created_at" jdbcType="BIGINT" property="createdAt" />
|
||||
<result column="updated_at" jdbcType="BIGINT" property="updatedAt" />
|
||||
<result column="small_appid" jdbcType="VARCHAR" property="smallAppid" />
|
||||
<result column="alipay_small_appid" jdbcType="VARCHAR" property="alipaySmallAppid" />
|
||||
<result column="store_id" jdbcType="VARCHAR" property="storeId" />
|
||||
</resultMap>
|
||||
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.chaozhanggui.system.cashierservice.entity.TbMerchantThirdApply">
|
||||
<result column="app_token" jdbcType="LONGVARCHAR" property="appToken" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
id, type, app_id, status, pay_password, applyment_state, created_at, updated_at,small_appid,store_id
|
||||
id, type, app_id, status, pay_password, applyment_state, created_at, updated_at,small_appid,alipay_small_appid,store_id
|
||||
</sql>
|
||||
<sql id="Blob_Column_List">
|
||||
app_token
|
||||
|
||||
Reference in New Issue
Block a user