微信jssdk签名代码

代码片段

$url = $request->get('url');
$url = urldecode($url);####注意这里url一定要是转义前的url。url地址是#去掉前面的那一窜。例如http://test.com?a=1#ff=gg,则需要签名的url地址为http://test.com?a=1

$ticket = Wechat::getJsApiTicket();
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$nonce = substr(str_shuffle(str_repeat($pool, 10)), 0, 10);
$timestamp = time();
$signature = sha1(sprintf('jsapi_ticket=%s&noncestr=%s&timestamp=%s&url=%s', $ticket, $nonce, $timestamp, $url));

return $this->response([
    'jsapi_ticket' => $ticket,
    'appId' => config('wechat.app_id'),
    'nonceStr' => $nonce,
    'timestamp' => $timestamp,
    'url' => $url,
    'signature' => $signature,
]);

猜你喜欢

转载自blog.csdn.net/u014574478/article/details/104176205
今日推荐