google内购-订阅模式

1.订单有变化接收google推送的接口,据此可以实现续订订单

/**
	 * 接收google推送接口
	 * @param body
	 * @param request
	 * @param response
	 * @return
	 */
	@ApiOperation(value = "google回调接口", notes = "google回调接口")
	 @RequestMapping(value = "googleNotify")
	    public String googleNotify(@RequestBody(required = false) byte[] body,HttpServletRequest request, HttpServletResponse response) {
	        logger.info("googleNotify==【google play 实时开发通知入口.......】");
	        String paramStr = null;
	            try {
	                //获取返回的内容,是一个字节数组
	                paramStr = new String(body, "utf-8");
	                //回调具体内容见下方
	                logger.info("googleNotify== params:"+paramStr);
	                googleService.googleNotify(paramStr);
	            } catch (Exception e) {
	                e.printStackTrace();
	            }
	        return "0";
	    }



@Override
    @Transactional(rollbackFor = Exception.class)
    public void googleNotify(String paramStr) {
        if (StringUtils.isNotBlank(paramStr)){
            JSONObject paramJson = new JSONObject();
            try {
                paramJson = JSONObject.parseObject(URLDecoder.decode(paramStr,"utf-8"));
                /**
                 * paramJson数据格式如下
                 * "message": {
                 *         "data": "ewogICAgInZlcnNpb24iOiAiMS4wIiwKICAgICJwYWNrYWdlTmFtZSI6ICLljIXlkI0iLAogICAgImV2ZW50VGltZU1pbGxpcyI6ICLml7bpl7TmiLMo5q+r56eSKSIsCiAgICAic3Vic2NyaXB0aW9uTm90aWZpY2F0aW9uIjogewogICAgICAgICJ2ZXJzaW9uIjogIjEuMCIsCiAgICAgICAgIm5vdGlmaWNhdGlvblR5cGUiOiA0LAogICAgICAgICJwdXJjaGFzZVRva2VuIjogIuaUr+S7mOS7pOeJjCIsCiAgICAgICAgInN1YnNjcmlwdGlvbklkIjogIuiuoumYheeahOWVhuWTgWlkIgogICAgfQp9",
                 *         "messageId": "消息id",
                 *         "message_id": "消息id",
                 *         "publishTime": "2019-11-14T03:58:43.608Z",
                 *         "publish_time": "2019-11-14T03:58:43.608Z"
                 *     },
                 */
                JSONObject msgJson = paramJson.getJSONObject("message");
                String data = msgJson.getString("data");
                logger.info("googleNotify data :"+paramStr);
                //data 是由base64加密,解密即可
                String developerNotificationStr = new String(Base64.getDecoder().decode(data), "UTF-8");
                JSONObject developerNotificationJson = JSONObject.parseObject(developerNotificationStr);
                /**
                 * developerNotificationJson数据格式如下
                 * subscriptionNotification订阅类型
                 * oneTimeProductNotification一次性类型
                 *  {
                 *      "version":"1.0",
                 *       "packageName":"包名",
                 *       "eventTimeMillis":"时间戳(毫秒)",
                 *       "subscriptionNotification":{
                 *          "version":"1.0",
                 *          "notificationType":4,
                 *          "purchaseToken":"支付令牌",
                 *          "subscriptionId":"订阅的商品id"
                 *      }
                 *  }
                 */
                String packageName = developerNotificationJson.getString("packageName");
                JSONObject subscriptionNotificationJson = developerNotificationJson.getJSONObject("subscriptionNotification");
                logger.info("订阅后的收到的通知信息"+subscriptionNotificationJson.toJSONString());
                String purchaseToken = subscriptionNotificationJson.getString("purchaseToken");
                String subscriptionId = subscriptionNotificationJson.getString("subscriptionId");
                /**
                 * subscriptionNotification订阅类型
                 * notificationType    int
                 * 通知的类型。它可以具有以下值:
                 * (1) SUBSCRIPTION_RECOVERED - 从帐号保留状态恢复了订阅。
                 * (2) SUBSCRIPTION_RENEWED - 续订了处于活动状态的订阅。
                 * (3) SUBSCRIPTION_CANCELED - 自愿或非自愿地
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值