Always prompt the signature error when doing the signature shared by Wechat

problem description

using Wechat"s signature verification tool, the results are consistent. Baidu has some of the same problems. Many of them say that the URL sent from the front end needs to be decode, but our URL is that the front end only needs to pass a path over, and then I splice it up and send it back to him, so this kind of problem should not occur

related codes

/ / Please paste the code text below (do not replace the code with pictures)

static function GetSign($path)
{
    $appid = env("WECHAT_APPID");
    $secret = env("WECHAT_SECRET");
    $url = self::SIGN_URL . $path;
    //accessToken
    $accessToken = Cache::remember("accessToken", 120, function () use ($appid, $secret) {
        //access_token
        $accessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$secret";
        //access_token
        $accessTokenJson = self::Curl($accessTokenUrl);
        return $accessTokenJson["access_token"];
    });
    //jsapi_ticket
    $jsapiTicket = Cache::remember("jsapiTicket", 120, function () use ($appid, $secret, $accessToken) {
        $ticketUrl = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=$accessToken&type=jsapi";
        $jsapiTicketObj = self::Curl($ticketUrl);
        return $jsapiTicketObj["ticket"];
    });

    //16
    $noncestr = str_random(16);
    //
    $time = time();
    //string1
    $jsapiTicketNew = "jsapi_ticket=$jsapiTicket&noncestr=$noncestr&timestamp=$time&url=$url";
    //string1sha1
    $signature = sha1($jsapiTicketNew);
    //
    $data = [
        "appid" => $appid,
        "timestamp" => $time,
        "nonceStr" => $noncestr,
        "signature" => $signature,
        "jsapiTicket" => $jsapiTicket,
        "url" => $url,
        "jsApiList" => [
            "onMenuShareTimeline",
            "onMenuShareAppMessage",
            "onMenuShareQQ",
            "onMenuShareWeibo",
            "onMenuShareQZone"
        ]
    ];
    //
    return $data;
}


Mar.29,2021

generally speaking, the problem should be that the url of the signature is incorrect. Let's compare it carefully first

.

Let the front end pass the complete address directly!

you need to make sure that the final url used is consistent with the value of window.location.href in the front end

.

the url that generates the signature should be consistent with the url of the current page

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e635f0-45a1e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e635f0-45a1e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?