--微信支付
This commit is contained in:
@@ -0,0 +1,278 @@
|
||||
package com.peanut.modules.pay.IOSPay.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.peanut.common.utils.*;
|
||||
import com.peanut.modules.book.entity.*;
|
||||
import com.peanut.modules.book.service.*;
|
||||
import com.peanut.modules.pay.IOSPay.Result;
|
||||
import com.peanut.modules.pay.IOSPay.constant.VerifyReceiptConstant;
|
||||
import com.peanut.modules.pay.IOSPay.model.dto.IapRequestDTO;
|
||||
import com.peanut.modules.pay.IOSPay.model.dto.IapResponseDTO;
|
||||
import com.peanut.modules.pay.IOSPay.model.entities.IosPayOrderEntity;
|
||||
|
||||
import com.peanut.modules.pay.IOSPay.service.IapVerifyReceiptService;
|
||||
import com.peanut.modules.pay.IOSPay.service.OrderService;
|
||||
import com.peanut.modules.pay.IOSPay.vo.FailureVo;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.experimental.FieldDefaults;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/Ipa")
|
||||
@RequiredArgsConstructor
|
||||
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
|
||||
@Configuration
|
||||
public class AppController {
|
||||
@Autowired
|
||||
IapVerifyReceiptService iapVerifyReceiptService;
|
||||
@Autowired
|
||||
OrderService orderService;
|
||||
@Autowired
|
||||
private MyUserService userService;
|
||||
@Autowired
|
||||
private BookBuyConfigService bookBuyConfigService;
|
||||
@Autowired
|
||||
private TransactionDetailsService transactionDetailsService;
|
||||
@Autowired
|
||||
private PayPaymentOrderService payPaymentOrderService;
|
||||
@Autowired
|
||||
private BuyOrderService buyOrderService;
|
||||
|
||||
|
||||
@RequestMapping(value = "/text", method = RequestMethod.POST)
|
||||
public String verif() {
|
||||
return "test";
|
||||
}
|
||||
|
||||
/**
|
||||
* 苹果内购二次校验
|
||||
*
|
||||
* @param dto 入参: 订单id, 苹果凭证
|
||||
* @return 验证结果
|
||||
*/
|
||||
|
||||
|
||||
@RequestMapping(value = "/veri", method = RequestMethod.POST)
|
||||
public Result verifyIap(@RequestBody IapRequestDTO dto) {
|
||||
|
||||
|
||||
Lock lock = new ReentrantLock();
|
||||
lock.lock();
|
||||
|
||||
try {
|
||||
|
||||
|
||||
System.out.println("==============veri=================================" + dto);
|
||||
// 1. 校验入参
|
||||
if (dto == null)
|
||||
return Result.error("入参不能为空");
|
||||
if (dto.getOrderId().isEmpty()) {
|
||||
return Result.error("订单id不能为空");
|
||||
}
|
||||
if (dto.getProductId().isEmpty()) {
|
||||
return Result.error("订单号不能为空");
|
||||
}
|
||||
if (dto.getTransactionId().isEmpty())
|
||||
return Result.error("内购订单号不能为空");
|
||||
if (dto.getReceiptData().isEmpty())
|
||||
return Result.error("凭证不能为空");
|
||||
|
||||
IapResponseDTO receipt = iapVerifyReceiptService.verifyIapReceipt(dto.getReceiptData(), dto.isSandBox());
|
||||
BuyOrderEntity order2 = this.buyOrderService.getOne(new QueryWrapper<BuyOrderEntity>().eq("order_sn", dto.getOrderId()).eq("del_flag", "0"));
|
||||
order2.setPaymentDate(new Date());
|
||||
System.out.println("============order2=================" + order2);
|
||||
this.buyOrderService.updateById(order2);
|
||||
|
||||
IosPayOrderEntity order = new IosPayOrderEntity();
|
||||
|
||||
//todo 判断状态 订单状态 0-未付款 1-待发货 2-已发货 3-交易成功 4-交易失败
|
||||
System.out.println("============保存中=================" + order);
|
||||
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)) {
|
||||
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)) {
|
||||
// 插入花生币 变动记录
|
||||
System.out.printf("body====:" + body);
|
||||
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("充值");
|
||||
System.out.println("===============进入了point获取ID=========================" + order.getId());
|
||||
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);
|
||||
System.out.println("==========ok================================================================================================================================================");
|
||||
|
||||
|
||||
}
|
||||
orderService.update();
|
||||
System.out.println("==========ok================================================================================================================================================");
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return Result.ok0();
|
||||
}
|
||||
|
||||
return Result.ok("第一次付款成功");
|
||||
|
||||
|
||||
}
|
||||
return Result.nook(500,"订单加载失败");
|
||||
} finally {
|
||||
lock.unlock();
|
||||
|
||||
}
|
||||
// return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
|
||||
@RequestMapping(value = "/failure")
|
||||
// @RequestBody
|
||||
public Result update(@Validated @RequestBody IapRequestDTO vo) {
|
||||
System.out.println("=========entity1111================"+vo);
|
||||
|
||||
IosPayOrderEntity order = new IosPayOrderEntity();
|
||||
|
||||
order.setOrderid(vo.getOrderId());
|
||||
order.setReceiptData(vo.getReceiptData());
|
||||
order.setProductID(vo.getProductId());
|
||||
order.setTransactionId(vo.getTransactionId());
|
||||
System.out.println("=========dto.getTransactionId()============" + vo.getTransactionId());
|
||||
order.setCustomerOid(vo.getCustomerOid());
|
||||
order.setCloseOrder(0);
|
||||
order.setCreateTime(new Date());
|
||||
order.setFailureflag(vo.getFailureflag());
|
||||
System.out.println("============v0===================================================================================="+vo.getFailureflag());
|
||||
orderService.saveOrUpdate(order);
|
||||
System.out.println("=======order================"+order);
|
||||
|
||||
|
||||
|
||||
|
||||
return Result.updateok();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询失败数据接口
|
||||
*/
|
||||
// @Transactional
|
||||
@RequestMapping(value = "/showFailure")
|
||||
public R showFailure(@RequestParam Map<String, Object> params )throws Exception{
|
||||
|
||||
PageUtils pageUtils = orderService.queryPage1(params);
|
||||
|
||||
return R.ok().put("page",pageUtils);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@RequestMapping(value = "/list",method = RequestMethod.GET)
|
||||
public R list(@RequestParam Map<String, Object> params)throws Exception {
|
||||
|
||||
|
||||
PageUtils pageUtils = orderService.queryPage1(params);
|
||||
|
||||
return R.ok().put("page", pageUtils);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user