xinhuapiChajian.php 15 KB

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