WordapiController.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. <?php
  2. header("Content-type: text/html; charset=utf-8");
  3. /**
  4. * word试题导入接口控制器类
  5. * @author jiangfei
  6. * @date 2016-03-12 10:30:00
  7. * @company 上海风车教育有限公司.
  8. */
  9. class WordapiController extends CController
  10. {
  11. public $ucloud = '';
  12. public $webSiteUrl = '';
  13. public $charToNum = array('A'=>0,'B'=>1,'C'=>2,'D'=>3,'E'=>4,'F'=>5);
  14. public $flag = 1; // 解析返回的图片是否上传ucloud 0否 1是
  15. public $mathSubject = array(3,6,51);
  16. public function init()
  17. {
  18. @ini_set('memory_limit', '512M');
  19. set_time_limit(0);
  20. //$this->ucloud = new Ucloud();
  21. $this->ucloud = new Qcloud();
  22. $this->webSiteUrl = Yii::app()->params['teacherSiteurl'];
  23. $this->flag = isset($_GET['flag']) ? intval($_GET['flag']) : 1;
  24. }
  25. /**
  26. * 全学科第三方试卷解析
  27. * @param $string
  28. * @return mixed
  29. */
  30. public function actionAllSubjectCoach()
  31. {
  32. $apiTopics = array();
  33. // 获取curl过来值
  34. $word_id = isset($_GET['wid']) ? intval($_GET['wid']) : 0;
  35. $school_id = isset($_GET['sid']) ? intval($_GET['sid']) : 0;
  36. if (empty($word_id) || empty($school_id)) {
  37. exit('未找到word Id或者学校id');
  38. }
  39. // 连接业务库
  40. $busDsn = Yii::app()->businessDb;
  41. $dataBaseInfo = $busDsn->createCommand('SELECT * FROM `database` WHERE `school_id`=' . $school_id)->queryRow();
  42. if (empty($dataBaseInfo)) {
  43. exit('未找到数据库链接信息!');
  44. }
  45. $busdbh = null;
  46. // 连接学校库
  47. $schDsn = 'mysql:host=' . $dataBaseInfo['database_host'] . ';dbname=' . $dataBaseInfo['database_name'] . ';';
  48. $schdbh = new PDO($schDsn, $dataBaseInfo['database_user'], $dataBaseInfo['database_password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES "utf8";'));
  49. $wordInfo = $schdbh->query('SELECT `word_id`,`word_name`,`subject_id`,`uploader_id`,`exam_group_id` FROM `topic_word` WHERE `word_id`=' . $word_id)->fetch(PDO::FETCH_ASSOC);
  50. if (empty($wordInfo)) {
  51. exit('未找到上传word信息!');
  52. }
  53. $getWordJson = file_get_contents('php://input');
  54. $jsonArray = json_decode($getWordJson, true);
  55. if (empty($jsonArray) || $jsonArray['errcode'] == 1 || empty($jsonArray['items'])) {
  56. $errMsg = array();
  57. if (isset($jsonArray['errmsgs']) && $jsonArray['errmsgs']) {
  58. if (is_array($jsonArray['errmsgs'])) {
  59. foreach ($jsonArray['errmsgs'] as $msg) {
  60. $errMsg[] = key($msg) . ':' . implode(', ', $msg[key($msg)]);
  61. }
  62. } else {
  63. $errMsg[] = $jsonArray['errmsgs'];
  64. }
  65. }
  66. $errMsg = $errMsg ? implode('<br/>', $errMsg) : '解析异常';
  67. $stmt = $schdbh->prepare('UPDATE `topic_word` SET `status` = 3,`wrong_reason` = :reason,`content` = :content,`file_path` = :path,parse_time=:time WHERE `word_id` =:wid');
  68. $stmt->execute(array(':wid' => $word_id, ':reason' => $errMsg, ':content' => $getWordJson, ':path' => '', ':time' => time()));
  69. exit('解析失败!');
  70. } else {
  71. // 获取科目题型
  72. $tempTypeName = array(1=>'选择题','2'=>'多选题',11=>'多选题',5=>'填空题',7=>'解答题');
  73. $apiParam = Yii::app()->params['api'][0];
  74. $apiParam['prefix'] .= 'all_subject/topic_type/subjectId/' . $wordInfo['subject_id'];
  75. $topicTypeJson = self::getApiData($apiParam, 1, '', 3);
  76. $topicTypes = json_decode($topicTypeJson, true);
  77. if (isset($topicTypes['status'])) {
  78. if ($topicTypes['status'] == 0 || empty($topicTypes['data'])) {
  79. $stmt = $schdbh->prepare('UPDATE `topic_word` SET `status` = 3,`wrong_reason` = :reason, parse_time=:time WHERE `word_id` =:wid');
  80. $stmt->execute(array(':wid' => $word_id, ':reason' => '未找到科目题型', ':time' => time()));
  81. exit('未找到科目题型');
  82. } elseif ($topicTypes['status'] == 1 && $topicTypes['data']) {
  83. $topicTypes = $topicTypes['data'];
  84. }
  85. }
  86. // 查询考试试题
  87. $paper_topic_relation_data = $schdbh->query('select pt.topic_id,pt.type,pp.* from paper_topic_relation pt join (select p.paper_id ,e.subject_id as subject_id,e.exam_group_id from exam e left JOIN paper p on e.exam_id = p.exam_id where e.exam_group_id = ' . $wordInfo['exam_group_id'] . ' GROUP BY e.exam_group_id) as pp on pt.paper_id = pp.paper_id order by pt.order asc')->fetchAll(PDO::FETCH_ASSOC);
  88. if (empty($paper_topic_relation_data)) {
  89. $stmt = $schdbh->prepare('UPDATE `topic_word` SET `status` = 3,`wrong_reason` = :reason,`content` = :content,parse_time=:time WHERE `word_id` =:wid');
  90. $stmt->execute(array(':wid' => $word_id, ':reason' => '未找到考试试题', ':content' => $getWordJson, ':time' => time()));
  91. exit('未找到考试试题');
  92. }
  93. if (count($paper_topic_relation_data) != count($jsonArray['items'])) {
  94. $stmt = $schdbh->prepare('UPDATE `topic_word` SET `status`=3,`wrong_reason`=:reason,`content`=:content,parse_time=:time WHERE `word_id`=:wid');
  95. $stmt->execute(array(':wid' => $word_id, ':reason' => 'WORD题量与试卷题量不同', ':content' => $getWordJson, ':time' => time()));
  96. exit('WORD题量与试卷题量不同');
  97. }
  98. $relate_topic_id = array();
  99. $p_topic_type_num = array();
  100. $relate_topic_type = array();
  101. foreach ($paper_topic_relation_data as $v) {
  102. $relate_topic_id[] = $v['topic_id'];
  103. $p_topic_type_num[$v['type']][] = $v['topic_id'];
  104. if (!in_array($v['type'], $relate_topic_type)) {
  105. $relate_topic_type[] = $v['type'];
  106. }
  107. }
  108. // 题型格式
  109. $topicTypeName = array();
  110. $topicTypeConfig = array();
  111. foreach ($topicTypes as $topicType) {
  112. $topicTypeName[$topicType['topic_type_name']] = $topicType['topic_type_id'];
  113. $topicTypeConfig[$topicType['topic_type_id']] = $topicType;
  114. }
  115. // 删除已存在试题缓存
  116. $apiParam = Yii::app()->params['api'][0];
  117. $apiParam['prefix'] .= 'topic_clear_redis/ctopic';
  118. self::getApiData($apiParam, 2, json_encode(array('topicIds' => $relate_topic_id)), 3);
  119. $topic_type_num = array(); // 解析结果各题型数量
  120. $topic_type_error = array(); // 验证是否存在非题库题型
  121. $parse_topic_type = array(); // 解析返回的题型ID
  122. $topic_type_name = array();
  123. $bankTypeParam = Yii::app()->params['subject_topic_type_matching']; // 全学科基本题型与老题库对应
  124. foreach ($jsonArray['items'] as $loop) {
  125. if (!isset($topicTypeName[$loop['type']])) {
  126. $topic_type_error[] = "题库不存在【{$loop['type']}】题型不存在";
  127. } else {
  128. $tempTypeId = (int)$topicTypeName[$loop['type']];
  129. $typeConfig = $topicTypeConfig[$tempTypeId];
  130. if (isset($bankTypeParam[$typeConfig['btt_id']])) {
  131. if (!isset($topic_type_num[$bankTypeParam[$typeConfig['btt_id']]])) {
  132. $parse_topic_type[] = $bankTypeParam[$typeConfig['btt_id']];
  133. $topic_type_num[$bankTypeParam[$typeConfig['btt_id']]] = array();
  134. }
  135. $topic_type_num[$bankTypeParam[$typeConfig['btt_id']]][] = 1;
  136. }
  137. }
  138. }
  139. if ($topic_type_error) {
  140. $stmt = $schdbh->prepare('UPDATE `topic_word` SET `status` = 3,`wrong_reason` = :reason,`content` = :content, parse_time=:time WHERE `word_id` =:wid');
  141. $stmt->execute(array(':wid' => $word_id, ':reason' => implode('<br/>', $topic_type_error), ':content' => $getWordJson, ':time' => time()));
  142. exit('题型不存在');
  143. }
  144. // 获取默认文件夹id
  145. $defaultFolder = $schdbh->query('SELECT `folder_id` FROM `topic_folder` WHERE `is_system`=1')->fetch(PDO::FETCH_ASSOC);
  146. $folderId = empty($defaultFolder['folder_id']) ? 0 : $defaultFolder['folder_id'];
  147. // 解析试题内容
  148. foreach ($jsonArray['items'] as $key => $item) {
  149. $topicId = $paper_topic_relation_data[$key]['topic_id'];
  150. $apiTopics[] = $topicId;
  151. $typeId = (int)$topicTypeName[$item['type']];
  152. $typeConfig = $topicTypeConfig[$typeId];
  153. // 试题入库处理
  154. try {
  155. $schdbh->beginTransaction(); // 开启事务
  156. $now_time = time();
  157. $difficulty = isset($item['difficulty']) ? $item['difficulty'] : 1;
  158. // topic表
  159. $stmt = $schdbh->prepare('UPDATE `topic` SET `topic_title` = :topic_title,`topic_difficulty` = :topic_difficulty,`source_title`=:source_title,`bank_type`=:bank_type,`parse_content`=:parse_content,`update_time`=:update_time WHERE `topic_id` =:topic_id');
  160. $stmt->execute(array(':topic_id' => $topicId, ':topic_title' => $item['stem'],':topic_difficulty'=>$difficulty,':bank_type'=>$typeId, ':source_title' => 'word上传试题', ':parse_content' => $item['analysis'], ':update_time' => time()));
  161. // topic_item
  162. $stmt = $schdbh->prepare('UPDATE `topic_item` SET `topic_title` = :topic_title WHERE `topic_id` =:topic_id');
  163. $stmt->execute(array(':topic_id' => $topicId, ':topic_title' => $item['stem']));
  164. $stmt = $schdbh->prepare('delete from `topic_item_option` WHERE `topic_id` =:topic_id');
  165. $stmt->execute(array(':topic_id' => $topicId));
  166. // 选择题选项处理
  167. if (isset($item['options']) && $item['options']) { // 含有选项的试题
  168. //$optionKeys = explode(',', $item['key']);
  169. $optionKeys = array();
  170. foreach ($this->charToNum as $char => $num) {
  171. if (strpos($item['key'], $char) !== false) {
  172. $optionKeys[] = $char;
  173. }
  174. }
  175. $rowThr = $schdbh->prepare('INSERT INTO `topic_item_option`(`topic_id`, `option_content`, `option_correct`,`sort_order`) VALUES (:tpid,:content,:correct,:sort_order)');
  176. $correct = 'A';
  177. foreach ($item['options'] as $vk => $option) {
  178. $is_true = in_array($correct, $optionKeys) ? 1 : 0;
  179. $getRowThr = $rowThr->execute(array(':tpid'=>$topicId,':content'=>$option,':correct'=>$is_true,':sort_order'=>$vk));
  180. ++$correct;
  181. }
  182. } else {
  183. $rowFiv = $schdbh->prepare('INSERT INTO `topic_item_option`(`topic_id`, `option_content`) VALUES (:tpid,:content)');
  184. if (is_array($item['key']) && $item['key']) {
  185. foreach ($item['key'] as $topicKey) {
  186. $getRowFiv = $rowFiv->execute(array(':tpid' => $topicId, ':content' => $topicKey));
  187. }
  188. } else {
  189. $getRowFiv = $rowFiv->execute(array(':tpid' => $topicId, ':content' => $item['key']));
  190. if (!$getRowFiv) {
  191. throw new PDOException('插入topic_item_option表失败!');
  192. }
  193. }
  194. }
  195. // word与试题关系
  196. $rowFor = null;
  197. $rowFor = $schdbh->prepare('INSERT INTO `word_topic_relation`(`word_id`, `topic_id`) VALUES (:wid,:toid)');
  198. $getRowFor = $rowFor->execute(array(':wid' => $word_id, ':toid' => $topicId));
  199. if (!$getRowFor) {
  200. throw new PDOException('插入word_to_topic表失败!');
  201. }
  202. $schdbh->commit();
  203. } catch (PDOException $e) {
  204. $schdbh->rollback(); // 执行失败,事务回滚
  205. $stmt = $schdbh->prepare('UPDATE `topic_word` SET `status` = 3,`wrong_reason` = :reason,`content` = :content,parse_time=:time WHERE `word_id` =:wid');
  206. $stmt->execute(array(':wid' => $word_id, ':reason' => $e->getMessage(), ':content' => $getWordJson, ':time' => time()));
  207. exit($e->getMessage());
  208. }
  209. }
  210. //exit($topicId);
  211. }
  212. // 处理完
  213. $resu = $schdbh->prepare('UPDATE `topic_word` SET `status` = 2,`parse_time`=:time,`content` = :content WHERE `word_id` =:wid');
  214. $resu->execute(array(':wid' => $word_id, ':time' => time(), ':content' => $getWordJson));
  215. $resu = $schdbh->prepare('UPDATE `exam_group` SET `is_answersheet` = 1 WHERE `exam_group_id` =:exam_group_id');
  216. $resu->execute(array(':exam_group_id' => $wordInfo['exam_group_id']));
  217. // 插入解析时间记录
  218. $resPro = $schdbh->prepare("INSERT INTO `exam_process` (`exam_group_id`, `action_type`, `action_time`) VALUES (:exam_group_id, :tempType, :time)");
  219. $resPro->execute(array(':exam_group_id' => $wordInfo['exam_group_id'], ':tempType' => 4, ':time' => time()));
  220. $schdbh = null;
  221. if($apiTopics){
  222. //调用试题检索接口
  223. $this->searchTopics($apiTopics,$school_id);
  224. }
  225. exit('解析完成!');
  226. }
  227. // 试题内容相关过滤处理等
  228. function strip_content_tags($str)
  229. {
  230. if (empty($str)) return $str;
  231. $allow_tags = "<br><dd><dl><div><dt><img><label><li><ol><p><span><sub><sup><table><tbody><td><tfoot><th><thead><tr><ul>";
  232. // $str = htmlspecialchars_decode($str);
  233. $str = preg_replace('/alt=[\\\'|\\"](.*?)[\\\'|\\"]/', '', $str);
  234. return $str;
  235. // return strip_tags($str, $allow_tags);
  236. }
  237. // 下载远程图片
  238. function downloadImg($content, $school_id)
  239. {
  240. $img_date = date('Ymd');
  241. $school_id = empty($school_id) ? 1 : $school_id;
  242. // 如果解析返回的图片是已上传ucloud则无需处理
  243. if ($this->flag == 1) {
  244. return $content;
  245. }
  246. // 匹配所有远程图片
  247. $img_array = array();
  248. preg_match_all("/<img.*?src=[\\\'| \\\"](.*?(?:[\.gif|\.jpg|\.png]))[\\\'|\\\"].*?[\/]?>/is", $content, $img_array);
  249. if (empty($img_array[1])) {
  250. return $content;
  251. }
  252. // 文件保存目录URL
  253. $save_url = '/uploadfiles/wordimg/' . $school_id . '/' . date('Y') . '/' . date('m') . '/' . date('d');
  254. $save_path = dirname(dirname(dirname(__FILE__))) . $save_url;
  255. // 创建文件夹
  256. if (!is_dir($save_path)) {
  257. @mkdir($save_path, 0777, true);
  258. }
  259. foreach ($img_array[1] as $key => $value) {
  260. // 保存到本地图片名称
  261. $imgInfo = pathinfo($value);
  262. $imgname = uniqid() . '.' . $imgInfo['extension'];
  263. // 保存到本地的实际文件地址(包含路径和名称)
  264. $fileName = $save_path . '/' . $imgname;
  265. self::curlDownloadImage($value, $fileName);
  266. // 教师端访问的地址
  267. $fileurl = $this->webSiteUrl . $save_url . "/" . $imgname;
  268. // 判断图片是否要压缩
  269. self::imgCompress($fileName);
  270. // 替换原来的图片地址
  271. $uploadInfo = $this->ucloud->putFile('teacher'.$save_url .'/'. $imgname, $fileName);
  272. if ($uploadInfo['status']) {
  273. $content = str_replace($value, $uploadInfo['url'], $content);
  274. @unlink($fileName);
  275. } else {
  276. $content = str_replace($value, $fileurl, $content);
  277. }
  278. }
  279. return $content;
  280. }
  281. /**
  282. * 采集远程图片
  283. * @param string $url 远程文件地址
  284. * @param string $fileName 保存后的文件名
  285. * @return bool
  286. */
  287. function curlDownloadImage($url, $fileName = '')
  288. {
  289. if (empty($url) || empty($fileName)) {
  290. return false;
  291. }
  292. // 获取远程文件资源
  293. $ch = curl_init();
  294. curl_setopt($ch, CURLOPT_URL, $url);
  295. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  296. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
  297. $tempFile = curl_exec($ch);
  298. curl_close($ch);
  299. // 保存文件
  300. $fp = @fopen($fileName, "w");
  301. fwrite($fp, $tempFile);
  302. fclose($fp);
  303. return true;
  304. }
  305. // 压缩图片尺寸以及比例
  306. public static function imgCompress($imgSrc = '')
  307. {
  308. $standardWidth = 2000;
  309. if (empty($imgSrc)) {
  310. return true;
  311. } elseif (!file_exists($imgSrc)) {
  312. return true;
  313. }
  314. list($width, $height, $type) = getimagesize($imgSrc);
  315. if ($width < $standardWidth) {
  316. return true;
  317. }
  318. $multiple = round($width / $standardWidth, 2);
  319. $newWidth = 2000;
  320. $newHeight = ceil($height / $multiple);
  321. if (!$newWidth || !$newHeight) return true;
  322. $imgType = image_type_to_extension($type, false);
  323. $imageCreateType = 'image' . $imgType; // 创建新图像
  324. $funCreateFromType = 'imagecreatefrom' . $imgType; // 创建新图像
  325. $imageP = imagecreatetruecolor($newWidth, $newHeight);
  326. $colorBlack = imagecolorallocatealpha($imageP, 0, 0, 0, 127);//拾取一个完全透明的颜色
  327. imagealphablending($imageP, false);//关闭混合模式,以便透明颜色能覆盖原画布
  328. imagefill($imageP, 0, 0, $colorBlack);//填充
  329. $image = $funCreateFromType($imgSrc);
  330. imagecopyresampled($imageP, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
  331. imagesavealpha($imageP, true);
  332. $imageCreateType($imageP, $imgSrc);
  333. imagedestroy($image);
  334. imagedestroy($imageP);
  335. return true;
  336. }
  337. // 下载错题word文本
  338. function downloadWord($word_info, $word_url, $school_id)
  339. {
  340. //暂时修改
  341. return "";
  342. if (empty($word_info) || empty($word_url) || empty($school_id)) return '';
  343. // 文件保存目录URL
  344. $save_url = '/uploadfiles/words/wrong_word/' . $school_id . '/' . date('Y') . '/' . date('m') . '/' . date('d');
  345. $save_path = dirname(dirname(dirname(__FILE__))) . $save_url;
  346. // 创建文件夹
  347. if (!is_dir($save_path)) {
  348. @mkdir($save_path, 0777, true);
  349. }
  350. // 保存到本地word名称
  351. $wordInfo = pathinfo($word_info['word_name']);
  352. $wordname = $word_info['word_id'] . '.' . $wordInfo['extension'];
  353. // 保存到本地的实际文件地址(包含路径和名称)
  354. $fileName = $save_path . '/' . $wordname;
  355. // 实际访问的地址
  356. $fileurl = Yii::app()->params['siteurl'] . $save_url . "/" . $wordname;
  357. // 读取远程图片
  358. set_time_limit(0);
  359. $get_file = @file_get_contents($word_url);
  360. if ($get_file) {
  361. $fp = @fopen($fileName, "w");
  362. @fwrite($fp, $get_file);
  363. @fclose($fp);
  364. return $fileurl;
  365. }
  366. return '';
  367. }
  368. // 公式转换(2018-11-29停用)
  369. function formulaTransform($string)
  370. {
  371. preg_match_all("/(data-latex=\\\"([^\"]*\\\"))|(\\$.*?\\$)|(\\\\\\[.*?\\\\\\])/", $string, $get_math_thr);
  372. if ($get_math_thr[0]) {
  373. $uniqueMath = array_unique($get_math_thr[0]);
  374. foreach ($uniqueMath as $vvtr) {
  375. if (substr($vvtr, 0, 10) !== "data-latex") {
  376. $mathmlOptThr = saveMathtex($vvtr);
  377. if ($mathmlOptThr['status'] == 1) {
  378. $string = str_replace($vvtr, '<img src="' . $mathmlOptThr['fileUrl'] . '" class="gsImgLatex mathType" width="' . $mathmlOptThr['imgWidth'] . '" height="' . $mathmlOptThr['imgHeight'] . '"/>', $string);
  379. }
  380. }
  381. }
  382. }
  383. // LaTeX与MathML转换(暂时注销 2016-10-08)
  384. //$myMathml = new MathMlEncode();
  385. //$string = $myMathml->replaceForJsMathml($string);
  386. return $string;
  387. }
  388. private static function getApiData($apiParam, $flag = 1, $data, $timeOut = 0,$extraHeaders = array())
  389. {
  390. $result = FALSE;
  391. $ch = @curl_init();
  392. if ($ch) {
  393. $headers = array(
  394. 'Content-Type: application/json',
  395. 'Content-Length: ' . strlen($data),
  396. );
  397. if($extraHeaders){
  398. $headers = array_merge($headers,$extraHeaders);
  399. }
  400. // Digest认证
  401. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  402. curl_setopt($ch, CURLOPT_USERPWD, $apiParam['username'] . ':' . $apiParam['password']);
  403. // 不输出头部
  404. curl_setopt($ch, CURLOPT_HEADER, 0);
  405. if ($timeOut) {
  406. curl_setopt($ch, CURLOPT_TIMEOUT, $timeOut);
  407. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
  408. }
  409. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  410. // curl_exec 获取到的内容不直接输出, 而是返回
  411. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  412. // 请求重启路由器的地址 传参 进行重启
  413. curl_setopt($ch, CURLOPT_URL, $apiParam['prefix']);
  414. curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)');
  415. if ($flag == 2) {
  416. curl_setopt($ch, CURLOPT_POST, 1);
  417. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  418. }
  419. $result = curl_exec($ch);
  420. if (curl_errno($ch)) {
  421. return 'curl_errno:' . curl_errno($ch);
  422. }
  423. // 释放资源
  424. curl_close($ch);
  425. }
  426. return $result;
  427. }
  428. //全学科试题调用java检索缓存接口
  429. public function searchTopics($topicIds = array(),$schoolId = 0){
  430. $apiParam = Yii::app()->params['api'][3];
  431. if($apiParam && $topicIds && $schoolId){
  432. $url = $apiParam['prefix'].'cgi/teacher/schtk/qxk/school-topic-flush/'.$schoolId;
  433. self::getApiData(array(
  434. 'username' => $apiParam['username'],
  435. 'password' => $apiParam['password'],
  436. 'prefix' => $url
  437. ), 2, json_encode($topicIds), 3,array('X-Basic-V:2'));
  438. }
  439. }
  440. }