/test/class/webhook.class.php

https://github.com/easysoft/zentaopms · PHP · 473 lines · 220 code · 71 blank · 182 comment · 34 complexity · be4157ade7510b3202db183f3b1d18cf MD5 · raw file

  1. <?php
  2. class webhookTest
  3. {
  4. public function __construct()
  5. {
  6. global $tester;
  7. $this->objectModel = $tester->loadModel('webhook');
  8. }
  9. /**
  10. * Get by ID Test
  11. *
  12. * @param int mixed $id
  13. * @access public
  14. * @return array
  15. */
  16. public function getByIDTest($id)
  17. {
  18. $objects = $this->objectModel->getByID($id);
  19. if(dao::isError()) return dao::getError();
  20. return $objects;
  21. }
  22. /**
  23. * Get by type Test
  24. *
  25. * @param string mixed $type
  26. * @access public
  27. * @return array
  28. */
  29. public function getByTypeTest($type)
  30. {
  31. $objects = $this->objectModel->getByType($type);
  32. if(dao::isError()) return dao::getError();
  33. return $objects;
  34. }
  35. /**
  36. * Get bind account Test
  37. *
  38. * @param int mixed $webhookID
  39. * @param string mixed $webhookType
  40. * @param int mixed $openID
  41. * @access public
  42. * @return string
  43. */
  44. public function getBindAccountTest($webhookID, $webhookType, $openID)
  45. {
  46. $objects = $this->objectModel->getBindAccount($webhookID, $webhookType, $openID);
  47. if(dao::isError()) return dao::getError();
  48. return $objects;
  49. }
  50. /**
  51. * Get list Test
  52. *
  53. * @param string $orderBy
  54. * @param int mixed $pager
  55. * @param bool mixed $decode
  56. * @access public
  57. * @return array
  58. */
  59. public function getListTest($orderBy = 'id_desc', $pager = null, $decode = true)
  60. {
  61. $objects = $this->objectModel->getList($orderBy, $pager, $decode);
  62. if(dao::isError()) return dao::getError();
  63. return $objects;
  64. }
  65. /**
  66. * Get log list Test
  67. *
  68. * @param int mixed $id
  69. * @param string $orderBy
  70. * @param int mixed $pager
  71. * @access public
  72. * @return array
  73. */
  74. public function getLogListTest($id, $orderBy = 'date_desc', $pager = null)
  75. {
  76. $objects = $this->objectModel->getLogList($id, $orderBy, $pager);
  77. if(dao::isError()) return dao::getError();
  78. return $objects;
  79. }
  80. /**
  81. * Get data list Test
  82. *
  83. * @access public
  84. * @return array
  85. */
  86. public function getDataListTest()
  87. {
  88. global $tester;
  89. $objects = $this->objectModel->getDataList();
  90. if(dao::isError()) return dao::getError();
  91. return $objects;
  92. }
  93. /**
  94. * Get bound users Test
  95. *
  96. * @param int mixed $webhookID
  97. * @param array $users
  98. * @access public
  99. * @return int
  100. */
  101. public function getBoundUsersTest($webhookID, $users = array())
  102. {
  103. $objects = $this->objectModel->getBoundUsers($webhookID, $users);
  104. if(dao::isError()) return dao::getError();
  105. return $objects;
  106. }
  107. public function createTest($webhooks)
  108. {
  109. $posts = array();
  110. $posts['type'] = '';
  111. $posts['name'] = '';
  112. $posts['url'] = '';
  113. $posts['secret'] = '';
  114. $posts['agentId'] = '';
  115. $posts['appKey'] = '';
  116. $posts['appSecret'] = '';
  117. $posts['wechatCorpId'] = '';
  118. $posts['wechatCorpSecret'] = '';
  119. $posts['wechatAgentId'] = '';
  120. $posts['feishuAppId'] = '';
  121. $posts['feishuAppSecret'] = '';
  122. $posts['domain'] = '';
  123. $posts['sendType'] = '';
  124. $posts['products'] = array();
  125. $posts['executions'] = array();
  126. $posts['desc'] = '';
  127. foreach($posts as $field => $defaultvalue) $_POST[$field] = $defaultvalue;
  128. foreach($webhooks as $key => $value) $_POST[$key] = $value;
  129. $objects = $this->objectModel->create();
  130. if(dao::isError()) return dao::getError();
  131. return $objects;
  132. }
  133. /**
  134. * Update Test
  135. *
  136. * @param aray mixed $create
  137. * @param int mixed $id
  138. * @access public
  139. * @return int
  140. */
  141. public function updateTest($create, $update)
  142. {
  143. global $tester;
  144. $webhook1 = $this->createTest($create);
  145. $id = $tester->dao->select('id')->from(TABLE_WEBHOOK)->where('name')->eq($create['name'])->fetch('id');
  146. if($id == null)
  147. {
  148. a($webhook);
  149. return;
  150. }
  151. else{
  152. $post = array();
  153. $post['type'] = '';
  154. $post['name'] = '';
  155. $post['url'] = '';
  156. $post['secret'] = '';
  157. $post['domain'] = '';
  158. $post['products'] = array();
  159. $post['executions'] = array();
  160. $post['desc'] = '';
  161. foreach($post as $field => $defaultvalue) $_POST[$field] = $defaultvalue;
  162. foreach($update as $key => $value) $_POST[$key] = $value;
  163. $objects = $this->objectModel->update($id);
  164. if(dao::isError()) return dao::getError();
  165. return $objects;
  166. }
  167. }
  168. /**
  169. * Bind Test
  170. *
  171. * @param array mixed $create
  172. * @param array mixed $bind
  173. * @access public
  174. * @return array
  175. */
  176. public function bindTest($create, $bind)
  177. {
  178. global $tester;
  179. $result = $this->createTest($create);
  180. $id = $tester->dao->select('id')->from(TABLE_WEBHOOK)->where('name')->eq($create['name'])->fetch('id');
  181. if($id == null)
  182. {
  183. a($result);
  184. return;
  185. }else
  186. {
  187. foreach($bind as $key => $value) $_POST[$key] = $value;
  188. $objects = $this->objectModel->bind($id);
  189. if(dao::isError()) return dao::getError();
  190. return $objects;
  191. }
  192. }
  193. /**
  194. * Send Test
  195. *
  196. * @param string mixed $objectType
  197. * @param int mixed $objectID
  198. * @param string mixed $actionType
  199. * @param int mixed $actionID
  200. * @param string $actor
  201. * @access public
  202. * @return bool
  203. */
  204. public function sendTest($objectType, $objectID, $actionType, $actionID, $actor = '')
  205. {
  206. $objects = $this->objectModel->send($objectType, $objectID, $actionType, $actionID, $actor);
  207. if(dao::isError()) return dao::getError();
  208. return $objects;
  209. }
  210. /**
  211. * Build data Test
  212. *
  213. * @param string mixed $objectType
  214. * @param int mixed $objectID
  215. * @param string mixed $actionType
  216. * @param int mixed $actionID
  217. * @access public
  218. * @return bool
  219. */
  220. public function buildDataTest($objectType, $objectID, $actionType, $actionID)
  221. {
  222. static $webhooks = array();
  223. if(!$webhooks) $webhooks = $this->getListTest();
  224. if(!$webhooks) return true;
  225. foreach($webhooks as $id => $webhook)
  226. {
  227. $objects = $this->objectModel->buildData($objectType, $objectID, $actionType, $actionID, $webhook);
  228. }
  229. if(dao::isError()) return dao::getError();
  230. return $objects;
  231. }
  232. /**
  233. * Get view link Test
  234. *
  235. * @param string mixed $objectType
  236. * @param int mixed $objectID
  237. * @access public
  238. * @return string
  239. */
  240. public function getViewLinkTest($objectType, $objectID)
  241. {
  242. $objects = $this->objectModel->getViewLink($objectType, $objectID);
  243. if(dao::isError()) return dao::getError();
  244. return $objects;
  245. }
  246. /**
  247. * Get dingding data Test
  248. *
  249. * @param string mixed $title
  250. * @param string mixed $text
  251. * @param string mixed $mobile
  252. * @access public
  253. * @return array
  254. */
  255. public function getDingdingDataTest($title, $text, $mobile)
  256. {
  257. $objects = $this->objectModel->getDingdingData($title, $text, $mobile);
  258. if(dao::isError()) return dao::getError();
  259. return $objects;
  260. }
  261. /**
  262. * Get bearychat data Test
  263. *
  264. * @param string mixed $text
  265. * @param string mixed $mobile
  266. * @param string mixed $email
  267. * @param string mixed $objectType
  268. * @param int mixed $objectID
  269. * @access public
  270. * @return array
  271. */
  272. public function getBearychatDataTest($text, $mobile, $email, $objectType, $objectID)
  273. {
  274. $objects = $this->objectModel->getBearychatData($text, $mobile, $email, $objectType, $objectID);
  275. if(dao::isError()) return dao::getError();
  276. return $objects;
  277. }
  278. /**
  279. * Get weixin data Test
  280. *
  281. * @param string mixed $title
  282. * @param string mixed $text
  283. * @param string mixed $mobile
  284. * @access public
  285. * @return array
  286. */
  287. public function getWeixinDataTest($title, $text, $mobile)
  288. {
  289. $objects = $this->objectModel->getWeixinData($title, $text, $mobile);
  290. if(dao::isError()) return dao::getError();
  291. return $objects;
  292. }
  293. /**
  294. * Get feishu data Test
  295. *
  296. * @param string mixed $title
  297. * @param string mixed $text
  298. * @access public
  299. * @return array
  300. */
  301. public function getFeishuDataTest($title, $text)
  302. {
  303. $objects = $this->objectModel->getFeishuData($title, $text);
  304. if(dao::isError()) return dao::getError();
  305. return $objects;
  306. }
  307. /**
  308. * Get open id list Test
  309. *
  310. * @param int mixed $actionID
  311. * @access public
  312. * @return void
  313. */
  314. public function getOpenIdListTest($webhookID, $actionID)
  315. {
  316. static $webhooks = array();
  317. if(!$webhooks) $webhooks = $this->getListTest();
  318. if(!$webhooks) return true;
  319. foreach($webhooks as $id => $webhook)
  320. {
  321. $objects = $this->objectModel->getOpenIdList($webhook->id, $actionID);
  322. }
  323. if(dao::isError()) return dao::getError();
  324. return $objects;
  325. }
  326. /**
  327. * Fetch hook Test
  328. *
  329. * @param object mixed $webhook
  330. * @param object mixed $sendData
  331. * @param int $actionID
  332. * @access public
  333. * @return int
  334. */
  335. public function fetchHookTest($objectType, $objectID, $actionType, $actionID = 0)
  336. {
  337. static $webhooks = array();
  338. if(!$webhooks) $webhooks = $this->getListTest();
  339. if(!$webhooks) return true;
  340. foreach($webhooks as $id => $webhook)
  341. {
  342. $postData = $this->objectModel->buildData($objectType, $objectID, $actionType, $actionID, $webhook);
  343. $objects = $this->objectModel->fetchHook($webhook, $postData, $actionID);
  344. }
  345. if(dao::isError()) return dao::getError();
  346. return $objects;
  347. }
  348. /**
  349. * Save data Test
  350. *
  351. * @param int mixed $webhookID
  352. * @param int mixed $actionID
  353. * @param string mixed $data
  354. * @param string $actor
  355. * @access public
  356. * @return void
  357. */
  358. public function saveDataTest($objectType, $objectID, $actionType, $webhookID, $actionID, $actor = '')
  359. {
  360. static $webhooks = array();
  361. if(!$webhooks) $webhooks = $this->getListTest();
  362. if(!$webhooks) return true;
  363. foreach($webhooks as $id => $webhook)
  364. {
  365. $postData = $this->objectModel->buildData($objectType, $objectID, $actionType, $actionID, $webhook);
  366. $objects = $this->objectModel->saveData($webhookID, $actionID, $postData, $actor);
  367. }
  368. if(dao::isError()) return dao::getError();
  369. return $objects;
  370. }
  371. /**
  372. * Save log Test
  373. *
  374. * @param object mixed $webhook
  375. * @param int mixed $actionID
  376. * @param string mixed $data
  377. * @param string mixed $result
  378. * @access public
  379. * @return void
  380. */
  381. public function saveLogTest($webhook, $actionID, $data, $result)
  382. {
  383. $objects = $this->objectModel->saveLog($webhook, $actionID, $data, $result);
  384. if(dao::isError()) return dao::getError();
  385. return $objects;
  386. }
  387. /**
  388. * Set sent status Test
  389. *
  390. * @param array mixed $idList
  391. * @param string mixed $status
  392. * @param string $time
  393. * @access public
  394. * @return void
  395. */
  396. public function setSentStatusTest($idList, $status, $time = '')
  397. {
  398. $objects = $this->objectModel->setSentStatus($idList, $status, $time);
  399. if(dao::isError()) return dao::getError();
  400. return $objects;
  401. }
  402. }