Exemplo n.º 1
0
 /**
  * 获取封面图片素材媒体列表
  * @method getThumbMaterialMediaList
  * @since 0.0.1
  * @return {array}
  * @example $this->getThumbMaterialMediaList();
  */
 public function getThumbMaterialMediaList()
 {
     $materialMedias = [];
     foreach ($this->thumbMaterialMediaIdList as $thumb_material_media_id) {
         $materialMedias[$thumb_material_media_id] = WechatMaterialMedia::findOne($thumb_material_media_id);
     }
     return $materialMedias;
 }
Exemplo n.º 2
0
 /**
  * 获取素材媒体
  * @method getMaterialMedia
  * @since 0.0.1
  * @return {object}
  * @example $this->getMaterialMedia();
  */
 public function getMaterialMedia()
 {
     return $this->hasOne(WechatMaterialMedia::classname(), ['id' => 'material_media_id']);
 }
Exemplo n.º 3
0
 /**
  * 获取缩略图媒体
  * @method getThumbMaterialMedia
  * @since 0.0.1
  * @return {object}
  * @example $this->getThumbMaterialMedia();
  */
 protected function getThumbMaterialMedia()
 {
     $media = WechatMaterialMedia::findOne(['appid' => $this->manager->app->appid, 'material_id' => $this->thumb_material_id, 'expired_at' => 0]);
     if (!$media) {
         $media = WechatMaterialMedia::findOne($this->manager->addMaterial($this->thumb_material_id));
     }
     return $media;
 }
Exemplo n.º 4
0
 /**
  * 新增临时素材
  *
  * @since 0.0.1
  * @param {integer} $material_id 素材id
  * @return {integer}
  * @example \Yii::$app->wechat->addMedia($material_id);
  */
 public function addMedia($material_id)
 {
     $material = WechatMaterial::findOne($material_id);
     if (!$material) {
         throw new ErrorException('数据查询失败');
     }
     $data = $this->getData('/cgi-bin/media/upload', ['access_token' => $this->getAccessToken(), 'type' => $material->type], ['media' => '@' . $material->localFile]);
     $material->cleanTmp();
     if ($this->errcode == 0) {
         $materialMedia = new WechatMaterialMedia();
         $materialMedia->appid = $this->app->appid;
         $materialMedia->material_id = $material->id;
         $materialMedia->media_id = $data['media_id'];
         $materialMedia->expired_at = $data['created_at'] + $this->effectiveTimeOfTemporaryMaterial;
         if ($materialMedia->save()) {
             return $materialMedia->id;
         }
     }
     return 0;
 }