登陆

····

public function demo(){
	$app_id => 'wxxxxxxxxxxxxxxx77e',
    $secret=> '242eaxxxxxxxxxxxxxxxxxxxxxx5e1bed55',
    $login_url => "https://api.weixin.qq.com/sns/jscode2session?".
      "appid=%s&secret=%s&js_code=%s&grant_type=authorization_code"

	
         //  拼接url拼接访问微信接口
        $wxLoginUrl = sprintf($login_url ,
            $app_id ,
            $secret ,
            $code
        );
        //  发送get请求(字符串)
        $result = $this->curlGet($this->wxLoginUrl);
        $wxResult = json_decode($result, true);

        return $wxResult;
}



    /**
     * 发送网络请求
     * @param $url
     * @param int $httpCode
     * @return bool|string
     */
    public function curlGet($url, &$httpCode = 0)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

        //  不做证书效验,部署在Linux环境下请改为true
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 10);
        $file_contents = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

        return $file_contents;
    }

你可能感兴趣的:(登陆)