在管理后台填写你的接口地址,苹果apple会主动通知你
@RestController
@RequestMapping("/api/refund")
public class RefundController {
protected Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
RefundOrderService refundOrderService;
@Autowired
VipOrdrService vipOrdrService;
@Autowired
UserInfoService userInfoService;
@PostMapping("/ios")
public BaseResponse ios(@RequestBody RefundIosDto refundIosDto) {
if(refundIosDto.getNotification_type().equals("REFUND"))//退款
{
logger.info("苹果通知类型:"+refundIosDto.getNotification_type()+"环境:"+refundIosDto.getEnvironment());
logger.info("苹果退款json:"+refundIosDto.toString());
List<LatestReceiptInfo> list=refundIosDto.getUnified_receipt().getLatest_receipt_info();
if(Objects.nonNull(list)&&list.size()>0)
{
LatestReceiptInfo latestReceiptInfo=list.get(0);
if(StringUtils.isNotEmpty(latestReceiptInfo.getProduct_id())&&StringUtils.isNotEmpty(latestReceiptInfo.getOriginal_transaction_id()))
{
}
else {
logger.info("退款失败:订单或商品id为空");
return ReturnResponseUtil.Error(ReturnResponseUtil.BUSSINESS_ERROR, "fail ");
}
RefundOrder refundOrder=new RefundOrder();
refundOrder.setCreatetime(new Date());
refundOrder.setRefundDate(new Date(Long.parseLong(latestReceiptInfo.getCancellation_date_ms())));
refundOrder.setProductId(latestReceiptInfo.getProduct_id());
refundOrder.setOriginalTransactionId(latestReceiptInfo.getOriginal_transaction_id());
refundOrderService.insert(refundOrder);
//查找订单的memberuid
VipOrder vipOrder=vipOrdrService.getOne(latestReceiptInfo.getOriginal_transaction_id(),latestReceiptInfo.getProduct_id(),"ios");
if(Objects.nonNull(vipOrder))
{
//修改会员逻辑
}
}
}
else
logger.info("苹果通知类型,:"+refundIosDto.getNotification_type() );
return ReturnResponseUtil.Error(ReturnResponseUtil.BUSSINESS_ERROR, "success");
}
}
@ApiModel(value="苹果退款通知")
public class RefundIosDto {
private String notification_type;
private String password;
private String environment;
//过期
// private String latest_receipt;
// private Latest_receipt_info latest_receipt_info;
private UnifiedReceipt unified_receipt;
private String bid;
private String bvrs;
}
public class UnifiedReceipt {
private int status;
private String environment;
private List<LatestReceiptInfo> latest_receipt_info;
private String latest_receipt;
}
public class LatestReceiptInfo {
private String quantity;
private String product_id;
private String transaction_id;
private String purchase_date;
private String purchase_date_ms;
private String purchase_date_pst;
private String original_purchase_date;
private String original_purchase_date_ms;
private String original_purchase_date_pst;
private String is_trial_period;
private String original_transaction_id;
private String cancellation_date;
private String cancellation_date_ms;
private String cancellation_date_pst;
private String cancellation_reason;
}