首页 > 代码库 > 脚本转移

脚本转移

//1.主函数
/**
    * 通过API更新模板内容
    * @tpl_id int 模板ID
    * @return bool
    */
    function updateTemplateByAPI($tpl_id) {

        $data = $this->getTemplateByAPI($tpl_id);    //JUMP02 liyuhs

        if ($data == false || !is_array($data) || count($data) == 0) return;

        $data[‘tpl_name‘] = $data[‘name‘];
        $data[‘subject_check‘] = $this->_getSensitiveWord($data[‘subject‘]);
        $data[‘sender_nickname_check‘] = $this->_getSensitiveWord($data[‘sender_nickname‘]);
        $data[‘content_check‘] = $this->_getSensitiveWord(str_replace(array(‘,‘, "\n", "\r", ‘ ‘), array(‘,‘,‘‘,‘‘,‘‘), preg_replace(‘~<[^>]+>~‘, ‘‘, $data[‘content‘])));

        $id = $this->db->getvalue("SELECT id FROM {$this->tablepre}project_task_tpl WHERE tpl_id=‘$tpl_id‘");
        if ($id) $this->update(‘project_task_tpl‘,$data," WHERE id=‘$id‘");
        else $this->add(‘project_task_tpl‘,$data);

        return true;
    }

 





  /*
* * 通过API接口获取模板信息 * @tpl_id int 模板ID * @return array */ function getTemplateByAPI($tpl_id) { if ($tpl_id < 1) return array(); $api = $this->initAPI(); if ($api == false) return array(); $ch = $this->initCurl(); $post_data = array(); $post_data[‘id‘] = $tpl_id; // 必须项, 模板id $sign = md5($api[‘encrypt_key‘] . http_build_query($post_data)); $url = $api[‘api_url_prefix‘].‘tpl.php?do=getInfo&client_id=‘.$api[‘client_id‘].‘&sign=‘.$sign; curl_setopt($ch,CURLOPT_POST,true); curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data); curl_setopt($ch,CURLOPT_URL,$url); $content = curl_exec($ch); if(curl_errno($ch)!=CURLE_OK) { echo "\ndoing>>>>>do gettemplatebyapi,curl error:".curl_errno($ch).",tpl_id:".$tpl_id; curl_close($ch);return; } curl_close($ch); $mp = json_decode($content,true); if ($mp[‘code‘] > 1) return $mp[‘message‘]; $mp[‘data‘][‘tpl_id‘] = $mp[‘data‘][‘id‘]; unset($mp[‘data‘][‘id‘]); return $mp[‘data‘]; }

 

脚本转移