微信开发笔记

1、token验证。服务器地址:http://***/public/index.php/index/Wechat/index
文件路径:\application\index\controller\Wechat.php

<?php
namespace app\index\controller;

use think\facade\Config;
use think\facade\Request;

class Wechat{
    public function index(){
        $token     = Config::get('wechat.official_account.default.token');    
        $echostr   = 'failure';  
        $timestamp =Request::get('timestamp');          //input('timestamp');//
        $nonce     =Request::get('nonce');              //input('nonce');// 
        $signature = Request::get('signature');         //input('signature');//
       
        $list     = array($token, $timestamp, $nonce);
        $hashcode = sort($list, SORT_STRING) ? sha1(implode('', $list)) : '';
        if($hashcode == $signature) {
            $echostr =input('echostr');
        }
        return $echostr;    // 验证时必须关闭调试模式
    }
}

 

ThinkPHP 笔记

1、查看版本号

\thinkphp\library\think\App.php

2、模板输出

目录结构

index.php 内容

<?php
namespace app\index\controller;

use think\Controller;

class Index extends Controller
{
    public function index(){              
       return $this->fetch();          
    }
}

2.1、模板 比较标签

{lt name="product.total_count" value="$product.min_count"}    
    <div class="ProductCountLow">
        库存不足:{$product.total_count}/{$product.min_count}
    </div>
{/lt}

{egt name="product.total_count" value="$product.min_count"}    
    <div class="ProductCount">
        库存:{$product.total_count}
    </div>
{/egt}

2.2、输出关联对象

public function unit(){
   return $this->belongsTo("CateProductUnitModel")->field("id","name");
}
{$product.unit.name}

 

3、路由

以下路由定义匹配,当访问 http://domain.com/index.php/product时,转到 http://domain.com/index.php/index/Product/index。写链接时别忘了index.php

Route::rule('product','index/Product/index');

4、常量问题

参考:https://blog.csdn.net/yiyuwu7069/article/details/78466400

5、文件上传

 

composer 更新报错:SSL/TLS

在项目下执行一下更新命令时报错:

composer update

[Composer\Exception\NoSslException]
The openssl extension is required for SSL/TLS protection but is not available. If you can not enable the openssl extension, you can disable this error, at your own risk, by setting the ‘disable-tls’ option to true. 

 

=======================

解决方法

进入php.ini 修改配置打开ssl

//将这行代码前的 ; 去掉
extension=php_openssl.dll

 

Devexpress 笔记

GridView显示行号

Private Sub GridView1_CustomDrawRowIndicator(sender As Object, e As DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs) Handles GridView1.CustomDrawRowIndicator
     e.Info.DisplayText = e.RowHandle.ToString()
End Sub

 

调用百度地图接口获取地理位置手机电脑通用

<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>调用百度地图接口获取位置</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
<script src="http://api.map.baidu.com/api?v=1.4" type="text/javascript"></script>
<script>
var x=document.getElementById("demo");
function getLocation(){
    if(navigator.geolocation){
       navigator.geolocation.getCurrentPosition(showPosition);
      }else{
       alert("您的浏览器不支持地理定位");
      }
      
   }
 
function showPosition(position){
    lat=position.coords.latitude;
    lon=position.coords.longitude;
    //var map = new BMap.Map("container");            // 创建Map实例
    var point = new BMap.Point(lon, lat);    // 创建点坐标
    //map.centerAndZoom(point,15);                     // 
    //map.enableScrollWheelZoom(); 
    var gc = new BMap.Geocoder();    
    gc.getLocation(point, function(rs){
       var addComp = rs.addressComponents;
       alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street);
       var local=addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street;
         document.getElementById("local").value=local;  //查找元
      });
   }
</script>
</head>
<body>
<p id="demo">点击这个按钮,获得您的位置:</p>
<button onclick="getLocation()">试一下</button>
<input type="text" id="local"/>
</body>
</html>

 

CSS 笔记

引用外部CSS。注意是 href,不是src。

<link href=”img/divcss5.css” rel=”stylesheet” type=”text/css” />

float属性似乎对div更有效

