微信分享进入二次分享页面 提示 config:invalid signature

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012729832/article/details/79962811

lz想测试上次做的分享页面,在测二次分享的时候发现config:invalid signature签名错误;(请翻看我前几天的文章)

后来复制页面链接才知道分享链接自动带了参数,参数如下:

微信分享会根据分享的不同,为原始链接拼接如下参数:

对于IOS系统会自动增加如下参数:

朋友圈 from=timeline&isappinstalled=0
微信群 from=groupmessage&isappinstalled=0
好友分享 from=singlemessage&isappinstalled=0

对于安卓系统会自动添加如下参数:

朋友圈 from=timeline
微信群 from=groupmessage

好友分享 from=singlemessage

所以在此进入分享页面的是时候,会提示出onfig:invalid signature错误,因为当前链接与后端配置的签名url不一致了,才会导致签名错误;我们在url后面加上参数就可以了

比如:

$reurl="http://www.minshu.xin/My/index.php/Home/Index/share?";
  //分享好友链接改变
  if($_GET["from"]=='timeline'){
    $data1['url'] =$this->get_device_type()=='ios'? $reurl."from=timeline&isappinstalled=0" : $reurl."from=singlemessage";
  }elseif($_GET["from"]=='groupmessage'){
    $data1['url'] = $this->get_device_type()=='ios'? $reurl."from=groupmessage&isappinstalled=0" : $reurl."from=singlemessage";
  }elseif ($_GET["from"]=='singlemessage') {
    $data1['url'] = $this->get_device_type()=='ios'? $reurl."from=singlemessage&isappinstalled=0" : $reurl."from=singlemessage";
  }else{
    $data1['url']='http://www.minshu.xin/My/index.php/Home/Index/share';

}

//判断安卓还是苹果系统

function get_device_type()

{
 //全部变成小写字母
 $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
 $type = 'other';
 //分别进行判断
 if(strpos($agent, 'iphone') || strpos($agent, 'ipad'))
{
 $type = 'ios';
 } 
  
 if(strpos($agent, 'android'))
{
 $type = 'android';
 }
 return $type;

}


这样就不会错了,很希望可以帮到你们,还有如果需要我可以给源码。

阅读更多

thinkphp微信分享提示config:fail,invalid signature

11-20

我用的是微信公众号提供的demo里面的ssdk.pnprnjs代码用的都是demo里面的,安全域名和网页授权域名都是正确的,分享的链接、图片地址都是安全域名;rnrn为什么总是提示config:fail,invalid signaturernrn这个 $jsapiTicket = $this->getJsApiTicket(); rn我打印出来的值是空的?不知道为什么rnrn[code=php]rnGetSignPackage(); rn?> rn[/code]rnrn[code=php]appId = $appId; rn $this->appSecret = $appSecret; rn rn rn public function getSignPackage() rn $jsapiTicket = $this->getJsApiTicket(); rn $accesstoken = $this->getAccessToken(); rn rn // 注意 URL 一定要动态获取,不能 hardcode. rn $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; rn $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; rn rn $timestamp = time(); rn $nonceStr = $this->createNonceStr(); rn rn // 这里参数的顺序要按照 key 值 ASCII 码升序排序 rn $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url"; rn rn $signature = sha1($string); rn rn $signPackage = array( rn "appId" => $this->appId, rn "nonceStr" => $nonceStr, rn "timestamp" => $timestamp, rn "url" => $url, rn "signature" => $signature, rn "rawString" => $string rn ); rn return $signPackage; rn rn rn private function createNonceStr($length = 16) rn $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; rn $str = ""; rn for ($i = 0; $i < $length; $i++) rn $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); rn rn return $str; rn rn rn private function getJsApiTicket() rn // jsapi_ticket 应该全局存储与更新,以下代码以写入到文件中做示例 rn $data = json_decode(file_get_contents("jsapi_ticket.json")); rn if ($data->expire_time < time()) rn $accessToken = $this->getAccessToken(); rn // 如果是企业号用以下 URL 获取 ticket rn // $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken"; rn $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken"; rn $res = json_decode($this->httpGet($url)); rn $ticket = $res->ticket; rn if ($ticket) rn $data->expire_time = time() + 7000; rn $data->jsapi_ticket = $ticket; rn $fp = fopen("jsapi_ticket.json", "w"); rn fwrite($fp, json_encode($data)); rn fclose($fp); rn rn else rn $ticket = $data->jsapi_ticket; rn rn rn return $ticket; rn rn rn private function getAccessToken() rn // access_token 应该全局存储与更新,以下代码以写入到文件中做示例 rn $data = json_decode(file_get_contents("access_token.json")); rn if ($data->expire_time < time()) rn // 如果是企业号用以下URL获取access_token rn // $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret"; rn $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret"; rn $res = json_decode($this->httpGet($url)); rn $access_token = $res->access_token; rn if ($access_token) rn $data->expire_time = time() + 7000; rn $data->access_token = $access_token; rn $fp = fopen("access_token.json", "w"); rn fwrite($fp, json_encode($data)); rn fclose($fp); rn rn else rn $access_token = $data->access_token; rn rn return $access_token; rn rn rn private function httpGet($url) rn $curl = curl_init(); rn curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); rn curl_setopt($curl, CURLOPT_TIMEOUT, 500); rn curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); rn curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); rn curl_setopt($curl, CURLOPT_URL, $url); rn rn $res = curl_exec($curl); rn curl_close($curl); rn rn return $res; rn rn [/code]rnrn

没有更多推荐了,返回首页