文章分类 -  PHP

摘要:我们在项目开发中,会在某些情况会使用到 对指定的一些id需要进行优先查询,下面是使用方法 原生mysql查询例子: SELECT * from order WHERE status =1 order by field(id,11339,7005,3346) 在THINKPHP中可以这样使用: $id 阅读全文
posted @ 2022-03-23 17:07 智昕 阅读(142) 评论(0) 推荐(0)
摘要://base64图片保存 function base64Save($base64Image){ //接收base64数据 $image= $base64Image; //设置图片名称 $imageName = "l_".date("His",time())."_".rand(1111,9999).' 阅读全文
posted @ 2022-03-22 16:08 智昕 阅读(2275) 评论(0) 推荐(29)
摘要:这几天在研究MQTT协议以及protobuf,现在做安装protobuf扩展,特此记录 php-protobuf仓库地址https://github.com/allegro/php-protobuf 1、克隆代码 git clone https://github.com/allegro/php-pr 阅读全文
posted @ 2021-11-15 23:48 智昕 阅读(516) 评论(0) 推荐(10)
摘要:先通过composer安装elasticsearch composer require elasticsearch/elasticsearch 示例代码: <?php namespace app\controller; use app\BaseController; use Elasticsearc 阅读全文
posted @ 2021-11-12 18:04 智昕 阅读(1500) 评论(0) 推荐(17)
摘要:/** * 根据开始时间 和结束时间 循环生成期间内的时间信息 * @param $format_date * @return array */ function day_time_array($start_time,$end_time){ $day_list = array(); $day_key 阅读全文
posted @ 2021-09-30 16:18 智昕 阅读(152) 评论(0) 推荐(1)
摘要:我们在模型中使用条件进行软删除发现删除无效,文档上也有写 软删除的删除操作仅对模型的删除方法有效,如果直接使用数据库的删除方法则无效,例如下面的方式无效。 $user = new User; $user->where('id',1)->delete(); 使用下面闭包可以进行条件查询并进行软删除 U 阅读全文
posted @ 2021-09-27 14:37 智昕 阅读(788) 评论(0) 推荐(13)
摘要:在开发过程中会遇到多表关联查询的情况,这次使用三个表做关联查询表1:rate 表2:rate_acfee表3:rate_acfee_info表1的一条数据对应着表2的多条数据,表2的一条数据对应着表3的多条数,使用方法如下表1模型Rate: /** * 费率Model * Class Produce 阅读全文
posted @ 2021-09-19 19:39 智昕 阅读(4436) 评论(0) 推荐(35)
摘要:今天用到下载微信文章里的素材到服务器本地,写下以下方法,以做记录 //下载远程图片至本地 function downloadImageFromWeixin($url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl 阅读全文
posted @ 2021-03-16 14:52 智昕 阅读(131) 评论(0) 推荐(1)
摘要:在生成或保存文件时我们经常会遇到文件夹不存在时报错的情况,使用以下方法即可解决 //判断文件夹是否存在,没有则新建 function path_exists($path){ if (!function_exists($path)) { mkdirs($path); } } //创建文件夹 funct 阅读全文
posted @ 2021-03-16 14:50 智昕 阅读(2558) 评论(0) 推荐(19)
摘要:方法如下: //生成前六个月 function to_sex_month($mun){ $arr = array(); for($i = 1;$i <= $mun; ++$i){ $t = strtotime("-$i month"); $arr[] = date('Y-m',$t); } retu 阅读全文
posted @ 2021-02-19 14:26 智昕 阅读(622) 评论(0) 推荐(3)
摘要://获取字符串中的域名 function getStringUrl($Text) { $parttern = "/http[s]?:\/\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+/"; preg_matc 阅读全文
posted @ 2021-02-04 16:53 智昕 阅读(959) 评论(0) 推荐(3)
摘要:在用户访问时我们可以使用PHP的全局变量$_SERVER来获取操作系统和浏览器访问信息 // 获取当前请求的 User-Agent: 头部的内容。 $_SERVER['HTTP_USER_AGENT']; // 当前返回结果:Mozilla/5.0 (Windows NT 10.0; WOW64) 阅读全文
posted @ 2021-01-14 17:17 智昕 阅读(728) 评论(0) 推荐(8)
摘要:这次要开发聊天系统 , 需要用到WebSocket 我使用的是workerman+gateway,为了方便后面再用,做个简单记录 首先要特别注意的是,端口要开放,如果端口未开放,会出现连接时握手失败的情况,这里我用的商品是 801 和 802 1、安装workerman和gateway compos 阅读全文
posted @ 2021-01-14 12:41 智昕 阅读(1017) 评论(0) 推荐(6)
摘要:今天生成订单号时,使用了最简便的订单号生成方法 uniqid uniqid() 函数基于以微秒计的当前时间,生成一个唯一的 ID。 uniqid().rand(1000,9999);//并在后面加了四位随机数 现在在用的方法 date('Ymd').substr(implode(NULL, arra 阅读全文
posted @ 2020-12-31 11:48 智昕 阅读(591) 评论(0) 推荐(4)
摘要:生成配置文件 /** * 生成配置文件 * @param string $configPath 配置文件路径 * @param array $config 配置数组 */ function createConfigFile($configPath,$config=array()){ //获取配置内容 阅读全文
posted @ 2020-12-10 16:17 智昕 阅读(1250) 评论(0) 推荐(8)
摘要:今天在THINKPHP5上安装Workerman时报 Problem 1 - topthink/think-worker v3.0.5 requires topthink/framework ^6.0.0 -> satisfiable by topthink/framework[6.0.x-dev, 阅读全文
posted @ 2020-11-19 14:47 智昕 阅读(1889) 评论(0) 推荐(13)
摘要:在项目中用到小程序支付,费话不多说上代码 因为我这涉及么微信的很多开发功能 所以我把公共的方法放到的公共类中 WechatPublic <?php namespace app\zhonglian\controller\wechat; use app\BaseController; use think 阅读全文
posted @ 2020-11-04 16:35 智昕 阅读(2479) 评论(0) 推荐(11)
摘要:http_build_query()函数的作用是使用给出的关联(或下标)数组生成一个经过 URL-encode 的请求字符串。 写法格式:http_build_query ( mixed $query_data [, string $numeric_prefix [, string $arg_sep 阅读全文
posted @ 2020-10-26 14:05 智昕 阅读(724) 评论(0) 推荐(4)
摘要:在开发中我们经常会遇到AES的加解密,比如API接口,或是用户登录时存的id进行加密,有利安全 下面是AES加解密的代码 <?php namespace app\api\controller; /** * aes 加密 解密类库 * Class Zhix * @package app\common\ 阅读全文
posted @ 2020-10-26 13:21 智昕 阅读(1034) 评论(0) 推荐(4)
摘要:今天在TP5上安装 easyWechat时,执行官网安装命令 composer require overtrue/wechat:~5.0 -vvv 一直报Installation failed, reverting ./composer.json to its original content. 经 阅读全文
posted @ 2020-10-19 11:30 智昕 阅读(8240) 评论(0) 推荐(55)