<html>
    <head>
        <title>标题</title>
        <style type="text/css">
            body{
                padding:0px;
                margin:0px;
            }
            .container{
                position:relative;
                width:950px;
                margin-left:auto;
                margin-right:auto;
                height:100%;
                background-color:#FF0000;
            }
            .left{
                float:left;
                background-color:#DDD;
                width:80%;
                height:100px;
            }
            .right{
                float:right;
                background-color:#AAA;
                width:20%;
                height:100px;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="left">左边</div>
            <div class="right">右边</div>
        </div>
</body>
</html>

 

“清除”控件高亮色

-webkit-tap-highlight-color:rgba(0,0,0,0);

 

php 树形列表

TreeView.php

<?php
class TreeView {
    public $childName = "child";
    public $parentid;
    public $id;
    public $nameColumn;
    function __construct($parentid, $id,$nameColumn) {
        $this->parentid = $parentid;
        $this->id = $id;
        $this->nameColumn=$nameColumn;
    }
    
    public function display($Nodes) {
        echo '<div class="TreeView"><ul>';
        $GroupNodes = $this->buildTree($Nodes->list, $this->parentid, $this->id);
        $this->showTree($GroupNodes);
        echo '</ul>';
    }

    function buildTree($temp, $parentid, $idKey) {
        $grouped = $this->reGroup($temp, $parentid, $idKey);
        $fnBuilder = function ($siblings) use(&$fnBuilder, $grouped, $idKey) {
            foreach ($siblings as $k => $sibling) {
                $id = $sibling[$idKey];
                if (isset($grouped[$id])) {
                    $sibling[$this->childName] = $fnBuilder($grouped[$id]);
                }
                $siblings[$k] = $sibling;
            }
            return $siblings;
        };
        $tree = $fnBuilder($grouped[0]);
        return $tree;
    }


    function showTree($grouped) {
       foreach($grouped as $subGroupKey=>$subGroup){
           if(is_array($subGroup)){              
               if($subGroupKey===$this->childName){
                   //当前有子集
                   echo '<ul>';
                   $this->showTree($subGroup);
                   echo '</ul></li>';
               }else{
                   echo '</li>';
                   $this->showTree($subGroup);
               }
           }else{
               if($subGroupKey===$this->nameColumn){
                   echo '<li><div class="clickOnCollpose"><div class="title"><a>'.$subGroup.'</a></div></div>';
               }
           }
       }
    }
   
    function reGroup($temp, $parentid, $id) {
        $group = array();
        foreach ($temp as $item) {
            $key = $item[$parentid];
            $group[$key][] = $item;
        }
        return $group;
    }
    
}
class Nodes{
    public $list;

    function __construct(){
        $this->list=array();
    }

    public function add($Node) {
        array_push($this->list, $Node);
    }
    public function removeByNode($Node) {
        for ($i = 0;$i < count($this->list);$i++) {
            if ($this->list[$i] === $Node) {
                $this->remove($i);
            }
        }
    }
    public function removeByIndex($startIndex, $length = 0) {
        array_splice($this->list, $startIndex, $lenght);
    }
    public function clear() {
        unset($this->list);        
    }    
}

?>

TreeView.css

ul{
    list-style:none;
    padding-left: 1em;
}
.clickOnCollpose{
    display: inline-block;
    background-color: #eee;
    width:100%;
    margin:4px 0px 4px 0px;
    border-radius: 6px;
    border-width: 1px;
    border-color: #aaa;
    border-style: solid;
    padding:4px;
}

.clickOnCollpose:hover{
    background-color: #337ABC;
    color:#FFFFFF;
    padding:4px;
    border-color:#FFF;
}

.title{
    float:left;
    text-indent: 10px;
}
.count-near{
    background-color:#FF0000;
    border-radius:20px;
    color:#FFF;
    font-weight:bold;
    width:20px;
    height:20px;
    text-align:center;
    float:left;
    margin-left:20px;
}
.count-far{
    background-color:#FF0000;
    border-radius:20px;
    color:#FFF;
    font-weight:bold;
    width:20px;
    height:20px;
    text-align:center;
    float:right;
}


li{
    cursor:hand;
}
.treeview{
   width:100%;
}

TreeView.js

$(document).ready(function(){
    //默认从第2级隐藏
    $(".treeView ul li").find("ul").toggle();
 
    $(".clickOnCollpose").on('click',function(){    
        //展开/收缩下级
        $(this).parent().find("ul").toggle();  
 
        //展开/收缩下下级
        $(this).parent().find("ul li ul").toggle();        
    })
 
    $(".clickOnCollpose").mouseenter(function(){
        var count=$(this).next().children().length;
        //if(count>0){
            //class修改成 count-near 更改样式
            $(this).append("<div class='count-far'> "+count+" </div>");       
        //}
    })
 
    $(".clickOnCollpose").mouseleave(function(){     
        //class修改成 count-near 更改样式
         $(this).find(".count-far").remove();
    })
 
})

==============================================================

Demo.php

<?php
require_once("TreeView.php");
?>

<html>
<head>
<title>测试</title>
<link rel="stylesheet" href="./TreeView.css" type="text/css"/>
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script src="./TreeView.js"></script>
</head>
<body>

<?php

$n=new Nodes();
$n->add( ["id" => 1, "name" => "name0-1", "parentid" => 0]);
$n->add( ["id" => 2, "name" => "name1-2", "parentid" => 1]);
$n->add( ["id" => 3, "name" => "name1-3", "parentid" => 1]);
$n->add( ["id" => 4, "name" => "name2-4", "parentid" => 2]);
$n->add( ["id" => 5, "name" => "name2-5", "parentid" => 2]);
$n->add( ["id" => 6, "name" => "name4-6", "parentid" => 4]);
$n->add( ["id" => 7, "name" => "name1-7", "parentid" => 1]);
$n->add( ["id" => 8, "name" => "name2-8", "parentid" => 2]);
$n->add( ["id" => 9, "name" => "name2-9", "parentid" => 2]);
$n->add( ["id" => 10, "name" => "name2-10", "parentid" => 2]);
$n->add( ["id" => 11, "name" => "name8-11", "parentid" => 8]);
$n->add( ["id" => 12, "name" => "name8-12", "parentid" => 8]);
$n->add( ["id" => 13, "name" => "name11-13", "parentid" => 11]);
$n->add( ["id" => 14, "name" => "name0-14", "parentid" => 0]);
$n->add( ["id" => 15, "name" => "name0-15", "parentid" => 0]);


$treeview=new TreeView("parentid","id","name");
//可写作$treeview=new TreeView(2,0,1);
$treeview->display($n);
?>
</body>
</html>