xubinbk

微信分享签名无效的问题

 

 

微信签名无效问题处理

微信登录后前端页面上的地址其实已经变了,首页地址后面加上了一串code参数,刚开始以为分享地址就是首页地址,直接在服务端代码里写死了,生成签名后返给前端页面,前端页面一直提醒签名无效,在微信js接口签名校验工具中(https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=jsapisign),生成的签名是正确的,各种找问题,后来突然发现微信登录首页地址后面有参数,所以让前端传给服务端
一个地址,然后去生成分享签名参数,分享成功。

public function getSignPackage($urls) {
$jsapiTicket = $this->getJsApiTicket();
 
// URL hardcode.
//$protocol = (!empty($_SERVER[\'HTTPS\']) && $_SERVER[\'HTTPS\'] !== \'off\' || $_SERVER[\'SERVER_PORT\'] == 443) ? "https://" : "http://";
//$url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
//$url = $protocol.$url;
$timestamp = time();
$nonceStr = $this->createNonceStr();
 
// key ASCII
$string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$urls";
$signature = sha1($string);
 
$signPackage = array(
"appId" => config(\'wx_conf\')[\'appid\'],
"nonceStr" => $nonceStr,
"timestamp" => $timestamp,
"url" => $urls,
"signature" => $signature,
"rawString" => $string
);
return $signPackage;
}

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-15
  • 2022-01-31
  • 2021-09-24
  • 2021-12-12
  • 2022-01-16
  • 2022-12-23
猜你喜欢
  • 2022-02-03
  • 2022-12-23
  • 2021-12-15
  • 2022-01-02
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案