3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * 公共控制器 * Created by Mini * Time:2014-10-17 15:52:10 * * ┏┓ ┏┓ * ┏┛┻━━━━━━┻┗┓ * ┃ ┃ * ┃ ━ ┃ * ┃ ┳┛ ┗┳ ┃ * ┃ ┃ * ┃ ┻ ┃ * ┗━┓ ┏━┛ * ┃ ┃ 神兽保佑,代码无忧! * ┏━━━┛ ┃ 从此代码再无BUG! * ┏┫ ┃ ORZ ORZ ORZ ORZ....... * ┗┓ ┃ * ┗┓┏┳━━━┓ ┏┏┛ * ┣┣┃ ┣┣┃ * ┗┻┛ ┗┻┛ * */ class CreateOauth { protected $appid; //公众平台AppID protected $appsecret; //公众平台AppSecret; protected $curl_timeout; //CRUL超时时间 默认30S protected $code; //Oauth认证 回调Code protected $flag; //Oauth认证的模式 //false-->不弹出授权页面,直接跳转,只能获取用户openid //true-->弹出授权页面,可通过openid拿到昵称、性别、所在地。并且,即使在未关注的情况下,只要用户授权,也能获取其信息 protected $access_token; public function __construct ($appid = '', $appsecret = '', $curl_timeout = 30, $flag = false) { if ($appid == '' || $appsecret == '') { return false; } $this->appid = $appid; $this->appsecret = $appsecret; $this->curl_timeout = $curl_timeout; $this->flag = $flag; } /** * 作用:生成可以获得code的url */ public function createOauthUrlForCode ($redirectUrl = '') { if ($redirectUrl == '') return false; $urlObj['appid'] = $this->appid; $urlObj['redirect_uri'] = urlencode($redirectUrl); $urlObj['response_type'] = 'code'; if ($this->flag) { $urlObj["scope"] = "snsapi_userinfo"; //弹出授权页面 } else { $urlObj["scope"] = "snsapi_base"; //不弹出授权页面 } $urlObj["state"] = "STATE"."#wechat_redirect"; $bizString = $this->formatPara($urlObj); $url = 'https://open.weixin.qq.com/connect/oauth2/authorize?'.$bizString; return $url; } /** * 作用:生成可以获得openid的url */ public function createOauthUrlForOpenid () { $urlObj["appid"] = $this->appid; $urlObj["secret"] = $this->appsecret; $urlObj["code"] = $this->code; $urlObj["grant_type"] = "authorization_code"; $bizString = $this->formatPara($urlObj); return "https://api.weixin.qq.com/sns/oauth2/access_token?".$bizString; } /** * 作用:生成可以获得用户详细信息的URL */ public function createUrlForUserInfo () { $urlObj["access_token"] = $this->access_token; $urlObj["openid"] = $this->openid; $urlObj["lang"] = 'zh_CN '; $bizString = $this->formatPara($urlObj); return "https://api.weixin.qq.com/sns/userinfo?".$bizString; } /** * 作用:设置code */ public function setCode ($code_) { $this->code = $code_; } /** * 作用:通过curl向微信提交code,以获取openid */ public function getOpenid () { $url = $this->createOauthUrlForOpenid(); //初始化curl $ch = curl_init(); //设置超时 curl_setopt($ch, CURLOPT_TIMEOUT, $this->curl_timeout); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE); curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); //运行curl,结果以jason形式返回 $res = curl_exec($ch); curl_close($ch); //取出openid $data = json_decode($res,true); $this->openid = $data['openid']; $this->access_token = $data['access_token']; return $this->openid; } /** * 作用:通过curl获取用户信息 */ public function getUserInfo () { $this->getOpenid(); $url = $this->createUrlForUserInfo(); //初始化curl $ch = curl_init(); //设置超时 curl_setopt($ch, CURLOPT_TIMEOUT, $this->curl_timeout); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE); curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); //运行curl,结果以jason形式返回 $res = curl_exec($ch); curl_close($ch); //取出openid $data = json_decode($res,true); return $data; } /** * 作用:生成参数 */ protected function formatPara ($paraMap) { $buff = ''; foreach ($paraMap as $k => $v) { $buff .= $k . '=' . $v . '&'; } $reqPar = ''; if (strlen($buff) > 0) { $reqPar = substr($buff, 0, strlen($buff)-1); } return $reqPar; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vaDWO
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  159     0  E > > RETURN                                                   1

Class CreateOauth:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/vaDWO
function name:  __construct
number of ops:  19
compiled vars:  !0 = $appid, !1 = $appsecret, !2 = $curl_timeout, !3 = $flag
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV_INIT                                        !0      ''
          1        RECV_INIT                                        !1      ''
          2        RECV_INIT                                        !2      30
          3        RECV_INIT                                        !3      <false>
   37     4        IS_EQUAL                                         ~4      !0, ''
          5      > JMPNZ_EX                                         ~4      ~4, ->8
          6    >   IS_EQUAL                                         ~5      !1, ''
          7        BOOL                                             ~4      ~5
          8    > > JMPZ                                                     ~4, ->10
   38     9    > > RETURN                                                   <false>
   40    10    >   ASSIGN_OBJ                                               'appid'
         11        OP_DATA                                                  !0
   41    12        ASSIGN_OBJ                                               'appsecret'
         13        OP_DATA                                                  !1
   42    14        ASSIGN_OBJ                                               'curl_timeout'
         15        OP_DATA                                                  !2
   43    16        ASSIGN_OBJ                                               'flag'
         17        OP_DATA                                                  !3
   44    18      > RETURN                                                   null

End of function __construct

Function createoauthurlforcode:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vaDWO
function name:  createOauthUrlForCode
number of ops:  31
compiled vars:  !0 = $redirectUrl, !1 = $urlObj, !2 = $bizString, !3 = $url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV_INIT                                        !0      ''
   50     1        IS_EQUAL                                                 !0, ''
          2      > JMPZ                                                     ~4, ->4
          3    > > RETURN                                                   <false>
   51     4    >   FETCH_OBJ_R                                      ~6      'appid'
          5        ASSIGN_DIM                                               !1, 'appid'
          6        OP_DATA                                                  ~6
   52     7        INIT_FCALL                                               'urlencode'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $8      
         10        ASSIGN_DIM                                               !1, 'redirect_uri'
         11        OP_DATA                                                  $8
   53    12        ASSIGN_DIM                                               !1, 'response_type'
         13        OP_DATA                                                  'code'
   55    14        FETCH_OBJ_R                                      ~10     'flag'
         15      > JMPZ                                                     ~10, ->19
   56    16    >   ASSIGN_DIM                                               !1, 'scope'
         17        OP_DATA                                                  'snsapi_userinfo'
   55    18      > JMP                                                      ->21
   58    19    >   ASSIGN_DIM                                               !1, 'scope'
         20        OP_DATA                                                  'snsapi_base'
   61    21    >   ASSIGN_DIM                                               !1, 'state'
         22        OP_DATA                                                  'STATE%23wechat_redirect'
   62    23        INIT_METHOD_CALL                                         'formatPara'
         24        SEND_VAR_EX                                              !1
         25        DO_FCALL                                      0  $14     
         26        ASSIGN                                                   !2, $14
   63    27        CONCAT                                           ~16     'https%3A%2F%2Fopen.weixin.qq.com%2Fconnect%2Foauth2%2Fauthorize%3F', !2
         28        ASSIGN                                                   !3, ~16
   64    29      > RETURN                                                   !3
   65    30*     > RETURN                                                   null

End of function createoauthurlforcode

Function createoauthurlforopenid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vaDWO
function name:  createOauthUrlForOpenid
number of ops:  18
compiled vars:  !0 = $urlObj, !1 = $bizString
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   71     0  E >   FETCH_OBJ_R                                      ~3      'appid'
          1        ASSIGN_DIM                                               !0, 'appid'
          2        OP_DATA                                                  ~3
   72     3        FETCH_OBJ_R                                      ~5      'appsecret'
          4        ASSIGN_DIM                                               !0, 'secret'
          5        OP_DATA                                                  ~5
   73     6        FETCH_OBJ_R                                      ~7      'code'
          7        ASSIGN_DIM                                               !0, 'code'
          8        OP_DATA                                                  ~7
   74     9        ASSIGN_DIM                                               !0, 'grant_type'
         10        OP_DATA                                                  'authorization_code'
   75    11        INIT_METHOD_CALL                                         'formatPara'
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0  $9      
         14        ASSIGN                                                   !1, $9
   76    15        CONCAT                                           ~11     'https%3A%2F%2Fapi.weixin.qq.com%2Fsns%2Foauth2%2Faccess_token%3F', !1
         16      > RETURN                                                   ~11
   77    17*     > RETURN                                                   null

End of function createoauthurlforopenid

Function createurlforuserinfo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vaDWO
function name:  createUrlForUserInfo
number of ops:  15
compiled vars:  !0 = $urlObj, !1 = $bizString
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   83     0  E >   FETCH_OBJ_R                                      ~3      'access_token'
          1        ASSIGN_DIM                                               !0, 'access_token'
          2        OP_DATA                                                  ~3
   84     3        FETCH_OBJ_R                                      ~5      'openid'
          4        ASSIGN_DIM                                               !0, 'openid'
          5        OP_DATA                                                  ~5
   85     6        ASSIGN_DIM                                               !0, 'lang'
          7        OP_DATA                                                  'zh_CN+'
   86     8        INIT_METHOD_CALL                                         'formatPara'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0  $7      
         11        ASSIGN                                                   !1, $7
   87    12        CONCAT                                           ~9      'https%3A%2F%2Fapi.weixin.qq.com%2Fsns%2Fuserinfo%3F', !1
         13      > RETURN                                                   ~9
   88    14*     > RETURN                                                   null

End of function createurlforuserinfo

Function setcode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vaDWO
function name:  setCode
number of ops:  4
compiled vars:  !0 = $code_
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   93     0  E >   RECV                                             !0      
   94     1        ASSIGN_OBJ                                               'code'
          2        OP_DATA                                                  !0
   95     3      > RETURN                                                   null

End of function setcode

Function getopenid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vaDWO
function name:  getOpenid
number of ops:  65
compiled vars:  !0 = $url, !1 = $ch, !2 = $res, !3 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  101     0  E >   INIT_METHOD_CALL                                         'createOauthUrlForOpenid'
          1        DO_FCALL                                      0  $4      
          2        ASSIGN                                                   !0, $4
  103     3        INIT_FCALL_BY_NAME                                       'curl_init'
          4        DO_FCALL                                      0  $6      
          5        ASSIGN                                                   !1, $6
  105     6        INIT_FCALL_BY_NAME                                       'curl_setopt'
          7        SEND_VAR_EX                                              !1
          8        FETCH_CONSTANT                                   ~8      'CURLOPT_TIMEOUT'
          9        SEND_VAL_EX                                              ~8
         10        CHECK_FUNC_ARG                                           
         11        FETCH_OBJ_FUNC_ARG                               $9      'curl_timeout'
         12        SEND_FUNC_ARG                                            $9
         13        DO_FCALL                                      0          
  106    14        INIT_FCALL_BY_NAME                                       'curl_setopt'
         15        SEND_VAR_EX                                              !1
         16        FETCH_CONSTANT                                   ~11     'CURLOPT_URL'
         17        SEND_VAL_EX                                              ~11
         18        SEND_VAR_EX                                              !0
         19        DO_FCALL                                      0          
  107    20        INIT_FCALL_BY_NAME                                       'curl_setopt'
         21        SEND_VAR_EX                                              !1
         22        FETCH_CONSTANT                                   ~13     'CURLOPT_SSL_VERIFYPEER'
         23        SEND_VAL_EX                                              ~13
         24        SEND_VAL_EX                                              <false>
         25        DO_FCALL                                      0          
  108    26        INIT_FCALL_BY_NAME                                       'curl_setopt'
         27        SEND_VAR_EX                                              !1
         28        FETCH_CONSTANT                                   ~15     'CURLOPT_SSL_VERIFYHOST'
         29        SEND_VAL_EX                                              ~15
         30        SEND_VAL_EX                                              <false>
         31        DO_FCALL                                      0          
  109    32        INIT_FCALL_BY_NAME                                       'curl_setopt'
         33        SEND_VAR_EX                                              !1
         34        FETCH_CONSTANT                                   ~17     'CURLOPT_HEADER'
         35        SEND_VAL_EX                                              ~17
         36        SEND_VAL_EX                                              <false>
         37        DO_FCALL                                      0          
  110    38        INIT_FCALL_BY_NAME                                       'curl_setopt'
         39        SEND_VAR_EX                                              !1
         40        FETCH_CONSTANT                                   ~19     'CURLOPT_RETURNTRANSFER'
         41        SEND_VAL_EX                                              ~19
         42        SEND_VAL_EX                                              <true>
         43        DO_FCALL                                      0          
  112    44        INIT_FCALL_BY_NAME                                       'curl_exec'
         45        SEND_VAR_EX                                              !1
         46        DO_FCALL                                      0  $21     
         47        ASSIGN                                                   !2, $21
  113    48        INIT_FCALL_BY_NAME                                       'curl_close'
         49        SEND_VAR_EX                                              !1
         50        DO_FCALL                                      0          
  115    51        INIT_FCALL                                               'json_decode'
         52        SEND_VAR                                                 !2
         53        SEND_VAL                                                 <true>
         54        DO_ICALL                                         $24     
         55        ASSIGN                                                   !3, $24
  116    56        FETCH_DIM_R                                      ~27     !3, 'openid'
         57        ASSIGN_OBJ                                               'openid'
         58        OP_DATA                                                  ~27
  117    59        FETCH_DIM_R                                      ~29     !3, 'access_token'
         60        ASSIGN_OBJ                                               'access_token'
         61        OP_DATA                                                  ~29
  118    62        FETCH_OBJ_R                                      ~30     'openid'
         63      > RETURN                                                   ~30
  119    64*     > RETURN                                                   null

End of function getopenid

Function getuserinfo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vaDWO
function name:  getUserInfo
number of ops:  60
compiled vars:  !0 = $url, !1 = $ch, !2 = $res, !3 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  125     0  E >   INIT_METHOD_CALL                                         'getOpenid'
          1        DO_FCALL                                      0          
  126     2        INIT_METHOD_CALL                                         'createUrlForUserInfo'
          3        DO_FCALL                                      0  $5      
          4        ASSIGN                                                   !0, $5
  128     5        INIT_FCALL_BY_NAME                                       'curl_init'
          6        DO_FCALL                                      0  $7      
          7        ASSIGN                                                   !1, $7
  130     8        INIT_FCALL_BY_NAME                                       'curl_setopt'
          9        SEND_VAR_EX                                              !1
         10        FETCH_CONSTANT                                   ~9      'CURLOPT_TIMEOUT'
         11        SEND_VAL_EX                                              ~9
         12        CHECK_FUNC_ARG                                           
         13        FETCH_OBJ_FUNC_ARG                               $10     'curl_timeout'
         14        SEND_FUNC_ARG                                            $10
         15        DO_FCALL                                      0          
  131    16        INIT_FCALL_BY_NAME                                       'curl_setopt'
         17        SEND_VAR_EX                                              !1
         18        FETCH_CONSTANT                                   ~12     'CURLOPT_URL'
         19        SEND_VAL_EX                                              ~12
         20        SEND_VAR_EX                                              !0
         21        DO_FCALL                                      0          
  132    22        INIT_FCALL_BY_NAME                                       'curl_setopt'
         23        SEND_VAR_EX                                              !1
         24        FETCH_CONSTANT                                   ~14     'CURLOPT_SSL_VERIFYPEER'
         25        SEND_VAL_EX                                              ~14
         26        SEND_VAL_EX                                              <false>
         27        DO_FCALL                                      0          
  133    28        INIT_FCALL_BY_NAME                                       'curl_setopt'
         29        SEND_VAR_EX                                              !1
         30        FETCH_CONSTANT                                   ~16     'CURLOPT_SSL_VERIFYHOST'
         31        SEND_VAL_EX                                              ~16
         32        SEND_VAL_EX                                              <false>
         33        DO_FCALL                                      0          
  134    34        INIT_FCALL_BY_NAME                                       'curl_setopt'
         35        SEND_VAR_EX                                              !1
         36        FETCH_CONSTANT                                   ~18     'CURLOPT_HEADER'
         37        SEND_VAL_EX                                              ~18
         38        SEND_VAL_EX                                              <false>
         39        DO_FCALL                                      0          
  135    40        INIT_FCALL_BY_NAME                                       'curl_setopt'
         41        SEND_VAR_EX                                              !1
         42        FETCH_CONSTANT                                   ~20     'CURLOPT_RETURNTRANSFER'
         43        SEND_VAL_EX                                              ~20
         44        SEND_VAL_EX                                              <true>
         45        DO_FCALL                                      0          
  137    46        INIT_FCALL_BY_NAME                                       'curl_exec'
         47        SEND_VAR_EX                                              !1
         48        DO_FCALL                                      0  $22     
         49        ASSIGN                                                   !2, $22
  138    50        INIT_FCALL_BY_NAME                                       'curl_close'
         51        SEND_VAR_EX                                              !1
         52        DO_FCALL                                      0          
  140    53        INIT_FCALL                                               'json_decode'
         54        SEND_VAR                                                 !2
         55        SEND_VAL                                                 <true>
         56        DO_ICALL                                         $25     
         57        ASSIGN                                                   !3, $25
  141    58      > RETURN                                                   !3
  142    59*     > RETURN                                                   null

End of function getuserinfo

Function formatpara:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 23
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
Branch analysis from position: 10
filename:       /in/vaDWO
function name:  formatPara
number of ops:  25
compiled vars:  !0 = $paraMap, !1 = $buff, !2 = $v, !3 = $k, !4 = $reqPar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  148     0  E >   RECV                                             !0      
  149     1        ASSIGN                                                   !1, ''
  150     2      > FE_RESET_R                                       $6      !0, ->10
          3    > > FE_FETCH_R                                       ~7      $6, !2, ->10
          4    >   ASSIGN                                                   !3, ~7
  151     5        CONCAT                                           ~9      !3, '%3D'
          6        CONCAT                                           ~10     ~9, !2
          7        CONCAT                                           ~11     ~10, '%26'
          8        ASSIGN_OP                                     8          !1, ~11
  150     9      > JMP                                                      ->3
         10    >   FE_FREE                                                  $6
  153    11        ASSIGN                                                   !4, ''
  154    12        STRLEN                                           ~14     !1
         13        IS_SMALLER                                               0, ~14
         14      > JMPZ                                                     ~15, ->23
  155    15    >   INIT_FCALL                                               'substr'
         16        SEND_VAR                                                 !1
         17        SEND_VAL                                                 0
         18        STRLEN                                           ~16     !1
         19        SUB                                              ~17     ~16, 1
         20        SEND_VAL                                                 ~17
         21        DO_ICALL                                         $18     
         22        ASSIGN                                                   !4, $18
  157    23    > > RETURN                                                   !4
  158    24*     > RETURN                                                   null

End of function formatpara

End of class CreateOauth.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.61 ms | 1027 KiB | 16 Q