2020-04-24

[WebEX]XML API

反向取得會議室XML,不過需要重新處理

<?xml version="1.0" encoding="ISO-8859-1"?>
<serv:message
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:serv="http://www.webex.com/schemas/2002/06/service">
    <header>
        <securityContext>
            <webExID>輸入會議室帳號</webExID>
            <password>輸入會議室密碼</password>
           <siteName>輸入站台</siteName>
        </securityContext>
    </header>
    <body>
        <bodyContent xsi:type="java:com.webex.service.binding.meeting.GetMeeting">
            <meetingKey>輸入會議室號碼</meetingKey>
        </bodyContent>
    </body>
</serv:message>

 

 

以為為java sample code

package ext;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.*;

public class CiscoWebEX {
    public String replaceAttendee(HashMap Attendee){
        String stringXML = "";

        for (Object key : Attendee.keySet()) {
            stringXML = stringXML +
                        "<attendee><person>" +
                        "<name>"  + key          + "</name>" +
                        "<email>" + Attendee.get(key) + "</email>" +
                        "</person></attendee>";
        }
        //System.out.println(stringXML);
        return (stringXML);
    }
    
    
    static String replaceConfName(String uuid ,
                                  String webEXSiteName ,
                                  String webEXAccount ,
                                  String webEXPassword ,
                                  String meetingPassword ,
                                  String confName ,
                                  String agenda ,
                                  String maxUserNumber ,
                                  String attendee ,
                                  String startDate ,
                                  String duration)throws IOException{
        String frPath = "D:\\MeetingSample.xml";
        String fwPath = "D:\\Meeting_" + uuid +".xml";
        FileReader fr = new FileReader(frPath);
                
        BufferedReader fbr = new BufferedReader(fr);
        
        String line;
        String newContent = "";
        while((line = fbr.readLine()) != null){
            if (line.contains("{webEXSiteName}")){
                newContent = newContent + line.replace("{webEXSiteName}", webEXSiteName )+"\n";
            }else if (line.contains("{webEXAccount}")) {
                newContent = newContent + line.replace("{webEXAccount}", webEXAccount )+"\n";
            }else if (line.contains("{webEXPassword}")) {
                newContent = newContent + line.replace("{webEXPassword}", webEXPassword )+"\n";
            }else if (line.contains("{meetingPassword}")) {
                newContent = newContent + line.replace("{meetingPassword}", meetingPassword )+"\n";
            }else if (line.contains("{confName}")) {
                newContent = newContent + line.replace("{confName}", confName )+"\n";
            }else if (line.contains("{agenda}")) {
                newContent = newContent + line.replace("{agenda}", agenda )+"\n";
            }else if (line.contains("{maxUserNumber}")) {
                newContent = newContent + line.replace("{maxUserNumber}", maxUserNumber )+"\n";
            }else if (line.contains("{attendee}")) {
                newContent = newContent + line.replace("{attendee}", attendee )+"\n";
            }else if (line.contains("{startDate}")) {
                newContent = newContent + line.replace("{startDate}", startDate )+"\n";
            }else if (line.contains("{duration}")) {
                newContent = newContent + line.replace("{duration}", duration )+"\n";
            }else{
                newContent = newContent + line;
            }
            
        }
        
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(fwPath)));
        bw.write(newContent);
        fr.close();
        fbr.close();
        bw.close();
        return "OK";
    }
    
    //public static void main(String[] args) throws Exception{
    public String sendXMLPost(String webEXSiteName ,
                              String webEXAccount ,
                              String webEXPassword ,
                              String meetingPassword ,
                              String confName ,
                              String agenda ,
                              String maxUserNumber ,
                              String attendee ,
                              String startDate ,
                              String duration) throws Exception{
        String uuid = UUID.randomUUID().toString();
        //System.out.println(uuid);
        
        HashMap map = new HashMap();
        map.put("Yulin", "Yulin@gmail.com");
        map.put("firm-pd-tatung04@mail.taipei.gov.tw", "firm-pd-tatung04@mail.taipei.gov.tw");
        map.put("firm-pd-tatung38@mail.taipei.gov.tw", "firm-pd-tatung38@mail.taipei.gov.tw");
        
        String StringAttendee = replaceAttendee(map);
        replaceConfName(uuid ,
                        webEXSiteName ,
                        webEXAccount ,
                        webEXPassword ,
                        meetingPassword ,
                        confName ,
                        agenda ,
                        maxUserNumber ,
                        attendee ,
                        startDate ,
                        duration);
        String urlString = "https://api.webex.com/WBXService/XMLService";
        URL url = new URL(urlString);
        HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();

        String xmlFile = "D:\\Meeting_" + uuid +".xml";
        File fileToSend = new File(xmlFile);
        byte[] buf = new byte[(int) fileToSend.length()];
        
        
        new FileInputStream(xmlFile).read(buf);

        httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
        httpConn.setRequestMethod("POST");
        httpConn.setDoOutput(true);
        httpConn.setDoInput(true);

        OutputStream out = httpConn.getOutputStream();

        out.write(buf);
        out.close();

        if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK){
            InputStreamReader is = new InputStreamReader(httpConn.getInputStream());
            BufferedReader in = new BufferedReader(is);
            String inputLine;
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream("result.xml")));
            while ((inputLine = in.readLine()) != null)
            {
                //System.out.println(inputLine);
                bw.write(inputLine);
                bw.newLine();
            }
            bw.close();
            in.close();
            httpConn.disconnect();
            return "OK";
        }else{
            InputStream is = httpConn.getErrorStream();
            InputStreamReader isr = new InputStreamReader(is,"utf-8");
            BufferedReader in = new BufferedReader(isr);
            String inputLine;
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream("result.xml")));
            while ((inputLine = in.readLine()) != null)
            {
                //System.out.println(inputLine);
                bw.write(inputLine);
                bw.newLine();
                bw.close();
            }
            in.close();
            httpConn.disconnect();
            return "ERROR";
        }
        //httpConn.disconnect();
    }
}

 

 

 

