2 回复
这里只能填自己的服务器域名。
然后把小程序获取的code提交到你的服务器换取openid和3rd_sessionkey
我的代码示例:
public function check_code(){ $arr=array('errcode'=>1,'errmsg'=>'error'); if(isset($_POST['code'])){ $result = $this->http_get('https://api.weixin.qq.com/sns/jscode2session?appid='.$this->appid.'&secret='.$this->appsecret.'&js_code='.$_POST['code'].'&grant_type=authorization_code'); if ($result){ $json = json_decode($result,true); if (!$json || isset($json['errcode'])) { $this->errCode = $json['errcode']; $this->errMsg = $json['errmsg']; echo json_encode($arr); return; } $trd_session='session_key_'.$json['openid']; $cachevalue=array('session_key'=>$json['session_key'],'openid'=>$json['openid']); $this->setCache($trd_session,json_encode($cachevalue),$json['expires_in']); $arr=array('errcode'=>0,'errmsg'=>'ok','trd_session'=>$trd_session,'expires'=>$json['expires_in']); } } echo json_encode($arr);} |
