public function upload()
 {
     $media = new Media('wx8e883164d9342b1f', 'e73145bd0fdef28ea54b0b3608061c33');
     $imageId = $media->image('/Users/qloog/Downloads/demo_wx.png');
     // 上传并返回媒体ID
     $message = Message::make('image')->media($imageId);
     Log::info('message: ' . var_export($message, true));
 }
 public function testAdd()
 {
     $media = new Media(Config::APPID, Config::APPSECRET);
     $banner = $media->forever()->lists('image');
     $shelfData = $this->shelf();
     $shelf = new Shelf(Config::get());
     $response = $shelf->add(function (ShelfData $shelf) use($shelfData) {
         return $shelfData;
     }, file_get_contents('/home/pjxh/图片/pic_logo_1082168b92.png'), 'test');
     $this->assertTrue($response);
     return $response;
 }
Beispiel #3
0
 public function testGetData()
 {
     $media = new Media($this->config->appId, $this->config->appSecret);
     $image = $media->lists('image');
     //未上架
     $product = new Product();
     $product->setBaseAttr($image['item'][0]['url'], array($image['item'][0]['url'], $image['item'][0]['url']), null, '商品名', $this->categoryId)->setDetail('text', 'text')->setDetail('img', $image['item'][0]['url']);
     $testData = Yaml::parse(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Config' . DIRECTORY_SEPARATOR . 'Data.yml'));
     foreach ($testData['Overtrue\\Wechat\\Test\\Shop\\ProductTest']['testGetProperty'] as $value) {
         $product->setProperty($value['id'], $value['property_value'][0]['id']);
     }
     foreach ($testData['Overtrue\\Wechat\\Test\\Shop\\ProductTest']['testGetSku'] as $value) {
         foreach ($value['value_list'] as $key => $valueList) {
             //此判断仅是为了 让子序列少点,实际程序按照自身的逻辑来
             if ($key % 5 == 0 && $key % 2 == 0) {
                 $skuList[] = $valueList['id'];
             }
         }
         $skuInfo[] = array('id' => $value['id'], 'vid' => $skuList);
         $product->setSkuInfo($value['id'], $skuList);
     }
     foreach ($skuInfo[0]['vid'] as $vid) {
         foreach ($skuInfo[1]['vid'] as $vid1) {
             $product->setSkuList(100, 20, $image['item'][0]['url'], 100, array(array($skuInfo[0]['id'], $vid), array($skuInfo[1]['id'], $vid1)));
         }
     }
     $data = $product->setAttrext(0, 1, 1, 1)->setLocation('浙江省', '杭州市', '滨江区阿里园')->setDeliveryInfo(1, '400184180')->toArray();
     $this->assertTrue(is_array($data));
     //        //以上架
     //        $product = new Product(true);
     //        $data = $product->setBaseAttr('main_img',array('img','img'))
     //            ->setDetail('text','text')
     //            ->setDetail('img','image')
     //            //->setProperty('id','vid')
     //            //->setProperty('id','vid')
     //            ->setSkuInfo('id',array('vid','vid'))
     //            //统一售价
     //            //->setSkuList('原价','微信价','sku_ico','sku 库存');
     //            //设置sku售价
     //            ->setSkuList('原价','微信价','sku_ico','sku 库存',array('id'=>'vid','id1'=>'vid1'))
     //            ->setAttrext(0,1,1,1)
     //            ->setLocation('浙江省','杭州市','滨江区阿里园')
     //            ->setDeliveryInfo(1,'400184180')
     //            ->toArray();
     //        $this->assertTrue(is_array($data));
 }
Beispiel #4
0
 /**
  * Download image/voice/video file from wechat server.
  *
  */
 public function download()
 {
     $suffix = '';
     $filename = '';
     $app = WechatApp::getAppByOrgId($this->message->ToUserName);
     if (isset($app)) {
         if ($this->message->MsgType == 'image') {
             $suffix = '.jpg';
         }
         if ($this->message->MsgType == 'voice') {
             $suffix = '.amr';
         }
         if ($this->message->MsgType == 'shortvideo' || $this->message->MsgType == 'video') {
             $suffix = '.mp4';
         }
         $media = new Media($app->app_id, $app->app_secret);
         try {
             $filename = $media->download($this->message->MediaId, $this->message->MediaId . $suffix);
             Log::info('file' . $this->message->MediaId . $suffix . 'has been downloaded success!');
         } catch (\Exception $e) {
             Log::error('download file' . $this->message->MediaId . $suffix . ' failed:' . $e->getMessage());
         }
     }
 }
Beispiel #5
0
 /**
  * 取得远程素材的数量.
  *
  * @param AccountModel $account 公众号
  * @param string       $type    素材类型
  *
  * @return int
  */
 private function getRemoteMaterialCount($account, $type)
 {
     $mediaService = new MediaService($account->app_id, $account->app_secret);
     return $mediaService->stats($type);
 }
Beispiel #6
0
 /**
  * 设置语音
  *
  * @param string $path
  *
  * @return Voice
  */
 public function media($path)
 {
     $this->setAttribute('media_id', $this->media->voice($path));
     return $this;
 }
Beispiel #7
0
 public function testLists()
 {
     $media = new Media($this->config->appId, $this->config->appSecret);
     $response = $media->lists('image');
     $this->assertTrue(is_array($response));
 }