OAuthCode.php 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. defined('ONLY_ONLY_ONLY') or exit('Access Denied');
  3. define('LOG_CATALOG',"KLY_OAuthCode");
  4. try{
  5. require_once WEB_PHY_ROOT."/base/wxsrv.php";
  6. weixin_oauthCallBack(LOG_CATALOG,function($appid,$state){
  7. if(!empty($state)){//可按业务类别进行特殊处理
  8. $stateInfo=explode(":",$state);
  9. if(count($stateInfo)==2){
  10. $bizCatalog=$stateInfo[0];
  11. $bizId=$stateInfo[1];
  12. }
  13. }
  14. //if($appid!=WeiXin111_AppID) throw new GeneralException("","传递的appid无效");
  15. $appSecret=WeiXin111_AppSecret;
  16. if($appid=="wx1c0dd76b74598921"){
  17. $appSecret="652057f8e2840a4b0906b417b0911924";
  18. }
  19. return array(
  20. "appSecret"=>$appSecret,
  21. "needUnionid"=>true,//根据是否为公众号确定是否二次获取unionid
  22. "needUserInfo"=>true,//获取用户信息
  23. );
  24. },function($appid,$state,$userInfo){
  25. //可以在此处进行$userInfo的持久化工作
  26. $nickName=$userInfo["nickname"];
  27. eeglobal_log_handler(LOG_CATALOG,"info","nickName=$nickName");
  28. });
  29. exit;
  30. }catch(Throwable $e){
  31. $friendMsg=get_class($e)=='GeneralException'?$e->friendmsg:"非常抱歉,获取微信登录信息时发生错误";
  32. throw new GeneralException("处理业务发生错误:".$e->getMessage(),$friendMsg,LOG_CATALOG,0,$e);
  33. }