欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

没有ews,如何把其他系统的calendar同步到exchange?(2)

更新时间: 2014-01-05 03:03:38 责任编辑: Author_N1

 

没有EWS,怎么把其他系统的Calendar同步到Exchange?(2)
import groovyx.net.http.*

class ExchangeSyncService {

    static transactional = true
    
    static DOMAIN = 'my-domain'
    static CTMS_SYNC_USERNAME = 'usr'
    static CTMS_SYNC_PASSWORD = 'pwd'

    static HTTP_BUILDER_POOL = [:]
    private static getHttpBuilder(username) {
        HTTP_BUILDER_POOL[username] ?: ( HTTP_BUILDER_POOL[username] = new HTTPBuilder( "https://webmail.${DOMAIN}.com" ) )
    }

    def sendAppointment(params) {
        def username = CTMS_SYNC_USERNAME, password = CTMS_SYNC_PASSWORD
        _login(username, password)
        getHttpBuilder(username).post( path: "/Exchange/${username}/日历", body: getAppointmentBody(params)) {res->
            println res.statusLine.statusCode
        }
    }

    def saveTask(params) {
        def username = params.session.user?.username, password = params.session.user?.password
        _login(username, password)
        getHttpBuilder(username).post( path: "/Exchange/${username}/任务", body: getTaskBody(params)) {res->
            println res.statusLine.statusCode
        }
    }

    private _login(username, password) {
        getHttpBuilder(username).post(
          path: '/exchweb/bin/auth/owaauth.dll',
          body: [destination:"https://webmail.${DOMAIN}.com/Exchange",
            flags:'0',
            username:"${DOMAIN}/${username}",
            password:password]
          ) {res->
          if( res.statusLine.statusCode == 302 ) {
            println "${username} logged in to exchange server successfully."
          }
        }
    }

    private getAppointmentBody(m) {
        [
"Cmd": "sendappt",
"CmdReferring": "new",
"Embedded": "0",
"FORMTYPE": "appointment",
"Importance": "2",
"Optional": m.optional,//"sam.ds.chen@gmail.com; somebody@grs-cro.com",
"ReadForm": "1",
"Required": m.required,//"sachen@grs-cro.com",
"Resource": m.resource,//"sam.ds.chen@hotmail.com",
"urn:schemas:calendar:alldayevent": "1",
"urn:schemas:calendar:busystatus": "BUSY",
"urn:schemas:calendar:dtend": m.dtend,//"2011-09-21T16:00:00.000Z", //bug:总是用Exchange服务器所在的美国时区
"urn:schemas:calendar:dtstart": m.dtstart,//"2011-09-21T15:30:00.000Z", //bug:总是用Exchange服务器所在的美国时区
"urn:schemas:calendar:location": "",
"urn:schemas:calendar:reminderoffset": m.reminderoffset,//"900",
"urn:schemas:calendar:responserequested": "0",
"urn:schemas:httpmail:importance": "1",
"urn:schemas:httpmail:subject": m.subject,//"(sent by ctmssync)",
"urn:schemas:httpmail:textdescription": "Accept it to get it on your calendar"
          ]
    }

    private getTaskBody(m) {
        [
"Cmd": "savetask",
"CmdReferring": "new",
"Embedded": "0",
"FORMTYPE": "task",
"MsgClass": "IPM.Task",
"ReadForm": "1",
"SENDUPDATE": "0",
"exception": "",
"http://schemas.microsoft.com/exchange/tasks/percentcomplete": "0",
"http://schemas.microsoft.com/exchange/tasks/resetreminder": "",
"http://schemas.microsoft.com/mapi/reminderset": "1",
"task_due": m.task_due,//"2011-08-04T00:00:00.000Z",
"task_remindertime": m.remindertime,//"2011-10-06T08:00:00.000Z",
"task_start": m.task_start,//"2011-10-04T00:00:00.000Z",
"task_status": "0",
"urn:schemas:httpmail:importance": "1",
"urn:schemas:httpmail:subject": m.subject,//"Title_2",
"urn:schemas:httpmail:textdescription": "This is a task created by SmartCTMS on behalf of you"
          ]
    }
} 
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 03:03:38
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/17833/
本文WWW.DOC100.NET DOC100.NET版权所有。