コード例 #1
0
ファイル: Manager.php プロジェクト: xiewulong/yii2-wechat
 /**
  * 上传图文消息内的图片
  *
  * @since 0.0.1
  * @param {string} $url_source 源url(非微信端)
  * @return {integer}
  * @example \Yii::$app->wechat->addNewsImage($url_source);
  */
 public function addNewsImage($url_source)
 {
     if ($image = WechatNewsImage::findOne(['appid' => $this->app->appid, 'url_source' => $url_source])) {
         return $image->id;
     }
     $image = new WechatNewsImage();
     $image->url_source = $url_source;
     $data = $this->getData('/cgi-bin/media/uploadimg', ['access_token' => $this->getAccessToken()], ['media' => '@' . $image->localFile]);
     $image->cleanTmp();
     if ($this->errcode == 0) {
         $image->appid = $this->app->appid;
         $image->url = $data['url'];
         if ($image->save()) {
             return $image->id;
         }
     }
     return 0;
 }