コード例 #1
0
ファイル: CollectionController.php プロジェクト: im286er/ent
 /**
  * 触发关联动作
  *
  * @author young
  * @name 触发关联动作
  * @version 2014.02.12 young
  */
 public function hookAction()
 {
     $collection_id = isset($_REQUEST['__COLLECTION_ID__']) ? trim($_REQUEST['__COLLECTION_ID__']) : '';
     $collectionInfo = $this->_collection->findOne(array('_id' => myMongoId($collection_id), 'project_id' => $this->_project_id));
     if ($collectionInfo != null) {
         try {
             $postDatas = array('__PROJECT_ID__' => $this->_project_id, '__COLLECTION_ID__' => $collection_id);
             $url = $collectionInfo['hook'];
             $hookKey = $collectionInfo['hookKey'];
             $sign = dataSignAlgorithm($postDatas, $hookKey);
             $postDatas['__SIGN__'] = $sign;
             $response = doPost($url, $postDatas);
             if ($response === false) {
                 return $this->msg(false, '网络请求失败');
             }
             $this->_collection->update(array('_id' => myMongoId($collection_id)), array('$set' => array('hookLastResponseResult' => $response)));
             return $this->msg(true, '触发联动操作成功');
         } catch (\Exception $e) {
             return $this->msg(false, $e->getMessage());
         }
     } else {
         return $this->msg(false, '触发联动操作失败');
     }
 }
コード例 #2
0
ファイル: DataController.php プロジェクト: im286er/ent
 /**
  * 对于集合进行了任何操作,那么出发联动事件,联动修改其他集合的相关数据
  * 提交全部POST参数以及系统默认的触发参数__TRIGER__
  * $_POST['__TRIGER__']['collection'] 触发事件集合的名称
  * $_POST['__TRIGER__']['controller'] 触发控制器
  * $_POST['__TRIGER__']['action'] 触发动作
  * 为了确保调用安全,签名方法为所有POST参数按照字母顺序排列,构建的字符串substr(sha1(k1=v1&k2=v2连接密钥),0,32),做个小欺骗,让签名看起来很像MD5的。
  */
 public function __destruct()
 {
     fastcgi_finish_request();
     try {
         $controller = $this->params('controller');
         $action = $this->params('action');
         $_POST['__TRIGER__'] = array('collection' => $this->getCollectionAliasById($this->_collection_id), 'controller' => $controller, 'action' => $action);
         $collectionInfo = $this->_collection->findOne(array('_id' => myMongoId($this->_collection_id), 'isAutoHook' => true));
         if ($collectionInfo !== null && isset($collectionInfo['hook']) && filter_var($collectionInfo['hook'], FILTER_VALIDATE_URL) !== false) {
             $sign = dataSignAlgorithm($_POST, $collectionInfo['hookKey']);
             $_POST['__SIGN__'] = $sign;
             $response = doPost($collectionInfo['hook'], $_POST);
             $this->_collection->update(array('_id' => $collectionInfo['_id']), array('$set' => array('hookLastResponseResult' => $response)));
         }
     } catch (\Exception $e) {
         $this->log(exceptionMsg($e));
     }
     return false;
 }