收藏
回答

获取openid需要配置服务器信息,但是却不能配置



我也很绝望啊。。有没有老铁遇到这问题?如何处理?

就是https://api.weixin.qq.com

不能用了?

回答关注问题邀请回答
收藏

2 个回答

  • 迷惘
    迷惘
    2017-06-08

    请使用wx.login进行获取授权code,然后传到服务器再获取openid

    2017-06-08
    有用
    回复
  • 云选片~影楼在线选片小程序
    云选片~影楼在线选片小程序
    2017-06-08

    这里只能填自己的服务器域名。

    然后把小程序获取的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);
    }


    2017-06-08
    有用
    回复
登录 后发表内容