我作了以下配置:
1:JS接口安全域名
2:白名单
3:在网站根目前放入验证文件
通过调试工具,可以看到从后台正确取到了返回的数据(数据见下面)
并且通过在线的调试工具,得到的签名也是一样的,但是一直报签名错误
这个问题困扰了我大半个月了,一直没有解决。求大佬指教。
- appId: "wx3030b9536ac07236"
- jsapi_ticket: "O3SMpm8bG7kJnF36aXbe89RmCkIdEstJ69OVE3SGrga-j8Ntqv6kyg5sj2DWtcxUtCXOCSBJY-JTrBeaubEJIA"
- nonceStr: "VF46MfhrLT"
- ignature: "5b176e77ef12342598e363f1a5f49e047dcbadb5"
- 关
$sarr = array(); $sarr['noncestr'] = substr(str_shuffle($this->s), 0,10); $sarr['jsapi_ticket'] = $this->getticket($this->appid,$this->scret); $sarr['timestamp'] = ''.time().''; //$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; $protocol = "https://";//由负载均衡负责HTTPS以上判断有误 // $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; $url =$this->request->param('url','','string'); // $url = encodeURIComponent($url); // 这里务必编码 // $sarr['url'] = encodeURIComponent(trim($url)); ksort($sarr); reset($sarr); $pin = ''; foreach($sarr as $k=>$v){ $pin .= $k.'='.$v.'&'; } $pin = substr($pin, 0,-1); $sign = sha1($pin); $return['appId'] = $this->appid; $return['timestamp'] = (string)$sarr['timestamp']; $return['nonceStr'] = $sarr['noncestr']; $return['signature'] = $sign; $accsss = $this->getaccess($appid,$scret); if(!$accsss)return false; $is_exists = $this->getMysql()->name('WechatInfo')->where(array('name'=>'unih5ticket'))->find(); $sign = 'add'; if($is_exists){ if($is_exists['ex_time'] > time()){ return $is_exists['cont']; } $sign = 'save'; } $url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token='.$accsss.'&type=jsapi'; $get = curlGet($url); $ginfo = json_decode($get,true); // dump($ginfo); if($ginfo['errcode'] == 0 && $ginfo['errmsg'] == 'ok'){ $s_arr = array(); $s_arr['cont'] = $ginfo['ticket']; $s_arr['create_time'] = time(); $s_arr['ex_time'] = time()+7000; if($sign == 'save'){ $this->getMysql()->name('WechatInfo')->where(array('name'=>'unih5ticket'))->update($s_arr); }else{ $s_arr['name'] = 'unih5ticket'; $this->getMysql()->name('WechatInfo')->insert($s_arr); } return $ginfo['ticket']; }else{ return false; }
大佬 ,除了前端页面,加入encodeURIComponent 编码,其它你说的,我这边都有处理。而且我刚对前端页面加上了 encodeURIComponent,也还是报签名错误