v1.1 谷歌支付-接入策略,兼容vip贵族
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.accompany.payment.strategy;
|
||||
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.payment.annotation.PayChannelSupport;
|
||||
|
||||
import com.accompany.payment.dto.AppInnerPayRecordDTO;
|
||||
import com.accompany.payment.model.ChargeRecord;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
@Service
|
||||
@PayChannelSupport(Constant.ChargeChannel.google_play_billing)
|
||||
public class GooglePlayStrategy extends AbstractPayStrategy {
|
||||
|
||||
@Override
|
||||
public Object pay(PayContext context) throws Exception {
|
||||
ChargeRecord chargeRecord = context.getChargeRecord();
|
||||
AppInnerPayRecordDTO recordIdVo = new AppInnerPayRecordDTO();
|
||||
recordIdVo.setRecordId(chargeRecord.getChargeRecordId());
|
||||
return recordIdVo;
|
||||
}
|
||||
}
|
@@ -1,11 +1,15 @@
|
||||
package com.accompany.business.service.payment;
|
||||
|
||||
import com.accompany.business.service.ChargeService;
|
||||
import com.accompany.business.service.charge.VipChargeService;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.result.BusiResult;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.common.utils.UUIDUitl;
|
||||
import com.accompany.core.enumeration.BusinessStatusCodeEnum;
|
||||
import com.accompany.core.exception.ServiceException;
|
||||
import com.accompany.core.model.Users;
|
||||
import com.accompany.core.service.SysConfService;
|
||||
@@ -17,6 +21,7 @@ import com.accompany.payment.model.ChargeProd;
|
||||
import com.accompany.payment.model.ChargeRecord;
|
||||
import com.accompany.payment.service.ChargeProdService;
|
||||
import com.accompany.payment.service.ChargeRecordService;
|
||||
import com.accompany.payment.vo.VipOpenParams;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.api.services.androidpublisher.model.ProductPurchase;
|
||||
@@ -49,60 +54,20 @@ public class GooglePlayBillingService {
|
||||
private SysConfService sysConfService;
|
||||
@Autowired
|
||||
private UsersBaseService usersBaseService;
|
||||
@Autowired
|
||||
private VipChargeService vipChargeService;
|
||||
|
||||
public AppInnerPayRecordDTO placeOrder(Long uid, String chargeProdId, String clientIp, String deviceId) {
|
||||
public AppInnerPayRecordDTO placeOrder(Long uid, String chargeProdId, String clientIp, DeviceInfo deviceInfo) {
|
||||
validMoneyLimit(uid, chargeProdId);
|
||||
|
||||
RLock lock = redissonClient.getLock(RedisKey.lock_apply_charge.getKey(uid.toString()));
|
||||
try {
|
||||
lock.tryLock(10, TimeUnit.SECONDS);
|
||||
|
||||
Users users = usersBaseService.getUsersByUid(uid);
|
||||
if (users == null) {
|
||||
log.error("充值用户不存在,uId: {} ", uid);
|
||||
throw new ServiceException(BusiStatus.USERNOTEXISTS);
|
||||
}
|
||||
|
||||
ChargeProd chargeProd = chargeProdService.getChargeProdById(chargeProdId);
|
||||
if (chargeProd == null) {
|
||||
log.error("充值产品不存在,prodId: {} ", chargeProdId);
|
||||
throw new ServiceException(BusiStatus.CHARGE_PROD_NOT_EXIST);
|
||||
}
|
||||
|
||||
//保存充值记录
|
||||
//1.创建订单号
|
||||
//UUID不会重复,所以不需要判断是否生成重复的订单号
|
||||
String chargeRecordId = UUIDUitl.get();
|
||||
|
||||
ChargeRecord chargeRecord = new ChargeRecord();
|
||||
chargeRecord.setChargeRecordId(chargeRecordId);
|
||||
chargeRecord.setChargeProdId(chargeProdId);
|
||||
chargeRecord.setUid(uid);
|
||||
chargeRecord.setChannel(Constant.ChargeChannel.google_play_billing);
|
||||
chargeRecord.setChargeStatus(Constant.ChargeRecordStatus.create);
|
||||
// product中money单位为分
|
||||
chargeRecord.setAmount(chargeProd.getMoney());
|
||||
chargeRecord.setSubject(chargeProd.getProdName());
|
||||
chargeRecord.setBody(chargeProd.getProdName());
|
||||
chargeRecord.setClientIp(clientIp);
|
||||
|
||||
//写入数据库
|
||||
chargeRecordService.insertChargeRecord(chargeRecord);
|
||||
log.info("用户 {} 内购充值,本地订单号: {}", uid, chargeRecordId);
|
||||
|
||||
//订单创建成功返回订单号
|
||||
AppInnerPayRecordDTO recordIdVo = new AppInnerPayRecordDTO();
|
||||
recordIdVo.setRecordId(chargeRecordId);
|
||||
return recordIdVo;
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
throw new ServiceException(BusiStatus.SERVERBUSY);
|
||||
} finally {
|
||||
if (lock.isLocked()){
|
||||
lock.unlock();
|
||||
}
|
||||
BusiResult r = chargeService.applyChargeV4(uid, chargeProdId, Constant.ChargeChannel.google_play_billing,
|
||||
clientIp, null, null, deviceInfo, null, null, null, null);
|
||||
if (r.getCode() == BusinessStatusCodeEnum.SUCCESS.value()){
|
||||
//success
|
||||
return (AppInnerPayRecordDTO) r.getData();
|
||||
} else {
|
||||
throw new ServiceException(BusiStatus.SERVER_BUSY);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void validMoneyLimit(Long uid, String chargeProdId) {
|
||||
|
@@ -1,7 +1,9 @@
|
||||
package com.accompany.business.controller.apppay;
|
||||
|
||||
import com.accompany.business.common.BaseController;
|
||||
import com.accompany.business.service.ChargeService;
|
||||
import com.accompany.common.annotation.Authorization;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.utils.IPUitls;
|
||||
import com.accompany.core.enumeration.BusinessStatusCodeEnum;
|
||||
import com.accompany.core.vo.BaseRequestVO;
|
||||
@@ -22,7 +24,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
@RestController
|
||||
@RequestMapping("/googlePlayBilling")
|
||||
@Slf4j
|
||||
public class GooglePlayBillingChargeController {
|
||||
public class GooglePlayBillingChargeController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private ChargeService chargeService;
|
||||
@@ -31,14 +33,13 @@ public class GooglePlayBillingChargeController {
|
||||
|
||||
@ApiOperation("google内购预下单")
|
||||
@PostMapping("/placeOrder")
|
||||
@Authorization
|
||||
//@Authorization
|
||||
public BaseResponseVO<AppInnerPayRecordDTO> placeOrder(String chargeProdId, HttpServletRequest request) {
|
||||
BaseRequestVO baseRequestVO = new BaseRequestVO();
|
||||
Long uid = baseRequestVO.getMyUserId();
|
||||
Long uid = getUid(request);
|
||||
String clientIp = IPUitls.getRealIpAddress(request);
|
||||
String deviceId = baseRequestVO.getDeviceId();
|
||||
DeviceInfo deviceInfo = getDeviceInfo(request);
|
||||
|
||||
AppInnerPayRecordDTO appInnerPayRecordDTO = googlePlayBillingService.placeOrder(uid, chargeProdId, clientIp, deviceId);
|
||||
AppInnerPayRecordDTO appInnerPayRecordDTO = googlePlayBillingService.placeOrder(uid, chargeProdId, clientIp, deviceInfo);
|
||||
|
||||
return new BaseResponseVO<>(BusinessStatusCodeEnum.SUCCESS, appInnerPayRecordDTO);
|
||||
}
|
||||
|
Reference in New Issue
Block a user