Пример #1
0
 /**
  * 扫描
  * 
  * @param  Addons\Models\WechatUser $wechatUser  发送者
  * @param  Addons\Models\WechatAccount $account 接收者
  * @param  string $scene_id 二维码的参数值
  * @param  string $ticket   二维码的ticket,可用来换取二维码图片
  * @return string|response
  */
 public function scan(API $api, WechatUser $wechatUser, WechatAccount $account, $scene_id, $ticket)
 {
     if (($index = strpos($scene_id, 'store-')) !== FALSE) {
         $id = intval(substr($scene_id, $index + 6));
         $store = Store::find($id);
         if (!empty($store) && !empty($wechatUser->uid)) {
             $user = User::find($wechatUser->uid);
             !empty($user) && $user->stores()->sync([$store->getKey()], false);
             return $api->news([['Title' => '欢迎光临“汉派商城”,在这里,挑选您的美丽服饰,开始您的魅力之旅吧!', 'Description' => '', 'PicUrl' => url('attachment') . '?id=' . $store->user->avatar_aid, 'Url' => url('m?sid=' . $store->getKey())]])->reply([], true);
         }
     }
     //$result = (new WechatQrcode)->reply($scene_id, $ticket);
     return null;
 }
Пример #2
0
 private function uploadToWechat(API $api, Attachment $attachment, $type)
 {
     return $api->uploadMedia($attachment->create_symlink(NULL, NULL), $type, Mimes::getInstance()->mime_by_ext($attachment->ext));
 }
Пример #3
0
 public function takeEffect(Account $account)
 {
     // 	    $menu_data = array (
     // 	        'button' => array (
     // 	            0 => array (
     // 	                'name' => '新品特惠',
     // 	                'sub_button' => array (
     // 	                    0 => array (
     // 	                        'type' => 'view',
     // 	                        'name' => '优惠列表',
     // 	                        'url' => 'http://www.hanpaimall.com/m/classify',
     // 	                    ),
     // 	                ),
     // 	            ),
     // 	            1 => array (
     // 	                'type' => 'view',
     // 	                'name' => '汉派商城',
     // 	                'url' => 'http://www.hanpaimall.com/m',
     // 	            ),
     // 	            2 => array (
     // 	                'name' => '我的中心',
     // 	                'sub_button' => array (
     // 	                    0 => array (
     // 	                        'type' => 'view',
     // 	                        'name' => '管理中心',
     // 	                        'url' => 'http://www.hanpaimall.com/auth',
     // 	                    ),
     // 	                    1 => array (
     // 	                        'type' => 'view',
     // 	                        'name' => '个人中心',
     // 	                        'url' => 'http://www.hanpaimall.com/m/ucenter',
     // 	                    )
     // 	                )
     // 	            )
     // 	        )
     // 	    );
     $menu_data = ['button' => []];
     $menulist = WechatMenu::with('children')->newQuery()->where('waid', $account->getAccountID())->where('pid', 0)->orderBy('order', 'asc')->get();
     foreach ($menulist as $menu) {
         $menu_item_data = [];
         if ($menu->children->count() > 0) {
             $menu_item_data['name'] = $menu->title;
             foreach ($menu->children as $sub_menu) {
                 $menu_item_data['sub_button'][] = ['type' => 'view', 'name' => $sub_menu->title, 'url' => $sub_menu->url];
             }
         } else {
             $menu_item_data = ['type' => 'view', 'name' => $menu->title, 'url' => $menu->url];
         }
         $menu_data['button'][] = $menu_item_data;
     }
     //           var_export($menu_data);exit;
     $account = WechatAccount::findOrFail($account->getAccountID());
     $api = new API($account->toArray(), $account->getKey());
     if ($api->createMenu($menu_data)) {
         return $this->success('wechat::wechat.menu_create_succerss', url('admin/wechat/menu'));
     } else {
         return $this->failure('wechat::wechat.menu_create_failure', url('admin/wechat/menu'));
     }
 }
