functions.inc.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. <?php
  2. /**
  3. * 二维数组去重
  4. * @return array
  5. */
  6. if (! function_exists('array_unique_two_dimensional')) {
  7. function array_unique_multidimensional(array $input)
  8. {
  9. $unique = [];
  10. foreach ($input as $item) {
  11. if (! is_array($item)) {
  12. return $input;
  13. }
  14. $str = implode(',', $item); //利用implode,将二维数组中的下层数组变成字符串
  15. $strArr[] = $str;
  16. $unique = array_unique($strArr); //去掉重复的字符串,也就是生成一个干净的一维数组
  17. }
  18. $output = [];
  19. foreach ($unique as $item) {
  20. $output[] = explode(',', $item);
  21. }
  22. return $output;
  23. }
  24. }
  25. function ueditor() {
  26. $editer = <<<HTML
  27. <!-- 配置文件 -->
  28. <script type="text/javascript" src="/base/neditor-1.5.3/neditor.config.js"></script>
  29. <!-- 编辑器源码文件 -->
  30. <script type="text/javascript" src="/base/neditor-1.5.3/neditor.all.js"></script>
  31. <!-- 实例化编辑器 -->
  32. <script type="text/javascript">
  33. var ue = UE.getEditor('container',{
  34. toolbars: [
  35. ["fullscreen","source","autotypeset","bold", "italic","underline","forecolor", "paragraph","fontfamily","fontsize","indent","justifyleft", "justifycenter","justifyright","justifyjustify","link","unlink","insertimage","insertcode"
  36. ]],
  37. autoHeightEnabled: true,
  38. autoFloatEnabled: true,
  39. initialFrameHeight:320
  40. });
  41. ue.ready(function(){
  42. ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');
  43. })
  44. </script>
  45. HTML;
  46. return $editer;
  47. }
  48. if( ! function_exists('array_to_sort')) {
  49. /**
  50. * 对二维数组排序
  51. * @param string $arr old数组
  52. * @param string $keys 要排序的键
  53. * @param string $type 排序类型[asc,desc]
  54. * @param string $reset 重新排列数组key
  55. * @return string 返回排序之后的数组
  56. */
  57. function array_to_sort($arr, $keys, $type = 'asc', $reset = false)
  58. {
  59. $keysvalue = $new_array = array();
  60. foreach ($arr as $k => $v) {
  61. $keysvalue[$k] = $v[$keys];
  62. }
  63. if ($type == 'asc') {
  64. asort($keysvalue);
  65. } else {
  66. arsort($keysvalue);
  67. }
  68. reset($keysvalue);
  69. foreach ($keysvalue as $k => $v) {
  70. if ($reset) {
  71. $new_array[] = $arr[$k];
  72. } else {
  73. $new_array[$k] = $arr[$k];
  74. }
  75. }
  76. return $new_array;
  77. }
  78. }
  79. /**
  80. * 写作的时间人性化
  81. *
  82. * @param int $time 写作的时间
  83. * @return string
  84. */
  85. if( ! function_exists('showWriteTime'))
  86. {
  87. function showWriteTime($time)
  88. {
  89. $interval = time() - $time;
  90. $format = array(
  91. '31536000' => '年',
  92. '2592000' => '个月',
  93. '604800' => '星期',
  94. '86400' => '天',
  95. '3600' => '小时',
  96. '60' => '分钟',
  97. '1' => '秒'
  98. );
  99. foreach($format as $key => $value)
  100. {
  101. $match = floor($interval / (int) $key );
  102. if(0 != $match)
  103. {
  104. return $match . $value . '前';
  105. }
  106. }
  107. return date('Y-m-d', $time);
  108. }
  109. }
  110. if( ! function_exists('pairList'))
  111. {
  112. function pairList($list, $keyField, $valueField)
  113. {
  114. $pairList = array();
  115. foreach ($list as $one) {
  116. $pairList[$one[$keyField]] = $one[$valueField];
  117. }
  118. return $pairList;
  119. }
  120. }
  121. /**
  122. * 重新组装url ,如果没有host回自动添加当前host
  123. * @param string $url
  124. * @param array $query key=>val
  125. * @return string
  126. */
  127. function U ($url, $query = [])
  128. {
  129. $url = ltrim($url, '/');
  130. $urlInfo = parse_url($url);
  131. $aQuery = [];
  132. if (isset($urlInfo['query']) && $urlInfo['query'] !== '') {
  133. parse_str($urlInfo['query'],$aQuery);
  134. }
  135. $queryString = http_build_query(array_merge($aQuery, $query));
  136. if(isset($urlInfo['host'])) {
  137. $url = $urlInfo['scheme'] . '://' . $urlInfo['host'].'/admin/';
  138. }else{
  139. $url = request()->root() . '/admin/';
  140. }
  141. $url .= isset($urlInfo['path']) ? $urlInfo['path'] : '';
  142. $url .= $queryString === '' ? '' : ('?'.$queryString);
  143. return $url;
  144. }
  145. /**
  146. * 验证角色菜单权限
  147. *
  148. * @param string $route 路由
  149. * @param string $params 附带参数
  150. * @return bool
  151. */
  152. if( ! function_exists('role'))
  153. {
  154. function role($route, $params = [])
  155. {
  156. $user = \Auth::guard('admin')->user();
  157. $role = session()->get(LOGIN_MARK_SESSION_KEY);
  158. if($user['is_root']) {
  159. return true;
  160. }
  161. $route = trim($route);
  162. $roles = $role['role'];
  163. if(isset($roles[$route])){
  164. return true;
  165. }else{
  166. return false;
  167. }
  168. }
  169. }
  170. if( ! function_exists('dict'))
  171. {
  172. function dict()
  173. {
  174. return new App\Services\Base\Dictionary;
  175. }
  176. }
  177. /**
  178. * 隐藏部分手机号码
  179. * @param $mobile
  180. * @param $hide_length
  181. * @return string
  182. */
  183. if( ! function_exists('hidePartMobile'))
  184. {
  185. function hidePartMobile($mobile, $hide_length = 5){
  186. $hide_length = intval($hide_length);
  187. $hide = '';
  188. for($i = 0; $i < $hide_length; $i++){
  189. $hide .= '*';
  190. }
  191. $pattern = "/(1\d{1,2})([0-9]{". $hide_length .",". $hide_length ."})(\d+)/";
  192. $replacement = "\$1{$hide}\$3";
  193. return preg_replace($pattern, $replacement, $mobile);
  194. }
  195. }
  196. /**
  197. * Function echo_log
  198. * 输出调试日志
  199. * @param $content 输出内容
  200. */
  201. if( ! function_exists('echoLog'))
  202. {
  203. function echoLog($content, $filename = '')
  204. {
  205. if(is_object($content) || is_array($content)) {
  206. $content = var_export($content, true);
  207. }
  208. $log_path = storage_path() . DIRECTORY_SEPARATOR . "debug_log" . DIRECTORY_SEPARATOR;
  209. if($filename){
  210. $file_path = $log_path . $filename;
  211. }else{
  212. $file_path = $log_path . "debug_log_" . date("Ymd") . ".txt";
  213. }
  214. if(!file_exists($log_path)){
  215. mkdir($log_path,0777);
  216. }
  217. $fp = fopen($file_path, "a");
  218. flock($fp, LOCK_EX) ;
  219. fwrite($fp,"执行日期:".date("Y-m-d H:i:s",time())."\n".$content."\n\n");
  220. flock($fp, LOCK_UN);
  221. fclose($fp);
  222. }
  223. }
  224. if( ! function_exists('curlAjax'))
  225. {
  226. function curlAjax($url) {
  227. $cookieStr = '';
  228. if($_COOKIE) {
  229. foreach ($_COOKIE as $key=>$val) {
  230. $cookieStr .= $key . '=' . $val . ';';
  231. }
  232. $cookieStr = substr($cookieStr, 0,-1);
  233. }
  234. $headers = array(
  235. 'Content-Type' => 'text/json;charset=utf-8', // 设置为Ajax方式
  236. 'X-Requested-With' => 'XMLHttpRequest', // 设置为Ajax方式
  237. 'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36', // 设置为Ajax方式
  238. 'Referer' => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],
  239. 'Cookie' => $cookieStr
  240. );
  241. $headerArr = array();
  242. foreach( $headers as $n => $v ) {
  243. $headerArr[] = $n .':' . $v;
  244. }
  245. $ch = curl_init($url);
  246. curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);
  247. curl_setopt($ch, CURLOPT_HEADER, 0);
  248. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  249. $return = curl_exec($ch);
  250. curl_close ( $ch );
  251. return $return;
  252. }
  253. }
  254. if( ! function_exists('img'))
  255. {
  256. function img($system, $system_primary = NULL, $system_key = NULL, $first = false, $pagesize = PAGE_MAX_NUMS)
  257. {
  258. $paramArgs = func_get_args();
  259. $key = "system_img" . md5(serialize($paramArgs));
  260. if(!Cache::has($key) || request('no_cache') === 'true') {
  261. $data = \App\Services\Base\Images::getSrc($system, $system_primary, $system_key, $first, $pagesize);
  262. \Cache::forever($key,$data);
  263. }
  264. $data = \Cache::get($key);
  265. return $data;
  266. }
  267. }
  268. /**
  269. * 字符截取 支持UTF8/GBK
  270. * @param $string
  271. * @param $length
  272. * @param $dot
  273. */
  274. if( ! function_exists('str_cut'))
  275. {
  276. function str_cut($string, $length, $dot = '...') {
  277. $strlen = strlen($string);
  278. if($strlen <= $length) return $string;
  279. $string = str_replace(array(' ','&nbsp;', '&amp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;'), array('∵',' ', '&', '"', "'", '“', '”', '—', '<', '>', '·', '…'), $string);
  280. $strcut = '';
  281. if(strtolower('utf-8') == 'utf-8') {
  282. $length = intval($length-strlen($dot)-$length/3);
  283. $n = $tn = $noc = 0;
  284. while($n < strlen($string)) {
  285. $t = ord($string[$n]);
  286. if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
  287. $tn = 1; $n++; $noc++;
  288. } elseif(194 <= $t && $t <= 223) {
  289. $tn = 2; $n += 2; $noc += 2;
  290. } elseif(224 <= $t && $t <= 239) {
  291. $tn = 3; $n += 3; $noc += 2;
  292. } elseif(240 <= $t && $t <= 247) {
  293. $tn = 4; $n += 4; $noc += 2;
  294. } elseif(248 <= $t && $t <= 251) {
  295. $tn = 5; $n += 5; $noc += 2;
  296. } elseif($t == 252 || $t == 253) {
  297. $tn = 6; $n += 6; $noc += 2;
  298. } else {
  299. $n++;
  300. }
  301. if($noc >= $length) {
  302. break;
  303. }
  304. }
  305. if($noc > $length) {
  306. $n -= $tn;
  307. }
  308. $strcut = substr($string, 0, $n);
  309. $strcut = str_replace(array('∵', '&', '"', "'", '“', '”', '—', '<', '>', '·', '…'), array(' ', '&amp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;'), $strcut);
  310. } else {
  311. $dotlen = strlen($dot);
  312. $maxi = $length - $dotlen - 1;
  313. $current_str = '';
  314. $search_arr = array('&',' ', '"', "'", '“', '”', '—', '<', '>', '·', '…','∵');
  315. $replace_arr = array('&amp;','&nbsp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;',' ');
  316. $search_flip = array_flip($search_arr);
  317. for ($i = 0; $i < $maxi; $i++) {
  318. $current_str = ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
  319. if (in_array($current_str, $search_arr)) {
  320. $key = $search_flip[$current_str];
  321. $current_str = str_replace($search_arr[$key], $replace_arr[$key], $current_str);
  322. }
  323. $strcut .= $current_str;
  324. }
  325. }
  326. return $strcut.$dot;
  327. }
  328. }
  329. /**
  330. * 取得文件扩展
  331. *
  332. * @param $filename 文件名
  333. * @return 扩展名
  334. */
  335. if( ! function_exists('fileExt'))
  336. {
  337. function fileExt($filename)
  338. {
  339. return strtolower(trim(substr(strrchr($filename, '.'), 1, 10)));
  340. }
  341. }
  342. /**
  343. * 过滤参数
  344. *
  345. * @param $param 参数数组
  346. * @param $allowKey 被允许的KEY集合数组
  347. * @return 扩展名
  348. */
  349. if( ! function_exists('filterParam'))
  350. {
  351. function filterParam(array $param, array $allowKey)
  352. {
  353. $data = array();
  354. foreach ($param AS $key => $val) {
  355. if(in_array($key, $allowKey)) $data[$key] = $val;
  356. }
  357. return $data;
  358. }
  359. }
  360. if(!function_exists('list_to_tree')) {
  361. function list_to_tree($list, $pk='id',$pid = 'pid',$child = '_child',$root=0)
  362. {
  363. // 创建Tree
  364. $tree = array();
  365. if(is_array($list)) {
  366. // 创建基于主键的数组引用
  367. $refer = array();
  368. foreach ($list as $key => $data) {
  369. $refer[$data[$pk]] =& $list[$key];
  370. }
  371. foreach ($list as $key => $data) {
  372. // 判断是否存在parent
  373. $parentId = $data[$pid];
  374. if ($root == $parentId) {
  375. $tree[] =& $list[$key];
  376. }else{
  377. if (isset($refer[$parentId])) {
  378. $parent =& $refer[$parentId];
  379. $parent[$child][] =& $list[$key];
  380. }
  381. }
  382. }
  383. }
  384. return $tree;
  385. }
  386. }
  387. /**
  388. * 判断远程文件是否存在
  389. * @param unknown $url
  390. * @return boolean
  391. */
  392. function check_remote_file_exists($url)
  393. {
  394. $curl = curl_init($url);
  395. curl_setopt($curl, CURLOPT_NOBODY, true);
  396. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
  397. $result = curl_exec($curl);
  398. $found = false;
  399. if ($result !== false)
  400. {
  401. $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  402. if ($statusCode == 200)
  403. {
  404. $found = true;
  405. }
  406. }
  407. curl_close($curl);
  408. return $found;
  409. }
  410. if( ! function_exists('getCacheKey')) {
  411. /**
  412. * 更具参数获取一个唯一的缓存KEY
  413. * @param string $name 名称
  414. * @param obj|array|string $data 参数
  415. */
  416. function getCacheKey($name,$data) {
  417. return $name . md5(serialize($data));
  418. }
  419. }
  420. function isMobile()
  421. {
  422. // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
  423. if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
  424. {
  425. return true;
  426. }
  427. // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
  428. if (isset ($_SERVER['HTTP_VIA']))
  429. {
  430. // 找不到为false,否则为true
  431. return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
  432. }
  433. // 脑残法,判断手机发送的客户端标志,兼容性有待提高
  434. if (isset ($_SERVER['HTTP_USER_AGENT']))
  435. {
  436. $clientkeywords = array ('nokia',
  437. 'sony',
  438. 'ericsson',
  439. 'mot',
  440. 'samsung',
  441. 'htc',
  442. 'sgh',
  443. 'lg',
  444. 'sharp',
  445. 'sie-',
  446. 'philips',
  447. 'panasonic',
  448. 'alcatel',
  449. 'lenovo',
  450. 'iphone',
  451. 'ipod',
  452. 'blackberry',
  453. 'meizu',
  454. 'android',
  455. 'netfront',
  456. 'symbian',
  457. 'ucweb',
  458. 'windowsce',
  459. 'palm',
  460. 'operamini',
  461. 'operamobi',
  462. 'openwave',
  463. 'nexusone',
  464. 'cldc',
  465. 'midp',
  466. 'wap',
  467. 'mobile'
  468. );
  469. // 从HTTP_USER_AGENT中查找手机浏览器的关键字
  470. if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT'])))
  471. {
  472. return true;
  473. }
  474. }
  475. // 协议法,因为有可能不准确,放到最后判断
  476. if (isset ($_SERVER['HTTP_ACCEPT']))
  477. {
  478. // 如果只支持wml并且不支持html那一定是移动设备
  479. // 如果支持wml和html但是wml在html之前则是移动设备
  480. if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html'))))
  481. {
  482. return true;
  483. }
  484. }
  485. return false;
  486. }
  487. /**
  488. * post 提交
  489. * @param strint $url
  490. * @param array $post_data
  491. * @return mixed
  492. */
  493. function formPost($url, $post_data=array(), $timeout=60, $userpwd = null)
  494. {
  495. $ch = curl_init();
  496. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  497. curl_setopt($ch, CURLOPT_POST, 1);
  498. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  499. curl_setopt($ch, CURLOPT_HEADER, 0);
  500. curl_setopt($ch, CURLOPT_URL, $url);
  501. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); // 设置超时限制防止死循环
  502. curl_setopt($ch, CURLOPT_POST, 1);
  503. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
  504. // curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
  505. if ($userpwd) {
  506. curl_setopt($ch, CURLOPT_HTTPAUTH , CURLAUTH_BASIC);
  507. curl_setopt($ch, CURLOPT_USERPWD , $userpwd);
  508. }
  509. $result = curl_exec($ch);
  510. if (curl_errno($ch)) {
  511. // echo curl_error($ch);exit;
  512. }
  513. curl_close($ch); // 关键CURL会话
  514. // CBase::write_log('formPost' . date("Ymd") . ".log", $result);
  515. return $result;
  516. }
  517. /**
  518. *
  519. * @param string $textareaid 编辑器ID
  520. * @param unknown $getParam 上传参数
  521. * @param unknown $options 编辑器自带参数,直接以php数组的形式传入即可,但不支持对象类型(eg.Function)
  522. * @return string
  523. */
  524. function editor() {
  525. $editer = <<<HTML
  526. <!-- 配置文件 -->
  527. <script type="text/javascript" src="/base/neditor-1.5.3/neditor.config.js"></script>
  528. <!-- 编辑器源码文件 -->
  529. <script type="text/javascript" src="/base/neditor-1.5.3/neditor.all.js"></script>
  530. <!-- 实例化编辑器 -->
  531. <script type="text/javascript">
  532. var ue = UE.getEditor('container',{
  533. toolbars: [
  534. ["fullscreen","source","autotypeset","bold", "italic","underline","forecolor", "paragraph","fontfamily","fontsize","indent","justifyleft", "justifycenter","justifyright","justifyjustify","link","unlink","insertimage","insertcode"
  535. ]],
  536. autoHeightEnabled: true,
  537. autoFloatEnabled: true,
  538. initialFrameHeight:320
  539. });
  540. ue.ready(function(){
  541. ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');
  542. })
  543. </script>
  544. HTML;
  545. return $editer;
  546. }
  547. if( ! function_exists('widget'))
  548. {
  549. function widget($widgetName)
  550. {
  551. $widgetNameEx = explode('.', $widgetName);
  552. if( ! isset($widgetNameEx[1])) return false;
  553. $widgetClass = 'App\\Widget\\'.$widgetNameEx[0].'\\'.$widgetNameEx[1];
  554. if(app()->bound($widgetName)) return app()->make($widgetName);
  555. app()->singleton($widgetName, function() use ($widgetClass)
  556. {
  557. return new $widgetClass();
  558. });
  559. return app()->make($widgetName);
  560. }
  561. }
  562. //
  563. //if( ! function_exists('sendSms')) {
  564. // // return string 'success' 为成功
  565. // function sendSms($msg, $mobile){
  566. // $post_data = array();
  567. // $post_data['un'] ="N9304000";
  568. // $post_data['pw'] = "Mask751002@";
  569. // $post_data['msg']="【小洲蔬菜】$msg";
  570. // $post_data['phone'] =$mobile;
  571. // $post_data['rd']=1;
  572. //
  573. // $post_data['needstatus']='true';
  574. // $url='https://sms.253.com/msg/send';
  575. // $data=http_build_query($post_data);
  576. //
  577. // if(function_exists('curl_init')){
  578. // $curl = curl_init();
  579. // curl_setopt($curl, CURLOPT_URL, $url);
  580. //
  581. // if (!empty($data)){
  582. // curl_setopt($curl, CURLOPT_POST, 1);
  583. // curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  584. // }
  585. // curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  586. // $output = curl_exec($curl);
  587. // curl_close($curl);
  588. // $result=preg_split("/[,\r\n]/",$output);
  589. // if($result[1]==0){
  590. // $res = "success";
  591. // }else{
  592. // $res = "curl error:".$result[1];
  593. // }
  594. // }elseif(function_exists('file_get_contents')){
  595. // $output=file_get_contents($url.$data);
  596. // $result=preg_split("/[,\r\n]/",$output);
  597. // if($result[1]==0){
  598. // $res = "success";
  599. // }else{
  600. // $res = "error:".$result[1];
  601. // }
  602. // }else{
  603. // $res="error";
  604. // }
  605. // return $res;
  606. // }
  607. //}
  608. //
  609. //if( ! function_exists('sendMultiSms')) {
  610. // // 群发短信 $mobiles电话号码之间用英文逗号分割
  611. // // return string 'success' 为成功
  612. // function sendMultiSms($msg, $mobiles){
  613. // $post_data = array();
  614. // $post_data['un'] ="M3512322";
  615. // $post_data['pw'] = "N8ecbXn0A7dc18";
  616. // $post_data['msg']="【小洲蔬菜】$msg 回复TD退订";
  617. // $post_data['phone'] =$mobiles;
  618. // $post_data['rd']=1;
  619. //
  620. // $post_data['needstatus']='true';
  621. // $url='https://sms.253.com/msg/send';
  622. // $data=http_build_query($post_data);
  623. //
  624. // if(function_exists('curl_init')){
  625. // $curl = curl_init();
  626. // curl_setopt($curl, CURLOPT_URL, $url);
  627. //
  628. // if (!empty($data)){
  629. // curl_setopt($curl, CURLOPT_POST, 1);
  630. // curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  631. // }
  632. // curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  633. // $output = curl_exec($curl);
  634. // curl_close($curl);
  635. // $result=preg_split("/[,\r\n]/",$output);
  636. // if($result[1]==0){
  637. // $res = "success";
  638. // }else{
  639. // $res = "curl error:".$result[1];
  640. // }
  641. // }elseif(function_exists('file_get_contents')){
  642. // $output=file_get_contents($url.$data);
  643. // $result=preg_split("/[,\r\n]/",$output);
  644. // if($result[1]==0){
  645. // $res = "success";
  646. // }else{
  647. // $res = "error:".$result[1];
  648. // }
  649. // }else{
  650. // $res="error";
  651. // }
  652. // return $res;
  653. // }
  654. //}
  655. //
  656. //
  657. //if( ! function_exists('sendCaixin')) {
  658. // //return true or false
  659. // function sendCaixin($mobile){
  660. //
  661. // $post_data =$data =$msgdata = array();
  662. //
  663. // $url ="http://www.baidu.com";//回调URL
  664. // $key ="6MG5jNK4Q15907";//密码
  665. ////文字body
  666. // $data['frame']="1"; //文字标识
  667. // $data['part'] ="1";//文字标识
  668. // $data['type']="1" ;
  669. // $data['content']=base64_encode('亲爱的朋友,“芜湖小洲蔬菜”,芜湖人的掌上菜篮子,已是我每天买菜必备工具。好东西首先想到了您,赶快关注使用吧!');
  670. //
  671. ////图片body
  672. // $msgdata['frame']="1";
  673. // $msgdata['part'] ="2";//图片标识
  674. // $msgdata['type']="2" ;//图片标识
  675. // $msgdata['content']=base64_encode(file_get_contents(public_path('app/wap/images/')."qrcode.jpg"));//图片
  676. //
  677. // $post_data['account'] ="C8636841";//账号
  678. // $post_data['ext_id']="72175534217316595927";//自传参数
  679. // $post_data['msg']=json_encode(array($data,$msgdata)) ;//json
  680. // $post_data['phones'] = $mobile;//手机
  681. // $post_data['timestamp'] = time();//时间戳
  682. //
  683. // $post_data['title']= '芜湖小洲蔬菜'; //标题
  684. //
  685. // $sign ='account=' . $post_data['account'].'ext_id=' . $post_data['ext_id'].'msg=' . $post_data['msg'].'phones=' . $post_data['phones'].'timestamp=' . $post_data['timestamp'].'title=' . $post_data['title'].'url=' . $url.'key=' . $key;
  686. // $sign=md5($sign); //加密
  687. // $post_data['sign']=$sign;
  688. // $post_data['url']=$url;
  689. //
  690. // $url='http://caixin.253.com/api/send?';
  691. // $data = http_build_query($post_data);
  692. //
  693. // if(function_exists('curl_init')){
  694. // $curl = curl_init();
  695. // curl_setopt($curl, CURLOPT_URL, $url);
  696. //
  697. // if (!empty($data)){
  698. // curl_setopt($curl, CURLOPT_POST, 1);
  699. // curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  700. // }
  701. // curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  702. // $output = curl_exec($curl);
  703. // curl_close($curl);
  704. // $res = json_decode($output);
  705. // if(is_array($res)&&$res['code']==1){
  706. // return true;
  707. // }
  708. //
  709. // }
  710. // return false;
  711. // }
  712. //}