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×tamp=$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;
}