xinhuapiChajian.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <?php
  2. /**
  3. * 来自:信呼开发团队
  4. * 作者:磐石(rainrock)
  5. * 网址:http://www.rockoa.com/
  6. * 系统文件
  7. */
  8. class xinhuapiChajian extends Chajian
  9. {
  10. private $updatekey = '';
  11. private $updatekeys = '';
  12. private $systemnum = '';
  13. private $smsapikey = '';
  14. protected function initChajian()
  15. {
  16. if (getconfig('systype') == 'dev') {
  17. $this->updatekeys = 'aHR0cDovLzEyNy4wLjAuMS9hcHAvcm9ja2FwaS8:';
  18. } else {
  19. $this->updatekeys = 'aHR0cDovL2FwaS5yb2Nrb2EuY29tLw::';
  20. }
  21. $this->updatekey = $this->rock->jm->base64decode($this->updatekeys);
  22. $this->getsysnum();
  23. }
  24. private function getsysnum()
  25. {
  26. $dbs = m('option');
  27. $this->systemnum = $dbs->getval('systemnum');
  28. $this->smsapikey = $dbs->getval('sms_apikey');
  29. $this->qiannum = $dbs->getval('sms_qmnum');
  30. $this->sendtype = $dbs->getval('sms_dirtype');
  31. if (isempt($this->qiannum)) {
  32. $this->qiannum = '';
  33. }
  34. if (isempt($this->systemnum)) {
  35. $rnd = md5(str_shuffle('abcedfghijk') . rand(1000, 9999));
  36. $dbs->setval('systemnum', $rnd);
  37. $this->systemnum = $rnd;
  38. }
  39. return $this->systemnum;
  40. }
  41. public function geturlstr($mod, $act, $can = [])
  42. {
  43. $url = $this->updatekey;
  44. $url .= '?m=' . $mod . '&a=' . $act . '';
  45. $url .= '&host=' . $this->rock->jm->base64encode(HOST) . '&version=' . VERSION . '&randtime=' . time(
  46. ) . '&ip=' . $this->rock->ip . '&xinhukey=' . getconfig('xinhukey') . '&sysnum=' . $this->systemnum . '';
  47. if (!isempt($this->smsapikey)) {
  48. $url .= '&smsapikey=' . $this->smsapikey . '';
  49. }
  50. $url .= '&authorkey=' . getconfig('authorkey') . '';
  51. foreach ($can as $k => $v) {
  52. $url .= '&' . $k . '=' . $v . '';
  53. }
  54. return $url;
  55. }
  56. public function getdata($mod, $act, $can = [])
  57. {
  58. $url = $this->geturlstr($mod, $act, $can);
  59. $cont = c('curl')->getcurl($url);
  60. if (!isempt($cont) && contain($cont, 'success')) {
  61. $data = json_decode($cont, true);
  62. } else {
  63. $data = returnerror('无法访问到官网API的,' . $cont . '');
  64. }
  65. return $data;
  66. }
  67. public function postdata($mod, $act, $can = [])
  68. {
  69. $url = $this->geturlstr($mod, $act);
  70. $cont = c('curl')->postcurl($url, $can);
  71. if (!isempt($cont) && contain($cont, 'success')) {
  72. $data = json_decode($cont, true);
  73. } else {
  74. $data = returnerror('无法访问到官网API的,' . $cont . '');
  75. }
  76. return $data;
  77. }
  78. public function urlsmall($url)
  79. {
  80. if (isempt($url)) {
  81. return '';
  82. }
  83. $barr = $this->getdata('sms', 'urlsmall', ['url' => $this->rock->jm->base64encode($url)]);
  84. if (!$barr['success']) {
  85. return $url;
  86. }
  87. return $barr['data']['url'];
  88. }
  89. public function send($tomobile, $qiannum, $tplnum, $params = [], $url = '', $addlog = true)
  90. {
  91. if (isempt($qiannum)) {
  92. $qiannum = $this->qiannum;
  93. }
  94. if (!isempt($this->sendtype)) {
  95. if (!isset($params['url']) && $url) {
  96. $params['url'] = $url;
  97. }
  98. $barr = c($this->sendtype)->send($tomobile, $qiannum, $tplnum, $params);
  99. } else {
  100. $para['sys_tomobile'] = $tomobile;
  101. $para['sys_tplnum'] = $tplnum;
  102. $para['sys_qiannum'] = $qiannum;
  103. $para['sys_url'] = $this->rock->jm->base64encode($url);
  104. foreach ($params as $k => $v) {
  105. $para['can_' . $k . ''] = $v;
  106. }
  107. $barr = $this->postdata('sms', 'send', $para);
  108. }
  109. if (!$barr['success'] && $addlog) {
  110. m('log')->addlogs('短信', $barr['msg'], 2);
  111. }
  112. return $barr;
  113. }
  114. public function sendsms($receid, $qiannum, $tplnum, $params = [], $url = '', $addlog = true, $isyb = true)
  115. {
  116. if (isempt($receid)) {
  117. return returnerror('没有接收人');
  118. }
  119. $receda = explode(',', $receid);
  120. if (c('check')->iscnmobile($receda[0])) {
  121. $tomobile = $receid;
  122. } else {
  123. $tomobile = m('admin')->getjoinfields($receid, 'mobile');
  124. }
  125. if (isempt($tomobile)) {
  126. return returnerror('接收人[' . $receid . ']可能没设置手机号');
  127. }
  128. $toama = explode(',', $tomobile);
  129. $toarr = [];
  130. foreach ($toama as $tostr) {
  131. if (!contain($tostr, '000000')) {
  132. $toarr[] = $tostr;
  133. }
  134. }
  135. if (!$toarr) {
  136. return returnerror('接收人的手机号不完整');
  137. }
  138. $tomobile = join(',', $toarr);
  139. if (isempt($qiannum)) {
  140. $qiannum = $this->qiannum;
  141. }
  142. if (getconfig('asynsend') && $isyb) {
  143. $ybbo = m('reim')->asynurl(
  144. 'asynrun', 'sendsms', [
  145. 'tomobile' => $tomobile,
  146. 'qiannum' => $qiannum,
  147. 'tplnum' => $tplnum,
  148. 'url' => $this->rock->jm->base64encode($url),
  149. 'params' => $this->rock->jm->base64encode(json_encode($params)),
  150. ]
  151. );
  152. if ($ybbo) {
  153. return returnsuccess('异步发送');
  154. }
  155. }
  156. return $this->send($tomobile, $qiannum, $tplnum, $params, $url, $addlog);
  157. }
  158. public function sendanay($m, $a, $can = [], $runtime = 0)
  159. {
  160. $runurl = m('base')->getasynurl($m, $a, $can, 1);
  161. $barr = $this->sendanayurl($runurl, $runtime);
  162. return $barr;
  163. }
  164. public function sendanayurl($runurl, $runtime = 0)
  165. {
  166. if (isempt($runurl)) {
  167. return returnerror('异步调用地址不能为空');
  168. }
  169. $para = ['runurl' => $this->rock->jm->base64encode($runurl), 'runtime' => $runtime,];
  170. $barr = $this->postdata('anay', 'send', $para);
  171. if (!$barr['success']) {
  172. m('log')->addlogs('调用官网异步', $barr['msg'], 2);
  173. }
  174. return $barr;
  175. }
  176. public function getvercode($tomobile, $device, $tplnum = '', $qiannum = '')
  177. {
  178. if (isempt($tomobile)) {
  179. return returnerror('接收手机号不能为空');
  180. }
  181. if ($tplnum == '') {
  182. $tplnum = m('option')->getval('sms_yanzm');
  183. }
  184. if (isempt($tplnum)) {
  185. $tplnum = 'defyzm';
  186. }
  187. $otme = 0;
  188. $lorsr = m('log')->getone(
  189. "`type`='获取验证码' and (`optname`='$tomobile' or `device`='$device')", '`optdt`', 'id desc'
  190. );
  191. if ($lorsr) {
  192. $otme = strtotime($lorsr['optdt']);
  193. }
  194. $jgtims = 60;
  195. $jgtime = time() - $otme;
  196. if ($otme > 0 && $jgtime < $jgtims) {
  197. return returnerror('获取太频繁,请' . ($jgtims - $jgtime) . '秒后在试');
  198. }
  199. $code = '5' . rand(10000, 99999);
  200. $params['code'] = $code;
  201. $kaifbo = (getconfig('systype') == 'dev' || getconfig('systype') == 'demo');
  202. if (!$kaifbo) {
  203. $barr = $this->send($tomobile, $qiannum, $tplnum, $params);
  204. } else {
  205. $barr = returnsuccess('ok');
  206. }
  207. if ($barr['success']) {
  208. m('log')->addlog(
  209. '获取验证码', '获取验证码为:' . $code . '', ['device' => $device, 'optname' => $tomobile, 'optid' => $code]
  210. );
  211. $barr['data'] = '';
  212. if ($kaifbo) {
  213. $barr['data'] = $code;
  214. }
  215. }
  216. return $barr;
  217. }
  218. public function checkcode($tomobile, $code, $device)
  219. {
  220. if (isempt($tomobile)) {
  221. return returnerror('手机号不能为空');
  222. }
  223. if (isempt($code)) {
  224. return returnerror('验证码不能为空');
  225. }
  226. $youxiaq = 5 * 60;
  227. $optdt = date('Y-m-d H:i:s', time() - $youxiaq);
  228. $ors = m('log')->getone(
  229. "`type`='获取验证码' and `optname`='$tomobile' and `device`='$device' and `optdt`>'$optdt'",
  230. '`optid`,`optdt`,`id`', '`id` desc'
  231. );
  232. if (!$ors) {
  233. return returnerror('请先获取验证码');
  234. }
  235. if ($code != $ors['optid']) {
  236. return returnerror('验证码错误');
  237. }
  238. m('log')->update('`optid`=0', $ors['id']);
  239. return returnsuccess('ok');
  240. }
  241. public function starttask()
  242. {
  243. $turl = getconfig('anayurl', URL);
  244. $url = '' . $turl . 'task.php?m=runt&a=task';
  245. $barr = $this->postdata('anay', 'starttask', ['runurl' => $this->rock->jm->base64encode($url)]);
  246. return $barr;
  247. }
  248. public function stoptask()
  249. {
  250. $barr = $this->getdata('anay', 'stoptask');
  251. return $barr;
  252. }
  253. public function officesend($fileid, $lx = 0)
  254. {
  255. $yulx = ',doc,docx,xls,xlsx,ppt,pptx,';
  256. $frs = m('file')->getone($fileid);
  257. if (!$frs) {
  258. return returnerror('文件不存在1');
  259. }
  260. $filepath = $frs['filepath'];
  261. $fileext = $frs['fileext'];
  262. $filepathout = arrvalue($frs, 'filepathout');
  263. $filesize = floatval($frs['filesize']);
  264. if (!contain($yulx, ',' . $fileext . ',')) {
  265. return returnerror('不是文档类型');
  266. }
  267. if (isempt($filepath)) {
  268. return returnerror('文件路径是空的');
  269. }
  270. if (substr($filepath, 0, 4) != 'http' && isempt($filepathout) && !file_exists($filepath)) {
  271. return returnerror('文件不存在2');
  272. }
  273. $pdfpath = $frs['pdfpath'];
  274. if (!isempt($pdfpath) && file_exists($pdfpath)) {
  275. return returnerror('已转过了');
  276. }
  277. $localpath = $frs['filepath'];
  278. if (substr($filepath, 0, 4) != 'http' && !isempt($filepathout) && !file_exists($filepath)) {
  279. return returnerror('文件同步到其他平台无法转化预览');
  280. }
  281. if (substr($filepath, 0, 4) == 'http') {
  282. $localpath = '' . UPDIR . '/' . date('Y-m') . '/' . date('d_His') . '' . rand(
  283. 10, 99
  284. ) . '_temp.' . $fileext . '';
  285. $this->rock->createtxt($localpath, @file_get_contents($filepath));
  286. if (!file_exists($localpath)) {
  287. return returnerror('无法下载远程文件,不能转换');
  288. }
  289. $filesize = filesize($localpath);
  290. if ($filesize == 0) {
  291. return returnerror('远程文件已损坏');
  292. }
  293. }
  294. $officeyl = getconfig('officeyl');
  295. $cache = c('cache');
  296. $zhkey = 'filetopdf' . $fileid . '';
  297. $zhval = $cache->get($zhkey);
  298. if (isempt($zhval)) {
  299. if ($officeyl == '1') {
  300. $barr = $this->postdata(
  301. 'office', 'recedata', [
  302. 'data' => $this->rock->jm->base64encode(file_get_contents($localpath)),
  303. 'fileid' => $fileid,
  304. 'fileext' => $fileext,
  305. 'filesize' => $filesize,
  306. 'filesizecn' => $frs['filesizecn'],
  307. 'backurl' => $this->rock->jm->base64encode(
  308. m('base')->getasynurl('asynrun', 'gwpdf', ['fileid' => $fileid], 2)
  309. )
  310. ]
  311. );
  312. } else {
  313. if ($officeyl == '4') {
  314. $barr = c('libreoffice')->filetopdf($fileid);
  315. } else {
  316. if (!contain(PHP_OS, 'WIN')) {
  317. return returnerror('只能在windows的服务器下转化');
  318. }
  319. $bo = c('socket')->topdf($localpath, $fileid, $fileext);
  320. if (!$bo || is_string($bo)) {
  321. return returnerror('' . $bo . ',' . c('xinhu')->helpstr('topdf') . '');
  322. }
  323. $barr = returnsuccess();
  324. }
  325. }
  326. } else {
  327. $barr = returnsuccess();
  328. }
  329. if ($barr['success']) {
  330. $times = ceil($filesize / (20 * 1024)) + 10;
  331. if ($times < 10) {
  332. $times = 10;
  333. }
  334. $cache->set($zhkey, 'true', $times + 5);
  335. if (!is_array($barr['data'])) {
  336. $barr['data'] = [];
  337. }
  338. $barr['data']['times'] = $times;
  339. $barr['data']['localpath'] = $this->rock->jm->base64encode($localpath);
  340. }
  341. return $barr;
  342. }
  343. public function officestatus($fileid)
  344. {
  345. if (getconfig('officeyl') == '1') {
  346. $barr = $this->getdata('office', 'getstatus', ['fileid' => $fileid]);
  347. } else {
  348. $frs = m('file')->getone($fileid);
  349. if (!$frs) {
  350. return returnerror('文件不存在1');
  351. }
  352. $filepath = $frs['filepath'];
  353. $localpath = $this->rock->get('localpath');
  354. if (!isempt($localpath)) {
  355. $filepath = $this->rock->jm->base64decode($localpath);
  356. }
  357. $pdfpath = str_replace('.' . $frs['fileext'] . '', '.pdf', $filepath);
  358. $status = 0;
  359. if (file_exists($pdfpath)) {
  360. $status = 1;
  361. }
  362. if ($status == 1) {
  363. m('file')->update(['pdfpath' => $pdfpath], $fileid);
  364. }
  365. $barr = returnsuccess(['status' => $status, 'ftype' => '0']);
  366. }
  367. return $barr;
  368. }
  369. public function officedown($fileid)
  370. {
  371. $barr = $this->getdata('office', 'down', ['fileid' => $fileid]);
  372. if ($barr['success']) {
  373. $data = $barr['data'];
  374. $pdfpath = $data['pdfpath'];
  375. $this->rock->createtxt($pdfpath, $this->rock->jm->base64decode($data['data']));
  376. m('file')->update(['pdfpath' => $pdfpath,], $fileid);
  377. $barr = returnsuccess();
  378. }
  379. return $barr;
  380. }
  381. public function getjiari()
  382. {
  383. $barr = $this->getdata('base', 'getjiari');
  384. return $barr;
  385. }
  386. public function authercheck($key, $ym)
  387. {
  388. if (isempt($key)) {
  389. return returnerror('密钥格不能为空');
  390. }
  391. if (isempt($ym)) {
  392. return returnerror('域名不能为空');
  393. }
  394. $barr = $this->getdata(
  395. 'auther', 'check', ['autherkey' => $key, 'yuming' => $ym, 'randkey' => getconfig('randkey')]
  396. );
  397. if ($barr['success']) {
  398. $da = $barr['data'];
  399. $this->saveauther($da, $key);
  400. return returnsuccess();
  401. } else {
  402. return $barr;
  403. }
  404. }
  405. private function saveauther($da, $key)
  406. {
  407. $db = m('option');
  408. $db->setval('auther_enddt@-101', $da['enddt']);
  409. $db->setval('auther_yuming@-101', $da['yuming']);
  410. $db->setval('auther_authkey@-101', $da['authkey']);
  411. $db->setval('auther_aukey@-101', $key);
  412. m('chargems')->update("`updatedt`='2020-02-02 02:02:02'", "`type`=0 and `mid` in(1,22)");
  413. }
  414. public function autherfile($da, $key, $ym)
  415. {
  416. $da['enddt'] = $this->rock->jm->encrypt($this->rock->jm->strunlook($da['enddt'], $key));
  417. $yuming = $this->rock->jm->strunlook($da['yuming'], $key);
  418. $xhkey1 = $this->rock->jm->strunlook($da['xhkey'], $key);
  419. $da['yuming'] = $this->rock->jm->encrypt($yuming);
  420. $da['authkey'] = $this->rock->jm->base64encode($this->rock->jm->strunlook($da['authkey'], $key));
  421. $xhkey = getconfig('xinhukey');
  422. if (isempt($xhkey)) {
  423. return returnerror(
  424. $this->rock->jm->base64decode('6K!35YWI5Yiw57O757uf6K6!572u5LiL6K6!572u5L!h5ZG85a6Y572Ra2V5')
  425. );
  426. }
  427. if ($xhkey1 != $xhkey) {
  428. return returnerror(
  429. $this->rock->jm->base64decode('5L!h5ZG85a6Y572Ra2V55LiN5LiA6Ie077yM6K!36YeN5paw6K6!572u')
  430. );
  431. }
  432. if (!contain(',' . $yuming . ',', ',' . $ym . ',')) {
  433. return returnerror('' . $ym . '不在签授域名里');
  434. }
  435. $this->saveauther($da, $key);
  436. return returnsuccess();
  437. }
  438. public function autherdel()
  439. {
  440. $aukey = m('option')->getval('auther_aukey');
  441. m('option')->update('`value`=null', 'pid=-101');
  442. if (!isempt($aukey)) {
  443. $barr = $this->getdata('auther', 'delkey', ['autherkey' => $aukey, 'randkey' => getconfig('randkey')]);
  444. return $barr;
  445. }
  446. return returnsuccess();
  447. }
  448. }