<?xml version="1.0" encoding="UTF-8"?>
<serv:message
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <header>
        <securityContext>
            <siteName>{webEXSiteName}</siteName>
            <webExID>{webEXAccount}</webExID>
            <password>{webEXPassword}</password>
        </securityContext>
    </header>
    <body>
        <bodyContent
            xsi:type="java:com.webex.service.binding.meeting.CreateMeeting">
            <accessControl>
                <isPublic>false</isPublic>
                <meetingPassword>{meetingPassword}</meetingPassword>
            </accessControl>
            <metaData>
                <confName>{confName}</confName>
                <agenda>{agenda}</agenda>
            </metaData>
            <participants>
                <maxUserNumber>{maxUserNumber}</maxUserNumber>
                <attendees>
                    {attendee}
                </attendees>
            </participants>
            <enableOptions>
                <chat>true</chat>
                <poll>true</poll>
                <audioVideo>true</audioVideo>
                <attendeeList>true</attendeeList>
                <fileShare>true</fileShare>
                <presentation>true</presentation>
                <applicationShare>true</applicationShare>
                <desktopShare>true</desktopShare>
                <webTour>true</webTour>
                <meetingRecord>false</meetingRecord>
                <annotation>false</annotation>
                <importDocument>false</importDocument>
                <saveDocument>false</saveDocument>
                <printDocument>false</printDocument>
                <pointer>false</pointer>
                <switchPage>false</switchPage>
                <fullScreen>false</fullScreen>
                <thumbnail>false</thumbnail>
                <zoom>false</zoom>
                <copyPage>false</copyPage>
                <rcAppShare>true</rcAppShare>
                <rcDesktopShare>true</rcDesktopShare>
                <rcWebTour>true</rcWebTour>
                <javaClient>false</javaClient>
                <nativeClient>false</nativeClient>
                <autoRecord>true</autoRecord>
                <attendeeRecordMeeting>false</attendeeRecordMeeting>
                <voip>true</voip>
                <faxIntoMeeting>false</faxIntoMeeting>
                <enableReg>false</enableReg>
                <supportQandA>true</supportQandA>
                <supportFeedback>true</supportFeedback>
                <supportBreakoutSessions>false</supportBreakoutSessions>
                <supportPanelists>false</supportPanelists>
                <supportRemoteComputer>true</supportRemoteComputer>
                <supportShareWebContent>true</supportShareWebContent>
                <supportUCFWebPages>true</supportUCFWebPages>
                <supportUCFRichMedia>true</supportUCFRichMedia>
                <autoDeleteAfterMeetingEnd>false</autoDeleteAfterMeetingEnd>
                <viewAnyDoc>false</viewAnyDoc>
                <viewAnyPage>false</viewAnyPage>
                <allowContactPrivate>false</allowContactPrivate>
                <chatHost>true</chatHost>
                <chatPresenter>true</chatPresenter>
                <chatAllAttendees>true</chatAllAttendees>
                <!--<multiVideo>true</multiVideo>-->
                <notes>true</notes>
                <closedCaptions>false</closedCaptions>
                <singleNote>false</singleNote>
                <sendFeedback>false</sendFeedback>
                <displayQuickStartHost>true</displayQuickStartHost>
                <displayQuickStartAttendees>false</displayQuickStartAttendees>
                <supportE2E>false</supportE2E>
                <supportPKI>false</supportPKI>
                <!--<HQvideo>true</HQvideo>-->
                <HDvideo>false</HDvideo>
                <viewVideoThumbs>true</viewVideoThumbs>
            </enableOptions>
            <schedule>
                <startDate>{startDate}</startDate>
                <timeZoneID>48</timeZoneID>
                <timeZone>GMT+08:00, Taipei (Hong Kong)</timeZone>
                <duration>{duration}</duration>
                <openTime>900</openTime>
                <hostWebExID>firm-pd-tatung38@mail.taipei.gov.tw</hostWebExID>
                <templateFilePath></templateFilePath>
                <showFilePath></showFilePath>
                <showFileStartMode>true</showFileStartMode>
                <showFileContPlayFlag>false</showFileContPlayFlag>
                <showFileInterVal>30</showFileInterVal>
                <entryExitTone>2</entryExitTone>
                <extNotifyTime>0</extNotifyTime>
                <joinTeleconfBeforeHost>false</joinTeleconfBeforeHost>
                <firstAttendeeAsPresenter>true</firstAttendeeAsPresenter>
                <allowAnyoneHostMeeting>false</allowAnyoneHostMeeting>
            </schedule>
            <repeat>
                <repeatType>NO_REPEAT</repeatType>
            </repeat>
            <remind>
                <enableReminder>true</enableReminder>
                <emails>
                    <email>firm-pd-tatung38@mail.taipei.gov.tw</email>
                </emails>
                <sendEmail>true</sendEmail>
                <sendMobile>false</sendMobile>
                <daysAhead>0</daysAhead>
                <hoursAhead>0</hoursAhead>
                <minutesAhead>15</minutesAhead>
            </remind>
            <attendeeOptions>
                <request>false</request>
                <registration>false</registration>
                <auto>false</auto>
                <participantLimit>0</participantLimit>
                <excludePassword>false</excludePassword>
                <joinRequiresAccount>false</joinRequiresAccount>
                <emailInvitations>true</emailInvitations>
            </attendeeOptions>
        </bodyContent>
    </body>
