1. 程式人生 > >微信jssdk簽名生成程式碼示例PHP版本

微信jssdk簽名生成程式碼示例PHP版本

    /**
     * 獲取jssdk簽名
     */
    public function signature(Request $request){
        //隨機字串
        $str = time() . rand(111111,999999). 'suibian';
        $nonce_str = substr( md5($str),5,8 );
        $timestamp = time(); //當前時間戳
        $url = $request['url'];  //需要前端傳過來

        $data = [
            'jsapi_ticket'
=> '文件有', 'noncestr' => $nonce_str, 'timestamp' => $timestamp, 'url' => $url ]; $param = ""; foreach($data as $k=>$v){ $param .= $k.'='.$v.'&'; } $p = rtrim($param,'&'
); //計算簽名 $signature = sha1($p); $response['nonce_str'] = $nonce_str; $response['timestamp'] = $timestamp; $response['signature'] = $signature; $response['url'] = $url; echo json_encode($response); }