虎泰克博客

QQ互联登录PHP-SDK,(-1)invalid openid错误—解决方法


QQ互联登录PHP-SDK,(-1)invalid openid错误—解决方法,问题现象是:部署了P

QQ互联登录PHP-SDK,(-1)invalid openid错误—解决方法,问题现象是:部署了PHP-SDK之后,出现有时能登录,有时不能登录的情况,错误提示是:-1 client request's parameters are invalid, invalid openid 网上找过很多方法,测试了各种调试两天,终于貌似找到了解决方法: 在 callback.php页面 请按顺序放置以下几行代码 require_once("API/qqConnectAPI.php");   $qc = new QC(); $acs = $qc->qq_callback(); $oid = $qc->get_openid(); $qc = new QC($acs,$oid); $uinfo = $qc->get_user_info(); 

虎mbcph泰yqdm克_w新puamh闻x网kn_i版权所有,请勿未授权转载!!!

注意几点: 

虎fs_泰bban克h新qxs闻syzv网a版权所有,请勿未授权转载!!!

1、定义$qc 时,记得使用new 关键字 

虎tt泰mp克xsj新m闻ox网jpkly版权所有,请勿未授权转载!!!

2、要定义两次$qc= new qc(),第一次用于获取正确的access_token 和openid,第二次用于保证正确传输access_token和openid以保证api的使用 

虎utty泰sgsg克gt新pg闻lzdzm网mnshy版权所有,请勿未授权转载!!!

3、【顺序】一定要先获取access_token(即先使用qq_callback()方法),再获取openid(get_openid()方法),否则错误,作者本人因为偶然写反了顺序,花了1小时才找到错误。。。 

虎h泰_xuv克r新wh闻sgt网ufw版权所有,请勿未授权转载!!!

4、【代码位置】,为了尽量减少未知的错误,尽量保证 上述代码在整个php代码执行流程中,保持在顶端先执行(尤其注意因require等方式包含进来的代码), 

虎allql泰twe克os新g闻lrnb网p版权所有,请勿未授权转载!!!

5、【变量传递】作者推荐:在第一次new QC()之后,立即获取access_token和openid,并立即重新使用获取到的access_token和openid来重新定义QC()类(见上述代码示例),以防止变量丢失或被覆盖



Statement: all articles / drawings reproduced on this website are for the purpose of transmitting more information and facilitating discussion, which does not mean that the website, the host and the organizer agree with their opinions or confirm the authenticity of their contents. The contents of the articles are for reference only. If the rights of the original author are violated, please contact the website administrator.

Sign in to comment

Comment list

    No data