微信用户经过网页基本授权后jsdk 就报errmsg :"config:invalid signatrue"
微信用户经过网页基本授权后jsdk 就报errmsg :"config:invalid signatrue"(前提我不经过网页基本授权进来是不会报错接口也可以用)
这是不经过基本授权jsdk是ok的
这是经过授权
代码:
//JS-SDK使用权限签名算法
public function getJsapiTicket(){
$jsapi=D('jsapi');
$jsapi_data=$jsapi->selt_jsapi();
foreach ($jsapi_data as $v) {
}
if($v['time']>time()){
return $v['jsapi'];
}else{
$access_token=$this->access_token();
$urls="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi";
$res=$this->http_curl($urls);
$jsApi_Ticket=$res['ticket'];
$con['jsapi']=$jsApi_Ticket;
$con['time']=time()+7000;
$jsapi->creat_api($con);
return $jsApi_Ticket;;
}
}
//curl抓取
public function http_curl($url,$type='get', $res='json',$postJson=''){//CURL
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if($type=='post'){
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postJson);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result=curl_exec($ch);
if($res=='json'){
if(curl_errno($ch)){
var_dump(curl_error($ch)) ;
}
return json_decode($result,true);
}
curl_close($ch);
}
//授权第一步
public function getinfo(){
$appid=C('APPID');
$redirect_uri=urlencode("http://love.cc.com/index.php/admin/index/getOpenid");
$url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appid."&redirect_uri=".$redirect_uri."&response_type=code&scope=snsapi_base&state=state#wechat_redirect";
header('location:'.$url);
}
//获取openid
public function getOpenid(){
$urlt="http://love.cc.com/index.php/Admin/index/getOpenid";
$jsapi_ticket=$this->getJsapiTicket();
$noncestr=$this->getRandcode();
$time=time();
$signature="jsapi_ticket=".$jsapi_ticket."&noncestr=".$noncestr."×tamp=".$time."&url=".$urlt;
$signature=sha1($signature);
var_dump($signature);
$appid=C('APPID');
$appsecret=C('APPSECRET');
$code=$_GET['code'];
$url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$appsecret."&code=".$code."&grant_type=authorization_code";
$res=$this->http_curl($url);
$con['openid']= $res['openid'];
$img=D('purl');
$data['data']=$img->show_data($con);
// var_dump($data);
$this->assign('openid',$con['openid']);
$this->assign('time',$time);
$this->assign('noncestr',$noncestr);
$this->assign('signature',$signature);
$this->assign($data);
$this->display('index');
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)