memberconnectfun.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. //验证登录方式
  3. function MemberConnect_CheckApptype($apptype){
  4. global $empire,$dbtbpre;
  5. $apptype=RepPostVar($apptype);
  6. $appr=$empire->fetch1("select * from {$dbtbpre}enewsmember_connect_app where apptype='$apptype' and isclose=0 limit 1");
  7. if(!$appr['id'])
  8. {
  9. printerror2('请选择登录方式','../../../');
  10. }
  11. return $appr;
  12. }
  13. //验证openid
  14. function MemberConnect_CheckOpenid($apptype,$openid){
  15. global $empire,$dbtbpre;
  16. $mcr['id']=0;
  17. $mcr['userid']=0;
  18. $apptype=RepPostVar($apptype);
  19. $openid=RepPostVar($openid);
  20. if(!$apptype||!trim($openid))
  21. {
  22. return $mcr;
  23. }
  24. $mcr=$empire->fetch1("select id,userid from {$dbtbpre}enewsmember_connect where apptype='$apptype' and bindkey='$openid' limit 1");
  25. return $mcr;
  26. }
  27. //处理登录
  28. function MemberConnect_DoLogin($apptype,$openid){
  29. global $empire,$dbtbpre;
  30. $apptype=RepPostVar($apptype);
  31. $openid=RepPostVar($openid);
  32. $mcr=MemberConnect_CheckOpenid($apptype,$openid);
  33. if($mcr['id'])
  34. {
  35. $lifetime=0;
  36. $r=$empire->fetch1("select ".eReturnSelectMemberF('*')." from ".eReturnMemberTable()." where ".egetmf('userid')."='".$mcr['userid']."' limit 1");
  37. DoEcmsMemberLogin($r,$lifetime);
  38. MemberConnect_UpdateBindLogin($mcr['id']);
  39. MemberConnect_ResetVar();
  40. printerrortourl('../../../');
  41. }
  42. else
  43. {
  44. printerrortourl('../tobind.php');
  45. }
  46. }
  47. //更新登录绑定
  48. function MemberConnect_UpdateBindLogin($id){
  49. global $empire,$dbtbpre;
  50. $id=(int)$id;
  51. $lasttime=time();
  52. $empire->query("update {$dbtbpre}enewsmember_connect set loginnum=loginnum+1,lasttime='$lasttime' where id='$id' limit 1");
  53. }
  54. //写入登陆绑定
  55. function MemberConnect_InsertBind($apptype,$openid,$userid){
  56. global $empire,$dbtbpre;
  57. $apptype=RepPostVar($apptype);
  58. $openid=RepPostVar($openid);
  59. $userid=(int)$userid;
  60. $time=time();
  61. //验证是否重复
  62. MemberConnect_CheckReBind($apptype,$userid);
  63. $empire->query("insert into {$dbtbpre}enewsmember_connect(userid,apptype,bindkey,bindtime,loginnum,lasttime) values('$userid','$apptype','$openid','$time',1,'$time');");
  64. }
  65. //验证是否绑定过
  66. function MemberConnect_CheckReBind($apptype,$userid){
  67. global $empire,$dbtbpre;
  68. $userid=(int)$userid;
  69. $apptype=RepPostVar($apptype);
  70. $num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsmember_connect where userid='$userid' and apptype='$apptype' limit 1");
  71. if($num)
  72. {
  73. printerror2("此帐号已绑定过,不能重复绑定","history.go(-1)");
  74. }
  75. }
  76. //删除登陆绑定
  77. function MemberConnect_DelBind($id){
  78. global $empire,$dbtbpre,$public_r;
  79. $user_r=islogin();//是否登陆
  80. $id=(int)$id;
  81. $user_r[userid]=(int)$user_r[userid];
  82. $sql=$empire->query("delete from {$dbtbpre}enewsmember_connect where id='$id' and userid='$user_r[userid]';");
  83. if($sql)
  84. {
  85. printerror2("已解除绑定","../memberconnect/ListBind.php");
  86. }
  87. else
  88. {
  89. printerror("DbError","history.go(-1)",1);
  90. }
  91. }
  92. //原帐号绑定登录
  93. function MemberConnect_BindUser($userid){
  94. global $empire,$dbtbpre,$public_r;
  95. $userid=(int)$userid;
  96. $apptype=RepPostVar($_SESSION['apptype']);
  97. $openid=RepPostVar($_SESSION['openid']);
  98. if(!trim($apptype)||!trim($openid))
  99. {
  100. printerror2('来自的链接不存在','../../../');
  101. }
  102. $appr=MemberConnect_CheckApptype($apptype);//验证登录方式
  103. MemberConnect_CheckBindKey($apptype,$openid);
  104. MemberConnect_InsertBind($apptype,$openid,$userid);
  105. MemberConnect_ResetVar();
  106. }
  107. //绑定验证符
  108. function MemberConnect_GetBindKey($apptype,$openid){
  109. global $ecms_config;
  110. $checkpass=md5(md5('check-'.$apptype.'-empirecms-'.$openid).'-#empire.cms!-'.$openid.'-|-empirecms-|-'.$ecms_config['cks']['ckrndtwo']);
  111. return $checkpass;
  112. }
  113. //验证绑定验证符
  114. function MemberConnect_CheckBindKey($apptype,$openid){
  115. global $ecms_config;
  116. $pass=md5(md5('check-'.$apptype.'-empirecms-'.$openid).'-#empire.cms!-'.$openid.'-|-empirecms-|-'.$ecms_config['cks']['ckrndtwo']);
  117. $checkpass=$_SESSION['openidkey'];
  118. if('dg'.$pass!='dg'.$checkpass)
  119. {
  120. printerror2('来自的链接不存在','../../../');
  121. }
  122. }
  123. //重置变量
  124. function MemberConnect_ResetVar(){
  125. $_SESSION['state']='';
  126. $_SESSION['openid']='';
  127. $_SESSION['apptype']='';
  128. $_SESSION['openidkey']='';
  129. }
  130. ?>