Пример #4
0
 /**
  * 微信推送接口,自动添加用户
  * 
  * @return string|response
  */
 public function push(Request $request, $id = 0)
 {
     $api = $account = null;
     $_config = [];
     if (empty($id)) {
         $api = new API(NULL, 0);
         if ($api->valid(true, false) && ($to = @$api->getRev()->getRevTo())) {
             $account = WechatAccount::where('account', $to)->firstOrFail();
             $api->setConfig($account->toArray() + $_config, $account->getKey());
         } else {
             return null;
         }
     } else {
         $account = WechatAccount::findOrFail($id);
         $api = new API($account->toArray() + $_config, $account->getKey());
     }
     $wechatUserTool = new WechatUserTool($api);
     $api->valid();
     $rev = $api->getRev();
     $type = $rev->getRevType();
     $from = $rev->getRevFrom();
     $to = $rev->getRevTo();
     $wechatUser = $wechatUserTool->updateWechatUser($from);
     $user = $this->user($api, $wechatUser);
     empty($wechatUser->uid) && !empty($user) && ($wechatUser->uid = $user->getKey());
     !in_array($type, [API::MSGTYPE_EVENT]) && ($message = WechatMessage::create(['waid' => $api->waid, 'wuid' => $wechatUser->getKey(), 'message_id' => $rev->getRevID(), 'type' => $type, 'transport_type' => 'receive']));
     switch ($type) {
         case API::MSGTYPE_TEXT:
             //文字消息
             $text = WechatMessageText::create(['id' => $message->getKey(), 'content' => $rev->getRevContent()]);
             return $this->text($api, $message, $text);
         case API::MSGTYPE_IMAGE:
             //图片消息
             $data = $rev->getRevPic();
             $image = WechatMessageMedia::create(['id' => $message->getKey(), 'media_id' => $data['mediaid'], 'format' => 'jpg']);
             //auto download
             return $this->image($api, $message, $image);
         case API::MSGTYPE_VOICE:
             //音频消息
             $data = $rev->getRevVoice();
             $voice = WechatMessageMedia::create(['id' => $message->getKey(), 'media_id' => $data['mediaid'], 'format' => $data['format']]);
             //auto download
             return $this->voice($api, $message, $voice);
         case API::MSGTYPE_VIDEO:
             //视频消息
             $data = $rev->getRevVideo();
             $video = WechatMessageMedia::create(['id' => $message->getKey(), 'media_id' => $data['mediaid'], 'thumb_media_id' => $data['thumbmediaid'], 'format' => 'mp4']);
             //auto download
             return $this->video($api, $message, $video);
         case API::MSGTYPE_SHORTVIDEO:
             //小视频消息
             $data = $rev->getRevVideo();
             $shortvideo = WechatMessageMedia::create(['id' => $message->getKey(), 'media_id' => $data['mediaid'], 'thumb_media_id' => $data['thumbmediaid'], 'format' => 'mp4']);
             //auto download
             return $this->shortvideo($api, $message, $shortvideo);
         case API::MSGTYPE_LOCATION:
             //地址消息
             $data = $rev->getRevGeo();
             $location = WechatMessageLocation::create(['id' => $message->getKey(), 'x' => $data['x'], 'y' => $data['y'], 'scale' => $data['scale'], 'label' => $data['label']]);
             return $this->location($api, $message, $location);
         case API::MSGTYPE_LINK:
             //链接消息
             $data = $rev->getRevLink();
             $link = WechatMessageLink::create(['id' => $message->getKey(), 'title' => $data['title'], 'description' => $data['description'], 'url' => $data['url']]);
             return $this->link($api, $message, $link);
         case API::MSGTYPE_EVENT:
             //事件
             $event = $rev->getRevEvent();
             switch ($event['event']) {
                 case 'subscribe':
                     if (empty($event['key'])) {
                         //关注微信
                         return $this->subscribe($api, $wechatUser, $account);
                     } else {
                         //扫描关注
                         return $this->scan_subscribe($api, $wechatUser, $account, $rev->getRevSceneId(), $rev->getRevTicket());
                     }
                 case 'unsubscribe':
                     //取消关注
                     return $this->unsubscribe($api, $wechatUser, $account);
                 case 'SCAN':
                     //扫描二维码
                     return $this->scan($api, $wechatUser, $account, $event['key'], $rev->getRevTicket());
                 case 'LOCATION':
                     //地址推送
                     return $this->location_event($api, $wechatUser, $account, $rev->getRevEventGeo());
                 case 'CLICK':
                     //点击触发事件
                     return $this->click($api, $wechatUser, $account, $event['key']);
                 case 'VIEW':
                     //浏览器打开
                     return $this->browser($api, $wechatUser, $account, $event['key']);
                 case 'scancode_push':
                     //扫码推事件的事件推送
                     return $this->scancode_push($api, $wechatUser, $account, $event['key'], $rev->getRevScanInfo());
                 case 'scancode_waitmsg':
                     //扫码推事件且弹出“消息接收中”提示框的事件推送
                     return $this->scancode_waitmsg($api, $wechatUser, $account, $event['key'], $rev->getRevScanInfo());
                 case 'pic_sysphoto':
                     //弹出系统拍照发图的事件推送
                     return $this->pic_sysphoto($api, $wechatUser, $account, $event['key'], $rev->getRevSendPicsInfo());
                 case 'pic_photo_or_album':
                     //弹出拍照或者相册发图的事件推送
                     return $this->pic_photo_or_album($api, $wechatUser, $account, $event['key'], $rev->getRevSendPicsInfo());
                 case 'pic_weixin':
                     //弹出微信相册发图器的事件推送
                     return $this->pic_weixin($api, $wechatUser, $account, $event['key'], $rev->getRevSendPicsInfo());
                 case 'location_select':
                     //弹出微信地址选择的事件推送
                     return $this->location_select($api, $wechatUser, $account, $event['key'], $rev->getRevSendGeoInfo());
             }
             break;
     }
 }