/// <summary> /// 分享 /// </summary> /// <param name="type">分享类型</param> /// <param name="msg">分享信息</param> /// <param name="scene">分享场景</param> /// <returns>是否发送成功,不等于分享成功</returns> private bool share(string type, WXMediaMessage msg, shareScene scene) { SendMessageToWX.Req req = new SendMessageToWX.Req(); req.Transaction = type; req.Message = msg; req.Scene = (int)scene; return(Api.SendReq(req)); }
/// <summary> /// 分享文本 /// </summary> /// <param name="text">文本</param> /// <param name="description">描述</param> /// <param name="scene">分享场景</param> /// <returns>是否发送成功,不等于分享成功</returns> public bool Share(string text, string description = null, shareScene scene = shareScene.WXSceneSession) { if (IsApi) { WXMediaMessage msg = new WXMediaMessage(new WXTextObject(text)); msg.Description = description ?? text; return(share("text", msg, scene)); } return(false); }
/// <summary> /// 分享网页 /// </summary> /// <param name="url">网页 URI</param> /// <param name="title">标题</param> /// <param name="description">描述</param> /// <param name="thumbnail">缩略图</param> /// <param name="thumbnailNeedRecycle">缩略图是否需要回收</param> /// <param name="scene">分享场景</param> /// <returns>是否发送成功,不等于分享成功</returns> public bool ShareWeb(string url, string title, string description = null, Bitmap thumbnail = null, bool thumbnailNeedRecycle = true, shareScene scene = shareScene.WXSceneSession) { if (IsApi) { WXWebpageObject web = new WXWebpageObject(url); return(share("webpage", web, title, description, thumbnail, thumbnailNeedRecycle, scene)); } return(false); }
/// <summary> /// 分享视频 /// </summary> /// <param name="url">视频链接地址</param> /// <param name="title">标题</param> /// <param name="description">描述</param> /// <param name="thumbnail">缩略图</param> /// <param name="thumbnailNeedRecycle">缩略图是否需要回收</param> /// <param name="scene">分享场景</param> /// <returns>是否发送成功,不等于分享成功</returns> public bool ShareVideo(string url, string title, string description = null, Bitmap thumbnail = null, bool thumbnailNeedRecycle = true, shareScene scene = shareScene.WXSceneSession) { if (IsApi) { WXVideoObject video = new WXVideoObject(); video.VideoUrl = url; return(share("video", video, title, description, thumbnail, thumbnailNeedRecycle, scene)); } return(false); }
/// <summary> /// 分享音乐 /// </summary> /// <param name="url">音乐链接地址</param> /// <param name="title">标题</param> /// <param name="description">描述</param> /// <param name="thumbnail">缩略图</param> /// <param name="thumbnailNeedRecycle">缩略图是否需要回收</param> /// <param name="scene">分享场景</param> /// <returns>是否发送成功,不等于分享成功</returns> public bool ShareMusic(string url, string title, string description = null, Bitmap thumbnail = null, bool thumbnailNeedRecycle = true, shareScene scene = shareScene.WXSceneSession) { if (IsApi) { WXMusicObject music = new WXMusicObject(); music.MusicUrl = url; return(share("music", music, title, description, thumbnail, thumbnailNeedRecycle, scene)); } return(false); }
/// <summary> /// 分享多媒体 /// </summary> /// <param name="type">分享类型</param> /// <param name="mediaObject">媒体信息</param> /// <param name="title">标题</param> /// <param name="description">描述</param> /// <param name="thumbnail">缩略图</param> /// <param name="thumbnailNeedRecycle">缩略图是否需要回收</param> /// <param name="scene">分享场景</param> /// <returns>是否发送成功,不等于分享成功</returns> private bool share(string type, WXMediaMessage.IMediaObject mediaObject, string title, string description, Bitmap thumbnail, bool thumbnailNeedRecycle, shareScene scene) { WXMediaMessage msg = new WXMediaMessage(mediaObject); msg.Title = title; msg.Description = description ?? string.Empty; if (thumbnail != null) { msg.ThumbData = bmpToByteArray(thumbnail, thumbnailNeedRecycle); } return(share(type, msg, scene)); }
/// <summary> /// 分享图片 /// </summary> /// <param name="bmp">图片</param> /// <param name="thumbnail">缩略图</param> /// <param name="thumbnailNeedRecycle">缩略图是否需要回收</param> /// <param name="scene">分享场景</param> /// <returns>是否发送成功,不等于分享成功</returns> public bool ShareImage(Bitmap bmp, Bitmap thumbnail, bool thumbnailNeedRecycle = true, shareScene scene = shareScene.WXSceneSession) { if (IsApi) { WXMediaMessage msg = new WXMediaMessage(new WXImageObject(bmp)); msg.ThumbData = bmpToByteArray(thumbnail, thumbnailNeedRecycle); share("img", msg, scene); } return(false); }