本地测试环境获取微信授权的,不用在手动跳过

本地测试环境可用。省去了后端返回假数据。
服务器上可用切换回post方法。

 public function getsessionkey()
    {
        $code = input('post.code','');
        if (!$code) {
            exit(json_encode(array('code'=>404,'msg'=>'error','data'=>"非法操作!")));
        }
        $url = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$this->xcx_appid.'&secret='.$this->xcx_appsecret.'&js_code='.$code.'&grant_type=authorization_code';
        $result = $this->httpGet($url, "GET");
        $result = json_decode($result, true);
        return DataReturn('success', 1, $result);
    }

    public function httpGet($url) {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_TIMEOUT, 500);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_URL, $url);
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }
posted @ 2020-09-29 10:21  china/xin  阅读(527)  评论(0编辑  收藏  举报