Bi Set (WeChat Mall) encountered problems and solutions

2018/3/15
1.Call to undefined function curl_init :
[Solution]: This means that curl_init is not defined. Find php.ini, modify extension=php_curl.dll and remove the semicolon in front.
2. Get, access_token, return NULL, and curl_errno($ch)no error is reported after writing .
Code snippet where the problem occurs:

 public function getWxAccessToken(){
    
    
         //将access_token存在session中
     if($_SESSION['access_token']&&$_SESSION['expire_time']>time()){
                //如果access_token在session中没有过期
                return $_SESSION['access_token'];
              }
     else{  
                $appid="wxcexxxxxxxxxxxx";
                $appsecret="55xxxxxxxxxxxxxxxx72";
                $url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$appsecret;
                //1.初始化
                $ch = curl_init();
                //2.设置参数
                curl_setopt($ch,CURLOPT_URL,$url);
                curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
                //3.调用接口
                $res = curl_exec($ch);
                //4.关闭
                curl_close($ch);
                //错误判断
                if(curl_errno($ch)){
                    var_dump(curl_errno($ch));
                }
                $arr = json_decode($res,true);
                $access_token=$arr['access_token'];
                $this->http_curl($url,'get','json'); 
                //将获取到的access_token存到session
                $_SESSION['access_token']=$access_token;
                $_SESSION['expire_time']=time()+7000;
                return $access_token;
              }
        }

Two problems
①: The reason for not reporting the error: The wrong judgment is written under curl_close:
[Solution]: Write curl_close at the end of the method.
②: access_token is NULL
[Solution]: Skip the SSL certificate check.

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//需要把这一句加在定义$ch的下一行

2018/3/16
3:

 public function defineItem()
    {
    
    
        header('content-type:text/html;charset=utf-8');
        $access_token = $this->getWxAccessToken();
        $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" . $access_token;
        $postArr = array(
            'button' => array(
                array('name' => urlencode('菜单一'),
                    'type' => 'click',
                    'key' => 'item1'),//第一个一级菜单
            ),
        );

        $postJson = urldecode(json_encode($postArr));//转化文字格式
        $res = $this->http_curl($url, 'post', 'json', $postJson);
        var_dump($res);
    }

In this code, $res prints out as int(60)

[Solution]: I don’t know why 60 is printed out. Because $res has the http_curl method, check this method, because there is a lot of code about curl, and it is also in the getWxAccess_token method, so the code in the getWxAccess_token method is overwritten with the code in http_curl, and the correct result is obtained: array (2) {["errcode"]=> int(0) ["errmsg"]=> string(2) "ok"}. It was found that the original code was curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false)missing, and it still made an error because the SSL certificate check was not skipped.
[Experience]:
* Note that you must skip the SSL certificate, otherwise curl cannot be collected

2018/4/1Background
management system
1.【Question】Write picture description here

 <div class="col-sm-2">
     <select class="form-control m-b" name="account" id="third" id="tr-third" >
     <option value="-1">请选择三级分类</option>
     </select>
  </div>

The js source code is as follows

var sortId = $("#third option:selected").val();//第三个下拉框
 if(0==countStandard){
 //countStandard用来记录有多少个规格
            alert("规格尚未填写");return false;
        }else if(sortId==-1){
            alert("分类尚未填写");return false;
        }else if(proName==''){
            alert("商品名称尚未填写");return false;
        }else{
          /*
            。。。。
            添加商品的操作
          */
}

It turns out that a three-level classification must be selected here. If a product has only a second-level classification, and when there is no third-level classification, when you click to add a product, it will prompt "Classification not yet selected". Because sortId takes the value of the third drop-down box.
In order to be elected to a certain level of classification, he can also add products without a sub-category, instead of the above situation, when there is no three-level classification, you can’t choose and cannot add, modify the code as follows

//PHP
 /*
     * 选择分类
     */
    public function chooseSort(){
    
    
        $sortId1 = I('sortId1');
        $sortId2 = I('sortId2');
        $sortId3 = I('sortId3');
        //判断sortId1是否为空或者是否有下级
        $where1['parent_id'] = $sortId1;
        $where2['parent_id'] = $sortId2;
        if($sortId1!='-1')
        $count1 = M('sort')->where($where1)->count();//如果选了一级,判断该一级有没有二级分类
        if($sortId2!='-1')
        $count2 = M('sort')->where($where2)->count();//如果选了二级,判断该二级有没有三级分类
        $data = array(
            'count1'=>$count1,
            'count2'=>$count2
        );
        $this->ajaxReturn(json_encode($data),'json');
    }
//js
/*
 *本来下面想用递归的,但是因为第二个下拉框要判断有没有下级分类,还要看选择了哪个,有变化,所以没想到如何简化。。。
 */
  var sortId1 = $("#tr-first option:selected").val();
        var sortId2 = $("#second option:selected").val();
        var sortId3 = $("#third option:selected").val();
        var sortId = -1;
        $.ajax({
            type: "post",
            url: "chooseSort",
            data:{sortId1: sortId1, sortId2: sortId2, sortId3: sortId3},
            cache:false,
            async:false,//同步,要十分注意这个,必须是同步,不然出了这个function(data),所赋值的sortId还是-1
            dataType:'json',
            success:function(data){
    
    
                var obj = eval("(" + data + ")");
                if (sortId1 != -1) {
                    //选了一级
                    if (obj.count1 == 0) {
                        //没有2级分类
                        //sort = true;
                        sortId = sortId1;
                    } else {
                        if (sortId2 != -1) {
                            //选了2级分类
                            if (obj.count2 == 0) {
                                //没有3级分类
                                // sort = true;
                                sortId = sortId2;
                            } else {
                                //有3级,但没选
                                if (sortId3 == -1) {
                                    sortId = -1;
                                    //  sort = true;
                                }
                                else {
                                    sortId = sortId3;
                                }
                            }
                        } else {
                            //有2级分类,但没选
                            sortId = -1;
                        }
                    }
                }
            }
        });

