msn机器人删除联系人的函数

来源:互联网 发布:ubuntu 16.04 ip配置 编辑:程序博客网 时间:2024/06/10 05:33

这个函数可以删除,但是你必须找到对应Email的contactid,最下面是取得这个id函数

 

/**
  * @name 删除联系人
  * @param $email被删除的email
  * @return 成功:true,失败:false
  * @example
  */
 function delContact($email)
 {
  //if ($network != 1) return true;
  // add contact for WLM
  $ticket = htmlspecialchars($this->contact_ticket);

  $contactid = $this->_getFriendContactId($email);
  if(empty($contactid) || '' == $contactid) return false;
  $XML = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema"
               xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Header>
    <ABApplicationHeader xmlns="http://www.msn.com/webservices/AddressBook">
        <ApplicationId>CFE80F9D-180F-4399-82AB-413F33A1FA11</ApplicationId>
        <IsMigration>false</IsMigration>
        <PartnerScenario>ContactSave</PartnerScenario>
    </ABApplicationHeader>
    <ABAuthHeader xmlns="http://www.msn.com/webservices/AddressBook">
        <ManagedGroupRequest>false</ManagedGroupRequest>
        <TicketToken>'.$ticket.'</TicketToken>
    </ABAuthHeader>
</soap:Header>
<soap:Body>
    <ABContactDelete xmlns="http://www.msn.com/webservices/AddressBook">
        <abId>00000000-0000-0000-0000-000000000000</abId>
        <contacts>
                <Contact>
                    <contactId>
                        '.$contactid.'
                    </contactId>
                </Contact>
            </contacts>      
      
        <options>
            <EnableAllowListManagement>true</EnableAllowListManagement>
        </options>
    </ABContactDelete>
</soap:Body>
</soap:Envelope>';

  $header_array = array(
  'SOAPAction: '.$this->delcontact_soap,
  'Content-Type: text/xml; charset=utf-8',
  'User-Agent: MSN Explorer/9.0 (MSN 8.0; TmstmpExt)'
  );

  $this->debug_message("*** del URL: $this->delcontact_url");
  $this->debug_message("*** del Sending SOAP:/n$XML");
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, $this->delcontact_url);
  curl_setopt($curl, CURLOPT_HTTPHEADER, $header_array);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
  if ($this->debug) curl_setopt($curl, CURLOPT_HEADER, 1);
  curl_setopt($curl, CURLOPT_POST, 1);
  curl_setopt($curl, CURLOPT_POSTFIELDS, $XML);
  $data = curl_exec($curl);
  $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  curl_close($curl);
  $this->debug_message("*** del Get Result:/n$data");

  if ($http_code != 200) {
   preg_match('#<faultcode>(.*)</faultcode><faultstring>(.*)</faultstring>#', $data, $matches);
   if (count($matches) == 0) {
    $this->log_message("*** can't del contact (contactid: $contactid) $email");
    return false;
   }
   $faultcode = trim($matches[1]);
   $faultstring = trim($matches[2]);
   $this->log_message("*** can't del contact (contactid: $contactid) $email, error code: $faultcode, $faultstring");
   return false;
  }
  $this->log_message("*** del contact (contactid: $contactid) $email");


  return true;
 }

 

 

 


 /**
  * @name 取得好友的联系id
  * @param $findemail 对应的contactid
  * @return 成功:返回$findemail 对应的contactid,失败:''
  * @example
  */
 function _getFriendContactId($findemail){
  $ret = '';
  //SOAP请求包
  $XML=' <soap:Envelope xmlns:soap=/'http://schemas.xmlsoap.org/soap/envelope//'
                    xmlns:xsi=/'http://www.w3.org/2001/XMLSchema-instance/'
                 xmlns:xsd=/'http://www.w3.org/2001/XMLSchema/'
                 xmlns:soapenc=/'http://schemas.xmlsoap.org/soap/encoding//'>
                    <soap:Header>
                        <ABApplicationHeader xmlns=/'http://www.msn.com/webservices/AddressBook/'>
                    <ApplicationId>CFE80F9D-180F-4399-82AB-413F33A1FA11</ApplicationId>
                    <IsMigration>false</IsMigration>
                    <PartnerScenario>Initial</PartnerScenario>
                   </ABApplicationHeader>
                   <ABAuthHeader xmlns=/'http://www.msn.com/webservices/AddressBook/'>
                    <ManagedGroupRequest>false</ManagedGroupRequest>
                    <TicketToken>'.htmlspecialchars($this->contact_ticket).'</TicketToken>
                   </ABAuthHeader>
                    </soap:Header>
                 <soap:Body>
                   <ABFindAll xmlns=/'http://www.msn.com/webservices/AddressBook/'>
                    <abId>00000000-0000-0000-0000-000000000000</abId>
                    <abView>Full</abView>
                    <deltasOnly>false</deltasOnly>
                    <lastChange>0001-01-01T00:00:00.0000000-08:00</lastChange>
                   </ABFindAll>
                    </soap:Body>
                </soap:Envelope>';
  $header_array = array(
  'SOAPAction: http://www.msn.com/webservices/AddressBook/ABFindAll',
  'Content-Type: text/xml; charset=utf-8',
  'Cookie: MSPAuth=Removed',
  'Host: contacts.msn.com'
  );

  //发送SOAP请求
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL,$this->addcontact_url);
  curl_setopt($curl, CURLOPT_HTTPHEADER, $header_array);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
  if ($this->debug) curl_setopt($curl, CURLOPT_HEADER, 1);
  curl_setopt($curl, CURLOPT_POST, 1);
  curl_setopt($curl, CURLOPT_POSTFIELDS, $XML);
  $data = curl_exec($curl);
  $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  curl_close($curl);
  $this->debug_message("*** find Get Result:/n$data");

  if ($http_code != 200) return false;

  //将回应包转换为对象
  $start = strpos($data, '<contacts>');
  $end = strpos($data, '</contacts>');
  $start+=10;
  $result=substr($data,$start,$end-$start);
  $this->debug_message("*** find Get contacts Result:/n$result");
  //print_r($result);
  $result=simplexml_load_string("<?xml version='1.0'?><document>".$result."</document>");

  $this->debug_message("*** find Get contacts is array Result:/n".is_array($result->Contact));
  $this->debug_message("*** find email Result:/n $findemail");
  //获取联系人信息
  //if (is_array($result->Contact)){

  foreach($result->Contact as $contact){
   $contactid = $contact->contactId;
   $info=$contact->contactInfo;
   //print_r($info);

   //自己,不加入联系人中
   if($info->contactType=='Me')continue;

   //获取EMAIL地址
   if(isset($info->passportName)){
    $email=$info->passportName;
   }elseif(isset($info->emails)&&isset($info->emails->ContactEmail)){
    if(is_array($info->emails->ContactEmail)){
     $email=$info->emails->ContactEmail[0]->email;
    }else{
     $email=$info->emails->ContactEmail->email;
    }
   }
   $this->debug_message("*** find Get contacts Result:/n$email == $findemail");
   if($email == $findemail){
    $ret = htmlspecialchars((string)$contactid,ENT_QUOTES);
    $this->debug_message("*** find id:/n $ret");
    return $ret;
   }
  }
  //}
  return $ret;
 }

原创粉丝点击