コード例 #1
0
ファイル: Cache.php プロジェクト: xutongtong/wechat
 /**
  * 设置缓存文件前缀
  *
  * @return void
  */
 public function boot()
 {
     $this->filePrefix = Wechat::getOption('appId');
 }
コード例 #2
0
ファイル: Image.php プロジェクト: xutongtong/wechat
 /**
  * 设置图片
  *
  * @param string $path
  *
  * @return Image
  */
 public function media($path)
 {
     $this->setAttribute('media_id', Wechat::media()->image($path));
     return $this;
 }
コード例 #3
0
ファイル: User.php プロジェクト: xutongtong/wechat
 /**
  * 获取用户所在的组
  *
  * @param string $openId
  *
  * @return integer
  */
 public function getGroup($openId)
 {
     $params = array('openid' => $openId);
     $response = Wechat::request('POST', self::API_GROUP, $params);
     return $response['groupid'];
 }
コード例 #4
0
ファイル: Menu.php プロジェクト: xutongtong/wechat
 /**
  * 删除菜单
  *
  * @return boolean
  */
 public function delete()
 {
     Wechat::request('GET', self::API_DELETE);
     return true;
 }
コード例 #5
0
ファイル: Staff.php プロジェクト: xutongtong/wechat
 /**
  * 发送消息
  *
  * @param string $openId
  *
  * @return boolean
  */
 public function to($openId)
 {
     if (empty($this->message)) {
         throw new Exception("未设置要发送的消息");
     }
     $this->message->to = $openId;
     Wechat::request('POST', self::API_MESSAGE_SEND, $this->message->buildForStaff());
     return true;
 }
コード例 #6
0
ファイル: Media.php プロジェクト: xutongtong/wechat
 /**
  * 下载媒体文件
  *
  * @param string $mediaId
  * @param string $filename
  *
  * @return mixed
  */
 public function download($mediaId, $filename = '')
 {
     $params = array('media_id' => $mediaId);
     $contents = Wechat::request('GET', self::API_GET, $params);
     return $filename ? $contents : file_put_contents($filename, $contents);
 }
コード例 #7
0
ファイル: Group.php プロジェクト: xutongtong/wechat
 /**
  * 批量移动用户
  *
  * @param array   $openIds
  * @param integer $groupId
  *
  * @return boolean
  */
 public function moveUsers(array $openIds, $groupId)
 {
     $params = array('openid_list' => $openIds, 'to_groupid' => $groupId);
     Wechat::request('POST', self::API_MEMBER_BATCH_UPDATE, $params);
     return true;
 }
コード例 #8
0
ファイル: Music.php プロジェクト: xutongtong/wechat
 /**
  * 设置音乐消息封面图
  *
  * @param string $path
  *
  * @return Music
  */
 public function thumb($path)
 {
     $this->setAttribute('thumb_media_id', Wechat::media()->thumb($path));
     return $this;
 }
コード例 #9
0
ファイル: Wechat.php プロジェクト: xutongtong/wechat
 /**
  * 静态访问
  *
  * @param string $method
  * @param array  $args
  *
  * @return mixed
  */
 public static function __callStatic($method, $args)
 {
     self::requireInstance();
     return self::$instance->__call($method, $args);
 }
コード例 #10
0
ファイル: Crypt.php プロジェクト: xutongtong/wechat
 /**
  * 检验消息的真实性,并且获取解密后的明文.
  * <ol>
  *    <li>利用收到的密文生成安全签名,进行签名验证</li>
  *    <li>若验证通过,则提取xml中的加密消息</li>
  *    <li>对消息进行解密</li>
  * </ol>
  *
  * @param string $msgSignature  签名串,对应URL参数的msg_signature
  * @param string $timestamp     时间戳 对应URL参数的timestamp
  * @param string $nonce         随机串,对应URL参数的nonce
  * @param string $postXML       密文,对应POST请求的数据
  * @param string &$msg          解密后的原文,当return返回0时有效
  *
  * @return array
  */
 public function decryptMsg($msgSignature, $nonce, $timestamp, $postXML)
 {
     //提取密文
     $array = XML::parse($postXML);
     if (empty($array)) {
         throw new Exception('Invalid xml.', self::ERROR_PARSE_XML);
     }
     $encrypted = $array['Encrypt'];
     //验证安全签名
     $signature = $this->getSHA1(Wechat::getOption('token'), $timestamp, $nonce, $encrypted);
     if ($signature != $msgSignature) {
         throw new Exception('Invalid Signature.', self::ERROR_INVALID_SIGNATURE);
     }
     return XML::parse($this->decrypt($encrypted, Wechat::getOption('appId')));
 }
コード例 #11
0
ファイル: Auth.php プロジェクト: xutongtong/wechat
 /**
  * 通过code授权
  *
  * @param string $code
  *
  * @return array
  */
 protected function authorize($code)
 {
     if ($this->authResult) {
         return $this->authResult;
     }
     // 关闭自动加access_token参数
     Wechat::autoRequestToken(false);
     $params = array('appid' => Wechat::getOption('appId'), 'secret' => Wechat::getOption('secret'), 'code' => $code, 'grant_type' => 'authorization_code');
     $authResult = Wechat::request('GET', self::API_TOKEN_GET, $params);
     // 开启自动加access_token参数
     Wechat::autoRequestToken(true);
     //TODO:refresh_token机制
     return $this->authResult = $authResult;
 }