</serv:message>

 

 

 

 

加解密

package ext;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Base64;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

public class AES {
    private static SecretKeySpec secretKey;
    private static byte[] key;

    public static void setKey(String myKey) {
        MessageDigest sha = null;
        try {
            key = myKey.getBytes("UTF-8");
            sha = MessageDigest.getInstance("SHA-1");
            key = sha.digest(key);
            key = Arrays.copyOf(key, 16);
            secretKey = new SecretKeySpec(key, "AES");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    public static String encrypt(String strToEncrypt, String secret) {
        try {
            setKey(secret);
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
            cipher.init(Cipher.ENCRYPT_MODE, secretKey);
            return Base64.getEncoder().encodeToString(cipher.doFinal(strToEncrypt.getBytes("UTF-8")));
        } catch (Exception e) {
            System.out.println("Error while encrypting: " + e.toString());
        }
        return null;
    }

    public static String decrypt(String strToDecrypt, String secret) {
        try {
            setKey(secret);
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
            cipher.init(Cipher.DECRYPT_MODE, secretKey);
            return new String(cipher.doFinal(Base64.getDecoder().decode(strToDecrypt)));
        } catch (Exception e) {
            System.out.println("Error while decrypting: " + e.toString());
        }
        return null;
    }
    /*
    public static void main(String[] args) {
        final String secretKey = "Taipei";

        String originalString = "test@sdfasdf";
        String encryptedString = AES.encrypt(originalString, secretKey);
        String decryptedString = AES.decrypt(encryptedString, secretKey);

        System.out.println(originalString);
        System.out.println(encryptedString);
        System.out.println(decryptedString);
    }
    */
}

沒有留言:

張貼留言