コード例 #1
0
 /**
  * 通过授权获取用户.
  *
  * @param string $to
  * @param string $state
  * @param string $scope
  *
  * @return Bag | null
  */
 public function authorize($to = null, $scope = 'snsapi_userinfo', $state = 'STATE')
 {
     if (!$this->input->get('state') && !$this->input->get('code')) {
         $this->redirect($to, $scope, $state);
     }
     return $this->user();
 }
コード例 #2
0
ファイル: Server.php プロジェクト: monkeylady/wechat
 /**
  * 获取微信事件类型
  *
  * @return string
  **/
 public function getMsgType()
 {
     $this->prepareInput();
     $this->call('received', array($this->input));
     $types = ['msgtype' => $this->input->get('MsgType'), 'event' => $this->input->get('Event'), 'eventkey' => $this->input->get('EventKey'), 'content' => $this->input->get('Content'), 'from_user_name' => $this->input->get('FromUserName'), 'to_user_name' => $this->input->get('ToUserName'), 'encrypt_type' => $this->input->get('encrypt_type'), 'signature' => $this->input->get('signature'), 'timestamp' => $this->input->get('timestamp'), 'nonce' => $this->input->get('nonce'), 'msg_signature' => $this->input->get('msg_signature')];
     return $types;
     //$this->input->get('MsgType').'-'.$this->input->get('Event')  .'-'.$this->input->get('EventKey') .'-'. $this->input;
 }
コード例 #3
0
ファイル: AuthBiz.php プロジェクト: shoaly/wechat-biz
 /**
  * 获取已授权用户
  *
  * @return \Overtrue\Wechat\Utils\Bag | null
  */
 public function user()
 {
     if ($this->authorizedUser || !$this->input->has('state') || !($code = $this->input->get('code')) && $this->input->has('state')) {
         return $this->authorizedUser;
     }
     $permission = $this->getAccessPermission($code);
     $user = new Bag(array('UserId' => $permission['UserId'], 'DeviceId' => $permission['DeviceId']));
     return $this->authorizedUser = $user;
 }
コード例 #4
0
ファイル: Server.php プロジェクト: nutsdo/rp-wechat
 /**
  * 处理微信的请求
  *
  * @return mixed
  */
 protected function handleRequest()
 {
     $this->call('received', array($this->input));
     if ($this->input->has('MsgId')) {
         return $this->handleMessage($this->input);
     } elseif ($this->input->has('MsgType') && $this->input->get('MsgType') === 'event') {
         return $this->handleEvent($this->input);
     }
     return false;
 }
コード例 #5
0
ファイル: Auth.php プロジェクト: iwillhappy1314/laravel-admin
 /**
  * 获取已授权用户
  *
  * @return \Overtrue\Wechat\Utils\Bag | null
  */
 public function user()
 {
     if ($this->authorizedUser || !$this->input->has('state') || !($code = $this->input->get('code')) && $this->input->has('state')) {
         return $this->authorizedUser;
     }
     $permission = $this->getAccessPermission($code);
     if ($permission['scope'] !== 'snsapi_userinfo') {
         $user = new Bag(array('openid' => $permission['openid']));
     } else {
         $user = $this->getUser($permission['openid'], $permission['access_token']);
     }
     return $this->authorizedUser = $user;
 }
コード例 #6
0
ファイル: Wechat.php プロジェクト: xutongtong/wechat
 /**
  * 获取access_token
  *
  * @return string
  */
 public function getAccessToken()
 {
     if ($this->accessToken) {
         return $this->accessToken;
     }
     $key = 'overtrue.wechat.access_token';
     if ($cached = $this->service('cache')->get($key)) {
         return $cached;
     }
     // 关闭自动加access_token参数
     self::autoRequestToken(false);
     $params = array('appid' => $this->options->get('appId'), 'secret' => $this->options->get('secret'), 'grant_type' => 'client_credential');
     $token = self::request('GET', self::API_TOKEN_GET, $params);
     // 开启自动加access_token参数
     self::autoRequestToken(true);
     $this->service('cache')->set($key, $token['access_token'], $token['expires_in']);
     return $token['access_token'];
 }
コード例 #7
0
ファイル: Media.php プロジェクト: nutsdo/rp-wechat
 /**
  * 图片素材总数
  *
  * @param string $type
  *
  * @return array|int
  */
 public function stats($type = null)
 {
     $response = $this->http->get(self::API_FOREVER_COUNT);
     $response['voice'] = $response['voice_count'];
     $response['image'] = $response['image_count'];
     $response['video'] = $response['video_count'];
     $response['news'] = $response['news_count'];
     $response = new Bag($response);
     return $type ? $response->get($type) : $response;
 }