Inheritance: WXBaseMessage
コード例 #1
0
ファイル: MainPage.xaml.cs プロジェクト: yefuchao/WeChatSDK
        public async void ShareText()
        {
            var shareScene = ComboBox.SelectionBoxItem as ShareScene;
            if (shareScene == null)
            {
                return;
            }

            try
            {
                var scene = shareScene.Scene;
                var message = new WXTextMessage
                {
                    Title = "Sharing a text title!",
                    Text = "This is text content",
                    Description = "This is a text message.这是一个文本消息。",
                    ThumbData = null
                };
                SendMessageToWX.Req req = new SendMessageToWX.Req(message, scene);
                IWXAPI api = WXAPIFactory.CreateWXAPI("[YOUR APP ID]");
                var isValid = await api.SendReq(req);
            }
            catch (WXException ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
コード例 #2
0
        /// <summary>
        /// 文本分享到微信好友
        /// </summary>
        /// <param name="text"></param>
        /// <param name="title"></param>
        /// <param name="thumb"></param>
        public async void TextShare2SessionRequest(string text, string title, byte[] thumb)
        {
            var message = new WXTextMessage
            {
                Text = text,
                ThumbData = thumb,
                Title = title
            };
            SendMessageToWX.Req request = new SendMessageToWX.Req(message, SendMessageToWX.Req.WXSceneSession);
            IWXAPI api = WXAPIFactory.CreateWXAPI(APP_ID);

            await api.SendReq(request);
        }
コード例 #3
0
        internal static WXBaseMessage CreateMessage(int type)
        {
            WXBaseMessage result = null;

            switch (type)
            {
            case 1:
                result = new WXTextMessage();
                break;

            case 2:
                result = new WXImageMessage();
                break;

            case 3:
                result = new WXMusicMessage();
                break;

            case 4:
                result = new WXVideoMessage();
                break;

            case 5:
                result = new WXWebpageMessage();
                break;

            case 6:
                result = new WXFileMessage();
                break;

            case 7:
                result = new WXAppExtendMessage();
                break;

            case 8:
                result = new WXEmojiMessage();
                break;
            }
            return(result);
        }
コード例 #4
0
        public void share(string argsJSON) {
            var args = JsonHelper.Deserialize<string[]>(argsJSON);
            var options = JsonHelper.Deserialize<WeChatShareOptions>(args[0]);

            if (options == null) {
                dispatchResult(PluginResult.Status.JSON_EXCEPTION, ERR_INVALID_OPTIONS);
                return;
            }

            WXBaseMessage message = null;

            var messageOptions = options.message;

            if (messageOptions != null) {
                switch (messageOptions.type) {
                    case WeChatShareType.app:
                        break;
                    case WeChatShareType.emotion:
                        break;
                    case WeChatShareType.file:
                        break;
                    case WeChatShareType.image:
                        if (!String.IsNullOrEmpty(messageOptions.url)) {
                            message = new WXImageMessage(messageOptions.url);
                        } else if (!String.IsNullOrEmpty(messageOptions.data)) {
                            message = new WXImageMessage(Convert.FromBase64String(messageOptions.data));
                        } else {
                            dispatchResult(PluginResult.Status.ERROR, ERR_INVALID_OPTIONS);
                            return;
                        }
                        break;
                    case WeChatShareType.music:
                        break;
                    case WeChatShareType.video:
                        break;
                    case WeChatShareType.webpage:
                    default:
                        message = new WXWebpageMessage(messageOptions.url);
                        break;
                }

                if (message == null) {
                    dispatchResult(PluginResult.Status.ERROR, ERR_UNSUPPORTED_MEDIA_TYPE);
                    return;
                }

                message.Title = messageOptions.title;
                message.Description = messageOptions.description;

                if (!String.IsNullOrEmpty(messageOptions.thumbData)) {
                    message.ThumbData = Convert.FromBase64String(messageOptions.thumbData);
                }
            } else if (options.text != null) {
                message = new WXTextMessage(options.text);
            } else {
                dispatchResult(PluginResult.Status.ERROR, ERR_INVALID_OPTIONS);
                return;
            }

            var scene = options.scene;
            if (scene == null) {
                scene = WeChatScene.timeline;
            }

            try {
                var request = new SendMessageToWX.Req(message, (int)scene);
                api.SendReq(request);
            } catch (WXException e) {
                dispatchResult(PluginResult.Status.ERROR, e.Message);
            }
        }