ios内购

This commit is contained in:
wuchunlei
2024-07-09 16:48:28 +08:00
parent ec17636fe6
commit 472021ca9b
7 changed files with 93 additions and 99 deletions

View File

@@ -10,6 +10,7 @@ public interface VerifyReceiptConstant {
*/
String APP_BUNDLE_IDENTIFIER = "com.cn.nuttyreading";
String MEDICINE_APP_BUNDLE_IDENTIFIER = "com.cn.medicine";
String URL_SANDBOX = "https://sandbox.itunes.apple.com/verifyReceipt";
String URL_VERIFY = "https://buy.itunes.apple.com/verifyReceipt";

View File

@@ -46,7 +46,6 @@ public class AppController {
@Autowired
private BuyOrderService buyOrderService;
@RequestMapping(value = "/text", method = RequestMethod.POST)
public String verif() {
return "test";
@@ -58,19 +57,11 @@ public class AppController {
* @param dto 入参: 订单id, 苹果凭证
* @return 验证结果
*/
@RequestMapping(value = "/veri", method = RequestMethod.POST)
public Result verifyIap(@RequestBody IapRequestDTO dto) {
Lock lock = new ReentrantLock();
lock.lock();
try {
// 1. 校验入参
if (dto == null)
return Result.error("入参不能为空");
@@ -84,122 +75,91 @@ public class AppController {
return Result.error("内购订单号不能为空");
if (dto.getReceiptData().isEmpty())
return Result.error("凭证不能为空");
IapResponseDTO receipt = iapVerifyReceiptService.verifyIapReceipt(dto.getReceiptData(), dto.isSandBox());
BuyOrder order2 = this.buyOrderService.getOne(new QueryWrapper<BuyOrder>().eq("order_sn", dto.getOrderId()).eq("del_flag", "0"));
order2.setPaymentDate(new Date());
order2.setProductId(dto.getProductId());
this.buyOrderService.updateById(order2);
IosPayOrderEntity order = new IosPayOrderEntity();
//todo 判断状态 订单状态 0-未付款 1-待发货 2-已发货 3-交易成功 4-交易失败
String order01 = order.getOrderid();
String order02 = order2.getOrderSn();
if (order01 == order02) {
return Result.ok();
}
else
if (order01 == null ) {
// 3.1 校验bundle id
if (!receipt.getReceipt().getBundle_id().equals(VerifyReceiptConstant.APP_BUNDLE_IDENTIFIER)) {
if (!receipt.getReceipt().getBundle_id().equals(VerifyReceiptConstant.APP_BUNDLE_IDENTIFIER)&&
!receipt.getReceipt().getBundle_id().equals(VerifyReceiptConstant.MEDICINE_APP_BUNDLE_IDENTIFIER)) {
return Result.error1();
}
if (receipt.getStatus().equals("0")) {
for (IapResponseDTO.AppleOrder appleOrder : receipt.getReceipt().getIn_app()) {
if (appleOrder.getTransaction_id().equals(dto.getTransactionId()) &&
appleOrder.getProduct_id().equals(dto.getProductId())) {
System.out.println("开始进入判断3"+appleOrder.getTransaction_id()+"====="+dto.getTransactionId()+"====="+
appleOrder.getProduct_id()+"====="+dto.getProductId());
order.setOrderid(dto.getOrderId());
order.setReceiptData(dto.getReceiptData());
order.setProductID(dto.getProductId());
order.setTransactionId(dto.getTransactionId());
order.setCustomerOid(dto.getCustomerOid());
order.setOrderStatus(order2.getOrderStatus());
order.setDelFlag(order2.getDelFlag());
order.setCloseOrder(0);
order.setCreateTime(new Date());
order.setFailureflag(dto.getFailureflag());
orderService.saveOrUpdate(order);
String customerid = dto.getCustomerOid();
String subject = "point";
String body = dto.getProductId();
if ("point".equals(subject)) {
// 插入花生币 变动记录
BookBuyConfigEntity bookBuyConfigEntity = this.bookBuyConfigService.getById(Integer.valueOf(body));
String realMoney = bookBuyConfigEntity.getMoney();
Integer money = Integer.valueOf(realMoney);
userService.rechargeHSPoint(Integer.valueOf(customerid), money);
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
transactionDetailsEntity.setUserId(Integer.valueOf(customerid));
transactionDetailsEntity.setChangeAmount(new BigDecimal(money));
transactionDetailsEntity.setOrderType("充值");
transactionDetailsEntity.setRelationId(order.getId());
transactionDetailsEntity.setRemark("充值");
MyUserEntity user = userService.getById(Integer.valueOf(customerid));
BigDecimal peanutCoin = user.getPeanutCoin();
transactionDetailsEntity.setUserBalance(peanutCoin);
transactionDetailsEntity.setUserName(user.getNickname());
transactionDetailsEntity.setTel(user.getTel());
transactionDetailsService.save(transactionDetailsEntity);
// 插入 花生币 充值记录
PayPaymentOrderEntity payPaymentOrderEntity = new PayPaymentOrderEntity();
payPaymentOrderEntity.setUserId(Integer.valueOf(customerid));
payPaymentOrderEntity.setOrderId(order.getTransactionId());
payPaymentOrderEntity.setRealAmount(new BigDecimal(bookBuyConfigEntity.getRealMoney()));
payPaymentOrderEntity.setRechargeAmount(new BigDecimal(bookBuyConfigEntity.getMoney()));
payPaymentOrderEntity.setRechargeChannel(bookBuyConfigEntity.getQudao());
payPaymentOrderEntity.setRechargeStatus("success");
payPaymentOrderEntity.setSuccessTime(new Date());
payPaymentOrderEntity.setUserName(user.getNickname());
payPaymentOrderEntity.setTel(user.getTel());
payPaymentOrderService.save(payPaymentOrderEntity);
buyOrderService.updateOrderStatus(Integer.valueOf(customerid), dto.getOrderId(), "2");
order.setMoney(Integer.valueOf(bookBuyConfigEntity.getRealMoney()));
order.setUsername(user.getName());
orderService.saveOrUpdate(order);
}
orderService.update();
}
IapResponseDTO.AppleOrder appleOrder = receipt.getReceipt().getIn_app()[0];
if (appleOrder.getTransaction_id().equals(dto.getTransactionId()) &&
//p+productid为吴门医述商品单id为疯子读书商品
(appleOrder.getProduct_id().equals(dto.getProductId())||
appleOrder.getProduct_id().equals("p"+dto.getProductId()))) {
System.out.println("开始进入判断3"+appleOrder.getTransaction_id()+"====="+dto.getTransactionId()+"====="+
appleOrder.getProduct_id()+"====="+dto.getProductId());
order.setOrderid(dto.getOrderId());
order.setReceiptData(dto.getReceiptData());
order.setProductID(dto.getProductId());
order.setTransactionId(dto.getTransactionId());
order.setCustomerOid(dto.getCustomerOid());
order.setOrderStatus(order2.getOrderStatus());
order.setDelFlag(order2.getDelFlag());
order.setCloseOrder(0);
order.setCreateTime(new Date());
order.setFailureflag(dto.getFailureflag());
orderService.saveOrUpdate(order);
String customerid = dto.getCustomerOid();
String body = dto.getProductId();
// 插入花生币 变动记录
BookBuyConfigEntity bookBuyConfigEntity = this.bookBuyConfigService.getById(Integer.valueOf(body));
String realMoney = bookBuyConfigEntity.getMoney();
Integer money = Integer.valueOf(realMoney);
userService.rechargeHSPoint(Integer.valueOf(customerid), money);
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
transactionDetailsEntity.setUserId(Integer.valueOf(customerid));
transactionDetailsEntity.setChangeAmount(new BigDecimal(money));
transactionDetailsEntity.setOrderType("充值");
transactionDetailsEntity.setRelationId(order.getId());
transactionDetailsEntity.setRemark("充值");
MyUserEntity user = userService.getById(Integer.valueOf(customerid));
BigDecimal peanutCoin = user.getPeanutCoin();
transactionDetailsEntity.setUserBalance(peanutCoin);
transactionDetailsEntity.setUserName(user.getNickname());
transactionDetailsEntity.setTel(user.getTel());
transactionDetailsService.save(transactionDetailsEntity);
// 插入 花生币 充值记录
PayPaymentOrderEntity payPaymentOrderEntity = new PayPaymentOrderEntity();
payPaymentOrderEntity.setUserId(Integer.valueOf(customerid));
payPaymentOrderEntity.setOrderId(order.getTransactionId());
payPaymentOrderEntity.setRealAmount(new BigDecimal(bookBuyConfigEntity.getRealMoney()));
payPaymentOrderEntity.setRechargeAmount(new BigDecimal(bookBuyConfigEntity.getMoney()));
payPaymentOrderEntity.setRechargeChannel(bookBuyConfigEntity.getQudao());
payPaymentOrderEntity.setRechargeStatus("success");
payPaymentOrderEntity.setSuccessTime(new Date());
payPaymentOrderEntity.setUserName(user.getNickname());
payPaymentOrderEntity.setTel(user.getTel());
payPaymentOrderService.save(payPaymentOrderEntity);
buyOrderService.updateOrderStatus(Integer.valueOf(customerid), dto.getOrderId(), "2");
order.setMoney(Integer.valueOf(bookBuyConfigEntity.getRealMoney()));
order.setUsername(user.getName());
orderService.saveOrUpdate(order);
orderService.update();
return Result.ok0();
}else {
return Result.nook(500,"订单id错误或者商品id");
}
return Result.ok0();
}
return Result.ok("第一次付款成功");
}
return Result.nook(500,"订单加载失败");
} finally {
lock.unlock();
}
}