vod callback settings

HTTP form callback) Continued upload a video, you found a problem when Ali goes over there to set up video transcoding, if the upload is complete you immediately go to get video information, the video will return you still can not get video transcoding information, Ali looked callback api write callback, the callback when the video transcoding after the success of data to fill in the video information
to note if you set up a callback URL authorization, he will send two "X-VOD-TIMESTAMP "," X-VOD-SIGNATURE " this is to prevent someone malicious brush your link
URL link authentication api
callback event type api link

on the code:

AliyunVideoUtils.callbackUrl // this is where you set the callback url  
AliyunVideoUtils.privateKey this // let you set your default signature authentication ~ Key
public void callback (@RequestBody String body, Request the HttpServletRequest, HttpServletResponse the Response) {
        the try {
            String = vodTimestamp request.getHeader ( "the X--the VOD-TIMESTAMP"); // UNIX timestamp, a positive number plastic, fixed length 10, the number of seconds since January 1, 1970, represents a callback request to initiate time ~
            String vodSignature = Reques t.getHeader ( "X-VOD-SIGNATURE "); // string signature, a 32-bit MD5 value
            String sign = DigestUtils
                    .md5Hex (AliyunVideoUtils.callbackUrl + "|" + vodTimestamp + "|" + AliyunVideoUtils.privateKey); // spliced together in this form below comparing
            (! sign.equalsIgnoreCase (vodSignature)) if {// this comparison It is to prevent other people through your link brush data
                logger.warn ( "Ali cloud video callback signature is not the VOD-by-TIMESTAMP = the X-{}, the X-sIGNATURE-the VOD-= {}!", vodTimestamp, vodSignature);
            } the else {
                Logger .info ( "Ali cloud video callback: {}", body);
                IF (StringUtils.isNotBlank (body)) {
                    // event is determined, so the event is completed video transcoding, according to acquire video information populate the database videoId
                    Map < string, Object> map = jsonToMap ( body); // this method is to return to the map below json string to this method
                    // ruin the event type event type I have a lot of this is a single video transcoding successful event type is a callback to confirm what type of event by judging EventType reprocessing
                   // Note that he will return to the two events, because there m3u8 and MP4 so I went reduce cycle than in accordance with FileUrl take the suffix
                    if (map.get ( "EventType") . ToString (). EqualsIgnoreCase ( "StreamTranscodeComplete")
                            map.get && ( "Status"). toString (). equalsIgnoreCase ( "Success")
                            && map.get ( "file specified by fileurl"). toString ()
                                    .substring (map.get ( "file specified by fileurl"). toString (). lastIndexOf ( ".") +. 1)
                                    .equalsIgnoreCase ( "MP4")) {
                        String videoId as map.get = ( "VideoId") toString ();.
                        List <CourseVideo> courseVideos = courseVideoService.findByVideoUrl (videoId);
                        if (courseVideos != null && courseVideos.size() > 0) {
                            for (CourseVideo courseVideo: courseVideos) {
                            // After more than a judgment call on my writing tools to get the video information through the transcoded successfully and populate the database
                                GetPlayInfoResponse playInfo = AliyunVideoUtils.getPlayInfo (videoId);
                                IF (playInfo ! = null) {
                                    // courseVideo.setCoverUrl (playInfo.getVideoBase () getCoverURL ());. // I do to cover the first frame but after 3000 seconds so do not fail me into the database is populated with data when controlle take View the video and then when filled to the entity class (I was there in the temporary entity class fields) in
                                    courseVideo.setStatus (CourseVideoStatus.DRAFT.getValue ());
                                    courseVideo.setDuration (
                                            The Integer.parseInt (. PlayInfo.getPlayInfoList () GET (0) .getDuration ()));
                                } the else {
                                    logger.warn ( "Ali cloud not obtain the video information video: {}", "VideoId: " + videoId);
                                }
                            }
                            courseVideoService.save (courseVideos);
                        } the else {
                            logger.warn ( "program with respect to video information is not found, videoId = {}", videoId);
                        }
                    .} the else IF (as map.get ( "the EventType") toString () .equalsIgnoreCase ( "ImageUploadComplete")
                            && map.get ( "Status"). toString ().equalsIgnoreCase("success")) {
                        // Image Upload callback
                    }
                }
            }
        } the catch (Exception E) {
            logger.error ( "Ali cloud internal server error correction processing, the reason {} =", e.getMessage (), E);
            response.setStatus (500);
        }
    }

  / **
     * JSON string transfer the Map <string, Object>
     * /
    public the Map <string, Object> jsonToMap (string JSONString) {
        the JSONObject the JSONObject JSON new new = (JSONString);
        the Map <string, Object> = new new Map the HashMap <String, Object> ();
        @SuppressWarnings ( "rawtypes")
        the Iterator json.keys IT = ();
        the while (it.hasNext ()) {
            String Key = (String) it.next ();
            Object value = json.get(key);
            map.put(key, value);
        }
        return map;
    }

Guess you like

Origin www.cnblogs.com/lykbk/p/erererer2343434343.html