functions.inc.php 22 KB

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