腾讯云点播回调解决方案

腾讯云点播通过HTTP请求将通知消息POST到您所配置的通知接口,用户通知接口收到的HTTP POST请求BODY示例。例如,媒资转码成功时通知接口示例如下:

{ "messageId": "319519d9-722c-44ea-a352-3ea88fc2696c", "messageBody": "{"mediaId":"mda-hdnrx2nnwx45w0wf","status":"PUBLISHED","attributes":{"title":"vod_test.mp4","description":"","sourceExtension":"mp4"},"meta":{"sourceSizeInBytes":6408195,"durationInSeconds":25,"sizeInBytes":8286486},"publishTime":"2017-04-13T07:45:36Z","createTime":"2017-04-13T07:45:12Z","playableUrlList":[{"transcodingPresetName":"test_1","url":"http://gcikci7rzd3nstav8xw.exp.bcevod.com/mda-hdnrx2nnwx45w0wf/test1/mda-hdnrx2nnwx45w0wf.mp4","meta":{"sizeInBytes":626688,"durationInSeconds":25,"bitRateInBps":199680,"frameRate":30.0,"widthInPixel":320,"heightInPixel":180}},{"transcodingPresetName":"testtest","url":"http://gcikci7rzd3nstav8xw.exp.bcevod.com/mda-hdnrx2nnwx45w0wf/testtest/mda-hdnrx2nnwx45w0wf.mp4","meta":{"sizeInBytes":624640,"durationInSeconds":25,"bitRateInBps":199680,"frameRate":30.0,"widthInPixel":480,"heightInPixel":270}},{"transcodingPresetName":"test_2","url":"http://gcikci7rzd3nstav8xw.exp.bcevod.com/mda-hdnrx2nnwx45w0wf/test2/mda-hdnrx2nnwx45w0wf.mp4","meta":{"sizeInBytes":625664,"durationInSeconds":25,"bitRateInBps":199680,"frameRate":30.0,"widthInPixel":480,"heightInPixel":270}}],"thumbnailList":["http://gcikci7rzd3nstav8xw.exp.bcevod.com/mda-hdnrx2nnwx45w0wf/mda-hdnrx2nnwx45w0wf.jpg"],"transcodingPresetGroupName":"test"}", "notification": "notification_test", "server": "vod.baidubce.com", "subscriptionName": "ntf-hdnrd5t443umxk2d", "version": "v0.1", "signature": "vod"}

腾讯云点播通过增加字段提供回调信息,客户端需要用户自己实现回调解析。伴随腾讯云点播持续升级,更多、更丰富的回调信息需要解析,所以用户需要对字段的不断增加做好足够的兼容准备。

针对以上问题,我们提供了两种主流语言的解析示例代码,请根据实际情况参考使用:

Java

如果客户端是Java实现,并且是通过Jackson框架来转换json,那么只需要在新建ObjectMapper对象之后,给ObjectMapper修改配置信息如下:

objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

这句话的意思表示,在解析对象的时候,不考虑unkown properties的错误,可以防止因字段发生变化而引起的宕机。接着可以使用objectMapper使用readValue实现json和bean之间的转换。

objectMapper.readValue(jsonStr, Media.class);

详细的Java回调示例,请参考demo-callback-java。

PHP

如果客户端是php实现,可以遍历messageBody的json字符串,并转换为array,打印出来关键媒资信息。

详细的PHP回调示例,请参考demo-callback-php。

标签