支持支付宝获取用户手机号
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.chaozhanggui.system.cashierservice.controller;
|
package com.chaozhanggui.system.cashierservice.controller;
|
||||||
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.chaozhanggui.system.cashierservice.annotation.LimitSubmit;
|
import com.chaozhanggui.system.cashierservice.annotation.LimitSubmit;
|
||||||
import com.chaozhanggui.system.cashierservice.service.PayService;
|
import com.chaozhanggui.system.cashierservice.service.PayService;
|
||||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||||
@@ -40,8 +41,17 @@ public class PayController {
|
|||||||
return Result.fail("订单号不允许为空");
|
return Result.fail("订单号不允许为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!map.containsKey("payType")) {
|
||||||
|
return Result.fail("支付类型不允许为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
String payType = map.get("payType");
|
||||||
|
if (StrUtil.isEmpty(payType)) {
|
||||||
|
return Result.fail("支付类型不允许为空");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return payService.payOrder(openId, map.get("orderId"), IpUtil.getIpAddr(request));
|
return payService.payOrderTest(openId, map.get("orderId"), payType, IpUtil.getIpAddr(request));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ public class TbMerchantThirdApply implements Serializable {
|
|||||||
|
|
||||||
private String smallAppid;
|
private String smallAppid;
|
||||||
|
|
||||||
|
private String alipaySmallAppid;
|
||||||
|
|
||||||
private String storeId;
|
private String storeId;
|
||||||
|
|
||||||
|
|
||||||
@@ -117,4 +119,12 @@ public class TbMerchantThirdApply implements Serializable {
|
|||||||
public void setStoreId(String storeId) {
|
public void setStoreId(String storeId) {
|
||||||
this.storeId = 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.ObjectUtil;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
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.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@@ -166,9 +166,28 @@ public class PayService {
|
|||||||
this.shopSongOrderService = shopSongOrderService;
|
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> scanpay = thirdPayService.scanpay(thirdUrl, appId, reqbody, reqbody, amount, payType, smallAppid, openId, ip, timesSS, storeId, callFSTBack, null, appToken);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@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)) {
|
if (ObjectUtil.isEmpty(openId) || Objects.isNull(openId)) {
|
||||||
return Result.fail("付款用户[userId]参数不能为空");
|
return Result.fail("付款用户[userId]参数不能为空");
|
||||||
@@ -205,6 +224,10 @@ public class PayService {
|
|||||||
return Result.fail("支付通道不存在");
|
return Result.fail("支付通道不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ("aliPay".equals(payType) && StrUtil.isBlank(thirdApply.getAlipaySmallAppid())) {
|
||||||
|
return Result.fail("店铺未配置支付宝小程序appId");
|
||||||
|
}
|
||||||
|
|
||||||
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId);
|
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId);
|
||||||
if (ObjectUtil.isEmpty(payment) || payment == null) {
|
if (ObjectUtil.isEmpty(payment) || payment == null) {
|
||||||
payment = new TbOrderPayment();
|
payment = new TbOrderPayment();
|
||||||
@@ -212,8 +235,12 @@ public class PayService {
|
|||||||
payment.setAmount(orderInfo.getOrderAmount());
|
payment.setAmount(orderInfo.getOrderAmount());
|
||||||
payment.setPaidAmount(orderInfo.getPayAmount());
|
payment.setPaidAmount(orderInfo.getPayAmount());
|
||||||
payment.setHasRefundAmount(BigDecimal.ZERO);
|
payment.setHasRefundAmount(BigDecimal.ZERO);
|
||||||
|
if ("wechatPay".equals(payType)) {
|
||||||
payment.setPayName("微信支付");
|
payment.setPayName("微信支付");
|
||||||
payment.setPayType("wechatPay");
|
} else if ("aliPay".equals(payType)) {
|
||||||
|
payment.setPayName("支付宝支付");
|
||||||
|
}
|
||||||
|
payment.setPayType(payType);
|
||||||
payment.setReceived(payment.getAmount());
|
payment.setReceived(payment.getAmount());
|
||||||
payment.setChangeFee(BigDecimal.ZERO);
|
payment.setChangeFee(BigDecimal.ZERO);
|
||||||
payment.setMemberId(orderInfo.getMemberId());
|
payment.setMemberId(orderInfo.getMemberId());
|
||||||
@@ -222,6 +249,12 @@ public class PayService {
|
|||||||
payment.setCreatedAt(System.currentTimeMillis());
|
payment.setCreatedAt(System.currentTimeMillis());
|
||||||
tbOrderPaymentMapper.insert(payment);
|
tbOrderPaymentMapper.insert(payment);
|
||||||
} else {
|
} else {
|
||||||
|
if (payType.equals("wechatPay")) {
|
||||||
|
payment.setPayName("微信支付");
|
||||||
|
} else if (payType.equals("aliPay")) {
|
||||||
|
payment.setPayName("支付宝支付");
|
||||||
|
}
|
||||||
|
payment.setPayType(payType);
|
||||||
payment.setUpdatedAt(System.currentTimeMillis());
|
payment.setUpdatedAt(System.currentTimeMillis());
|
||||||
tbOrderPaymentMapper.updateByPrimaryKey(payment);
|
tbOrderPaymentMapper.updateByPrimaryKey(payment);
|
||||||
}
|
}
|
||||||
@@ -281,10 +314,25 @@ public class PayService {
|
|||||||
reqbody = body.toString();
|
reqbody = body.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
PublicResp<WxScanPayResp> publicResp = thirdPayService.scanpay(thirdUrl, thirdApply.getAppId(),
|
String smallAppid = thirdApply.getSmallAppid();
|
||||||
reqbody, reqbody,
|
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(),
|
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 (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
|
||||||
if ("000000".equals(publicResp.getCode())) {
|
if ("000000".equals(publicResp.getCode())) {
|
||||||
WxScanPayResp wxScanPayResp = publicResp.getObjData();
|
WxScanPayResp wxScanPayResp = publicResp.getObjData();
|
||||||
@@ -528,6 +576,11 @@ public class PayService {
|
|||||||
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
|
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
|
||||||
return Result.fail("支付通道不存在");
|
return Result.fail("支付通道不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ("aliPay".equals(payType) && StrUtil.isBlank(thirdApply.getAlipaySmallAppid())) {
|
||||||
|
return Result.fail("店铺未配置支付宝小程序appId");
|
||||||
|
}
|
||||||
|
|
||||||
StringBuffer body = new StringBuffer();
|
StringBuffer body = new StringBuffer();
|
||||||
body.append(orderInfo.getProName());
|
body.append(orderInfo.getProName());
|
||||||
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderInfo.getOrderNo());
|
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderInfo.getOrderNo());
|
||||||
@@ -605,14 +658,19 @@ public class PayService {
|
|||||||
} else {
|
} else {
|
||||||
reqbody = body.toString();
|
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(
|
PublicResp<WxScanPayResp> publicResp = thirdPayService.scanpay(
|
||||||
thirdUrl,
|
thirdUrl,
|
||||||
thirdApply.getAppId(),
|
thirdApply.getAppId(),
|
||||||
reqbody,
|
reqbody,
|
||||||
reqbody,
|
reqbody,
|
||||||
payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),
|
payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),
|
||||||
"WECHAT",
|
convertPayType,
|
||||||
thirdApply.getSmallAppid(),
|
smallAppid,
|
||||||
userId,
|
userId,
|
||||||
ip,
|
ip,
|
||||||
// orderInfo.getOrderNo(),
|
// orderInfo.getOrderNo(),
|
||||||
@@ -1240,7 +1298,6 @@ public class PayService {
|
|||||||
producer.putOrderCollect(jsonObject.toJSONString());
|
producer.putOrderCollect(jsonObject.toJSONString());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JSONObject baObj = new JSONObject();
|
JSONObject baObj = new JSONObject();
|
||||||
baObj.put("userId", tbShopUser.getUserId());
|
baObj.put("userId", tbShopUser.getUserId());
|
||||||
baObj.put("shopId", tbShopUser.getShopId());
|
baObj.put("shopId", tbShopUser.getShopId());
|
||||||
@@ -1282,7 +1339,6 @@ public class PayService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Result paySongOrder(String openId, String shopId, Integer orderId, String ip, TbMerchantThirdApply thirdApply) throws JsonProcessingException {
|
public Result paySongOrder(String openId, String shopId, Integer orderId, String ip, TbMerchantThirdApply thirdApply) throws JsonProcessingException {
|
||||||
if (ObjectUtil.isEmpty(openId) || Objects.isNull(openId)) {
|
if (ObjectUtil.isEmpty(openId) || Objects.isNull(openId)) {
|
||||||
return Result.fail("付款用户[openId]参数不能为空");
|
return Result.fail("付款用户[openId]参数不能为空");
|
||||||
|
|||||||
@@ -11,13 +11,14 @@
|
|||||||
<result column="created_at" jdbcType="BIGINT" property="createdAt" />
|
<result column="created_at" jdbcType="BIGINT" property="createdAt" />
|
||||||
<result column="updated_at" jdbcType="BIGINT" property="updatedAt" />
|
<result column="updated_at" jdbcType="BIGINT" property="updatedAt" />
|
||||||
<result column="small_appid" jdbcType="VARCHAR" property="smallAppid" />
|
<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" />
|
<result column="store_id" jdbcType="VARCHAR" property="storeId" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.chaozhanggui.system.cashierservice.entity.TbMerchantThirdApply">
|
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.chaozhanggui.system.cashierservice.entity.TbMerchantThirdApply">
|
||||||
<result column="app_token" jdbcType="LONGVARCHAR" property="appToken" />
|
<result column="app_token" jdbcType="LONGVARCHAR" property="appToken" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<sql id="Base_Column_List">
|
<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>
|
||||||
<sql id="Blob_Column_List">
|
<sql id="Blob_Column_List">
|
||||||
app_token
|
app_token
|
||||||
|
|||||||
Reference in New Issue
Block a user