伸手系列-苹果apple退款-java

在管理后台填写你的接口地址,苹果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;
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值