functions.inc.php 22 KB

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