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 - 自愿或非自愿地