2. [Problem] After
solving the previous problem, a new problem came up. When a product only reaches the secondary classification, the background controller cannot find the result
Write picture description here

 $where1['product.id'] = 7;//id为7的商品只有到二级分类
 $proInfo = M('Product')
            ->where($where1)
            ->alias('product')
            ->join('sort s1 On s1.id=product.sort_id')
            ->join('sort s2 On s2.id=s1.parent_id')
            ->join('sort s3 On s3.id=s2.parent_id')
            ->field('
             product.id as pro_id,
             name as pro_name,
             put_focus as focus,
             s1.sort_name as sort_name1,
             s2.sort_name as sort_name2,
             s3.sort_name as sort_name3')
            ->find();
        var_dump($proInfo);

[Analysis]
There must be no result, because the SQL statement is

SELECT product.id as pro_id,name as pro_name,put_focus as focus,s1.sort_name as sort_name1,s2.sort_name as sort_name2,s3.sort_name as sort_name3 
FROM product 
product INNER JOIN sort s1 On s1.id=product.sort_id 
INNER JOIN sort s2 On s2.id=s1.parent_id 
INNER JOIN sort s3 On s3.id=s2.parent_id 
WHERE product.id = 7 LIMIT 1 

I joined the sort classification table again. I joined the sort table three times. The product has only a secondary classification. There will be no results if the sort table is joined three times. Therefore, it is necessary to find whether the parent id of the parent id of the sort_id of this product is 0 (Because the table setting parent_id to 0 is a first-level classification).
Table structure
Write picture description here
if an item is the parent of the parent id id is 0, prove that it is the second classification, then join the two sort the table on the line. Otherwise, it is a three-level classification.
The modified MYSQL statement is

from product
product join sort1 s1 on s1.id = product.sort_id
inner join sort1 s2 on s2.id = s1.parent_id 
where product.id = 7
//这个mysql语句还可以这样表示
select product.id,s.child,s.father,s.grandfather 
from product
join (
      select s1.id child ,s2.id father,s2.parent_id grandfather 
      from sort1 s2 
      join sort1 s1 on s2.id = s1.parent_id) s
on product.sort_id = s.child
where product.id  = 7

//还可以这样写
select parent_id from sort1
where id=(SELECT parent_id from sort1,product
          where product.id  = 7
          and product.sort_id=sort1.id)

Query results are below
Write picture description here
so we can make a judgment.

$where1['product.id'] = 6;
         //$sort = M('product')->where($where0)->select('sort_id');
        $info =  M('Product')
            ->where($where1)
            ->join('sort s1 on s1.id = product.sort_id')
            ->join('sort s2 on s2.id = s1.parent_id ')
            ->field('s2.parent_id grandfather')
            ->find();
        //var_dump( $have_father);
        $have_father  = $info['grandfather'];
      if($have_father==0){

            $proInfo = M('Product')
                ->where($where1)
                ->alias('product')
                ->join('sort s1 On s1.id=product.sort_id')
                ->join('sort s2 On s2.id=s1.parent_id')
                ->field('
            product.id as pro_id,
            name as pro_name,
            put_focus as focus,
            s1.sort_name as sort_name1,
            s2.sort_name as sort_name2
                    ')
                ->find();
        }else{

            $proInfo = M('Product')
            ->where($where1)
            ->alias('product')
            ->join('sort s1 On s1.id=product.sort_id')
            ->join('sort s2 On s2.id=s1.parent_id')
            ->join('sort s3 On s3.id=s2.parent_id')
            ->field('
            product.id as pro_id,
            name as pro_name,
            put_focus as focus,
            s1.sort_name as sort_name1,
                    s2.sort_name as sort_name2,
                    s3.sort_name as sort_name3')
            ->find();
        }

3. In addition, if you want to see the Mysql statement executed by Thinkphp, you can add this statement to config.php under conf under Common

 SHOW_PAGE_TRACE'=>true

2018/4/2
1.【Question】
Write picture description here

//出现问题的代码段
  $return_url = "/Public".explode("./Public", $destination)[1];

[Analysis] This [1] reported an error because my PHP version is 5.3.3. You can refer to this blog. PHP versions below 5.3 cannot use subscripts to directly obtain the array returned by the function.
So there are two solutions, one is to upgrade the PHP version, and the other is to rewrite the code.

$tmp = "/Public".explode("./Public", $destination);
$return_url = $tmp[1];

2. [Question] How to modify the mysql password
I upgrade to PHP version, not on the server wamp (because I did online upgrade method is not successful ...), switch to PHPstudy, under all kinds of torment mysql password do not know how Changed. So I can only change back to the original password. . .
The modification method refers to the following MySQL methods to modify the root password (recommended)

Tried first method, the third method seemingly useless because the user table view mysql database, and there is no password field, being given
the third method
Write picture description here
a first method
Write picture description here

Guess you like

Origin blog.csdn.net/sinat_35803474/article/details/79587132