Blogger Information
Blog 21
fans 2
comment 3
visits 44161
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
5.31对接微信服务器时 需要的数字签名程序,即生成signature
李洋
Original
1084 people have browsed it
  • 对接微信服务器需要的签名程序

  • 可以把这段代码写在模型层中


  • 实例

    //对接微信服务器时 需要的数字签名程序,即生成signature
        public function valid()
        {
           $signature =  input("get.signature");
           $timestamp = input("get.timestamp");
           $nonce = input("get.nonce");
           $token = "weixin";
            $tmpArr = array($timestamp, $nonce,$token);
            sort($tmpArr, SORT_STRING);
            $tmpStr = implode( $tmpArr );
            $tmpStr = sha1( $tmpStr );
    
            if ($tmpStr == $signature){
                return true;
            }else{
                return false;
            }

    运行实例 »

    点击 "运行实例" 按钮查看在线实例

  • 在控制器中调用此方法


  • 实例

     public function index(\app\index\model\Weixin $weixin)
        {
                $data = $weixin -> valid();
                if ($data){
                    exit(input("get.echostr"));  //返回的如果是true 这个地方不能是echo  echo的话会配置不成功
                }else{
                    exit("signature error");
                }
    
        }

    运行实例 »

    点击 "运行实例" 按钮查看在线实例

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post