Ejemplo n.º 1
0
        /// <summary>
        /// 【异步方法】发送图文消息(点击跳转到图文消息页面)
        /// 图文消息条数限制在8条以内,注意,如果图文数超过8,则将会无响应。
        /// </summary>
        /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
        /// <param name="openId"></param>
        /// <param name="mediaId"></param>
        /// <param name="timeOut"></param>
        /// <param name="kfAccount">客服</param>
        /// <returns></returns>
        public static async Task <WxJsonResult> SendMpNewsAsync(string accessTokenOrAppId, string openId, string mediaId, int timeOut = Config.TIME_OUT, string kfAccount = "")
        {
            object data = null;

            if (kfAccount.IsNullOrWhiteSpace())
            {
                data = new
                {
                    touser  = openId,
                    msgtype = "mpnews",
                    mpnews  = new
                    {
                        media_id = mediaId
                    }
                };
            }
            else
            {
                data = new
                {
                    touser  = openId,
                    msgtype = "mpnews",
                    mpnews  = new
                    {
                        media_id = mediaId
                    },
                    CustomService = new
                    {
                        kf_account = kfAccount
                    }
                };
            }
            return(await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
            {
                return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync(accessToken, URL_FORMAT, data, timeOut: timeOut);
            }, accessTokenOrAppId));
        }
Ejemplo n.º 2
0
        public static Task <ListResultJson> ListAsync(string accessTokenOrAppId, uint msg_data_id, uint?index, uint begin, uint count, uint type, int timeOut = Config.TIME_OUT)
        {
            //返回JSON:

            /*
             * {
             * "errcode": 0,
             * "errmsg": "ok",
             * "comment": [
             * {
             * "user_comment_id": 9,
             * "create_time": 1521255525,
             * "content": "如果有什么大考验的话可能会发现自己啥都没改都白扯了吧",
             * "comment_type": 0,
             * "openid": "oufSm0Xw0nhuha_nWD6AfiZ3rgvA"
             * }
             * ],
             * "total": 1
             * }
             */

            return(ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
            {
                var urlFormat = Config.ApiMpHost + "/cgi-bin/comment/list?access_token={0}";
                var data = new
                {
                    msg_data_id = msg_data_id,
                    index = index,
                    begin = begin,
                    count = count,
                    type = type
                };

                JsonSetting jsonSetting = new JsonSetting(ignoreNulls: true);
                return await CommonJsonSend.SendAsync <ListResultJson>(accessToken, urlFormat, data, timeOut: timeOut, jsonSetting: jsonSetting).ConfigureAwait(false);
            }, accessTokenOrAppId));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 发送语音消息
        /// </summary>
        /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
        /// <param name="openId"></param>
        /// <param name="mediaId"></param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <param name="kfAccount"></param>
        /// <returns></returns>
        public static WxJsonResult SendVoice(string accessTokenOrAppId, string openId, string mediaId, int timeOut = Config.TIME_OUT, string kfAccount = "")
        {
            object data = null;

            if (kfAccount.IsNullOrWhiteSpace())
            {
                data = new
                {
                    touser  = openId,
                    msgtype = "voice",
                    voice   = new
                    {
                        media_id = mediaId
                    }
                };
            }
            else
            {
                data = new
                {
                    touser  = openId,
                    msgtype = "voice",
                    voice   = new
                    {
                        media_id = mediaId
                    },
                    CustomService = new
                    {
                        kf_account = kfAccount
                    }
                };
            }
            return(ApiHandlerWapper.TryCommonApi(accessToken =>
            {
                return CommonJsonSend.Send(accessToken, URL_FORMAT, data, timeOut: timeOut);
            }, accessTokenOrAppId));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取小程序页面的小程序码
        /// </summary>
        /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
        /// <param name="stream">储存小程序码的流</param>
        /// <param name="path">不能为空,最大长度 128 字节(如:pages/index?query=1。注:pages/index 需要在 app.json 的 pages 中定义)</param>
        /// <param name="width">小程序码的宽度</param>
        /// <param name="auto_color">自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调</param>
        /// <param name="lineColor">auth_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"}</param>
        /// <param name="timeOut">请求超时时间</param>
        /// <returns></returns>
        public static WxJsonResult GetWxaCode(string accessTokenOrAppId, Stream stream, string path,
                                              int width = 430, bool auto_color = false, LineColor lineColor = null, int timeOut = Config.TIME_OUT)
        {
            return(ApiHandlerWapper.TryCommonApi(accessToken =>
            {
                string urlFormat = Config.ApiMpHost + "/wxa/getwxacode?access_token={0}";
                var url = string.Format(urlFormat, accessToken);

                if (auto_color && lineColor == null)
                {
                    lineColor = new LineColor();//提供默认值
                }

                var data = new { path = path, width = width, line_color = lineColor };
                JsonSetting jsonSetting = new JsonSetting(true);
                SerializerHelper serializerHelper = new SerializerHelper();
                Post.Download(url, serializerHelper.GetJsonString(data, jsonSetting), stream);

                return new WxJsonResult()
                {
                    errcode = ReturnCode.请求成功
                };
            }, accessTokenOrAppId));
        }
Ejemplo n.º 5
0
        ///  <summary>
        ///  激活/绑定会员卡
        ///  </summary>
        ///  <param name="accessTokenOrAppId"></param>
        ///  <param name="membershipNumber">必填,会员卡编号,作为序列号显示在用户的卡包里。</param>
        ///  <param name="code">创建会员卡时获取的code</param>
        ///  <param name="activateEndTime">激活后的有效截至时间。若不填写默认以创建时的 data_info 为准。Unix时间戳格式。</param>
        ///  <param name="initBonus">初始积分,不填为0</param>
        ///  <param name="initBalance">初始余额,不填为0</param>
        ///  <param name="initCustomFieldValue1">创建时字段custom_field1定义类型的初始值,限制为4个汉字,12字节。</param>
        ///  <param name="initCustomFieldValue2">创建时字段custom_field2定义类型的初始值,限制为4个汉字,12字节。</param>
        ///  <param name="initCustomFieldValue3">创建时字段custom_field3定义类型的初始值,限制为4个汉字,12字节。</param>
        ///  <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <param name="cardId"></param>
        /// <param name="activateBeginTime">激活后的有效起始时间。若不填写默认以创建时的 data_info 为准。Unix时间戳格式。</param>
        ///  <returns></returns>
        public static WxJsonResult MemberCardActivate(string accessTokenOrAppId, string membershipNumber, string code, string cardId, string activateBeginTime = null, string activateEndTime = null, string initBonus = null,
                                                      string initBalance = null, string initCustomFieldValue1 = null, string initCustomFieldValue2 = null, string initCustomFieldValue3 = null, int timeOut = Config.TIME_OUT)
        {
            return(ApiHandlerWapper.TryCommonApi(accessToken =>
            {
                var urlFormat = string.Format("https://api.weixin.qq.com/card/membercard/activate?access_token={0}", accessToken);

                var data = new
                {
                    init_bonus = initBonus,
                    init_balance = initBalance,
                    membership_number = membershipNumber,
                    code = code,
                    card_id = cardId,
                    activate_begin_time = activateBeginTime,
                    activate_end_time = activateEndTime,
                    init_custom_field_value1 = initCustomFieldValue1,
                    init_custom_field_value2 = initCustomFieldValue2,
                    init_custom_field_value3 = initCustomFieldValue3,
                };

                return CommonJsonSend.Send <WxJsonResult>(null, urlFormat, data, timeOut: timeOut);
            }, accessTokenOrAppId));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 【异步方法】获取小程序页面的小程序码 不受限制
        /// </summary>
        /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
        /// <param name="stream">储存小程序码的流</param>
        /// <param name="scene">最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)</param>
        /// <param name="page">必须是已经发布的小程序页面,例如 "pages/index/index" ,根路径前不要填加'/',不能携带参数(参数请放在scene字段里),如果不填写这个字段,默认跳主页面</param>
        /// <param name="width">小程序码的宽度</param>
        /// <param name="auto_color">自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调</param>
        /// <param name="lineColor">auth_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"}</param>
        /// <param name="isHyaline">是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码,默认为 false</param>
        /// <param name="timeOut">请求超时时间</param>
        /// <returns></returns>
        public static async Task <WxJsonResult> GetWxaCodeUnlimitAsync(string accessTokenOrAppId, Stream stream,
                                                                       string scene, string page, int width = 430, bool auto_color = false, LineColor lineColor = null, bool isHyaline = false,
                                                                       int timeOut = Config.TIME_OUT)
        {
            return(await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
            {
                string urlFormat = Config.ApiMpHost + "/wxa/getwxacodeunlimit?access_token={0}";
                var url = string.Format(urlFormat, accessToken);

                if (auto_color && lineColor == null)
                {
                    lineColor = new LineColor();//提供默认值
                }

                var data = new { scene = scene, page = page, width = width, line_color = lineColor, is_hyaline = isHyaline };
                JsonSetting jsonSetting = new JsonSetting(true);
                await Post.DownloadAsync(url, SerializerHelper.GetJsonString(data, jsonSetting), stream);

                return new WxJsonResult()
                {
                    errcode = ReturnCode.请求成功
                };
            }, accessTokenOrAppId));
        }
Ejemplo n.º 7
0
        public void TryCommonApiTest()
        {
            //正确的测试
            {
                var result = ApiHandlerWapper.TryCommonApi(Senparc.Weixin.MP.CommonAPIs.CommonApi.GetMenu, base._appId);

                Assert.IsTrue(result.menu.button.Count > 0);
                Console.WriteLine(result.menu.button.Count);
            }

            //忽略appId
            {
                var result = ApiHandlerWapper.TryCommonApi(Senparc.Weixin.MP.CommonAPIs.CommonApi.GetMenu);
                Assert.IsTrue(result.menu.button.Count > 0);
                Console.WriteLine(result.menu.button.Count);
            }

            //错误的AccessToken
            {
                var appId       = MP.Containers.AccessTokenContainer.GetFirstOrDefaultAppId();
                var accessToken = MP.Containers.AccessTokenContainer.GetAccessToken(appId);
                Console.WriteLine("当前AccessToken:" + accessToken);

                try
                {
                    var result = ApiHandlerWapper.TryCommonApi(Senparc.Weixin.MP.CommonAPIs.CommonApi.GetMenu, "12345678901234567890这是错误的AccessToken");
                    Assert.Fail();//不应该执行到这里
                    Console.WriteLine("当前AccessToken:" + accessToken);
                }
                catch (WeixinMenuException ex)
                {
                    //应该执行到这里
                    Console.WriteLine(ex.Message);//如果传的是AccessToken,并且AccessToken,不会重新自动获取(因为AppId未知)。
                }
            }
        }
Ejemplo n.º 8
0
        public static async Task <MassResult> SendImageAsync(string accessTokenOrAppKey, string agentId, string mediaId, string toUser = null, string toParty = null, string toTag = null, int safe = 0,
                                                             int timeOut = Config.TIME_OUT)
        {
            return(await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
            {
                var data = new
                {
                    touser = toUser,
                    toparty = toParty,
                    totag = toTag,
                    msgtype = "image",
                    agentid = agentId,
                    image = new
                    {
                        media_id = mediaId
                    },
                    safe = safe
                };

                JsonSetting jsonSetting = new JsonSetting(true);

                return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync <MassResult>(accessToken, _urlFormat, data, CommonJsonSendType.POST, timeOut, jsonSetting: jsonSetting);
            }, accessTokenOrAppKey));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 配置设备与门店的关联关系
        /// 设备编号,若填了UUID、major、minor,则可不填设备编号,若二者都填,则以设备编号为优先
        /// UUID、major、minor,三个信息需填写完整,若填了设备编号,则可不填此信息。
        /// </summary>
        /// <param name="accessTokenOrAppId">调用接口凭证</param>
        /// <param name="deviceId">设备编号</param>
        /// <param name="uuid"></param>
        /// <param name="major"></param>
        /// <param name="minor"></param>
        /// <param name="poiId">Poi_id 的说明改为:设备关联的门店ID,关联门店后,在门店1KM的范围内有优先摇出信息的机会。</param>
        /// <param name="type">为1时,关联的门店和设备归属于同一公众账号;为2时,关联的门店为其他公众账号的门店。不填默认为1</param>
        /// <param name="timeOut"></param>
        /// <param name="poiAppid">当Type为2时,必填	关联门店所归属的公众账号的APPID</param>
        /// <returns></returns>
        public static WxJsonResult DeviceBindLocatoin(string accessTokenOrAppId, long deviceId, string uuid, long major, long minor, long poiId, string poiAppid, int type = 1, int timeOut = Config.TIME_OUT)
        {
            return(ApiHandlerWapper.TryCommonApi(accessToken =>
            {
                string url = string.Format("https://api.weixin.qq.com/shakearound/device/bindlocation?access_token={0}", accessToken.AsUrlData());

                var data = type == 2
                    ? new
                {
                    device_identifier = new
                    {
                        device_id = deviceId,
                        uuid = uuid,
                        major = major,
                        minor = minor
                    },
                    poi_id = poiId,
                    type = type,
                    poi_appid = poiAppid
                } as object
                    : new
                {
                    device_identifier = new
                    {
                        device_id = deviceId,
                        uuid = uuid,
                        major = major,
                        minor = minor
                    },
                    poi_id = poiId
                } as object;


                return CommonJsonSend.Send <WxJsonResult>(null, url, data, CommonJsonSendType.POST, timeOut);
            }, accessTokenOrAppId));
        }
Ejemplo n.º 10
0
        public void EditGetLimit(int?num, string cardid)
        {
            Func <string, WxJsonResult> fun = null;

            if (!num.HasValue)
            {
                num = 0;
            }
            WXCardLogInfo carddata = context.WXCardLogInfo.FirstOrDefault(o => o.CardId == cardid);

            if (carddata != null)
            {
                string accessToken = GetAccessToken(carddata.AppId, carddata.AppSecret);
                if (!string.IsNullOrWhiteSpace(accessToken))
                {
                    if (fun == null)
                    {
                        fun = delegate(string accessToken2)
                        {
                            string urlFormat = string.Format("https://api.weixin.qq.com/card/update?access_token={0}", accessToken2);
                            var    data      = new
                            {
                                card_id        = carddata.CardId,
                                general_coupon = new { base_info = new { get_limit = num } }
                            };
                            return(CommonJsonSend.Send <WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, 0x2710, false));
                        };
                    }
                    WxJsonResult result = ApiHandlerWapper.TryCommonApi(fun, accessToken, true);
                    if (result.errcode != ReturnCode.请求成功)
                    {
                        Log.Error("微信同步修改卡券个人限领失败", new Exception(((int)result.errcode).ToString() + ":" + result.errmsg));
                    }
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 【异步方法】根据分组进行群发【订阅号与服务号认证后均可用】
        ///
        /// 请注意:
        /// 1、该接口暂时仅提供给已微信认证的服务号
        /// 2、虽然开发者使用高级群发接口的每日调用限制为100次,但是用户每月只能接收4条,请小心测试
        /// 3、无论在公众平台网站上,还是使用接口群发,用户每月只能接收4条群发消息,多于4条的群发将对该用户发送失败。
        /// 4、群发视频时需要先调用GetVideoMediaIdResult接口获取专用的MediaId然后进行群发
        ///
        /// </summary>
        /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
        /// <param name="groupId">群发到的分组的group_id,参加用户管理中用户分组接口,若is_to_all值为true,可不填写group_id</param>
        /// <param name="value">群发媒体文件时传入mediaId,群发文本消息时传入content,群发卡券时传入cardId</param>
        /// <param name="type"></param>
        /// <param name="isToAll">用于设定是否向全部用户发送,值为true或false,选择true该消息群发给所有用户,选择false可根据group_id发送给指定群组的用户</param>
        /// <param name="sendIgnoreReprint">待群发的文章被判定为转载时,是否继续群发</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static async Task <SendResult> SendGroupMessageByGroupIdAsync(string accessTokenOrAppId, string groupId, string value, GroupMessageType type, bool isToAll = false, bool sendIgnoreReprint = false, int timeOut = Config.TIME_OUT)
        {
            return(await ApiHandlerWapper.TryCommonApiAsync(accessToken =>
            {
                const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token={0}";

                BaseGroupMessageDataByGroupId baseData = null;
                var filter = new GroupMessageByGroupId_GroupId()
                {
                    group_id = groupId,
                    is_to_all = isToAll
                };
                switch (type)
                {
                case GroupMessageType.image:
                    baseData = new GroupMessageByGroupId_ImageData()
                    {
                        filter = filter,
                        image = new GroupMessageByGroupId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "image"
                    };
                    break;

                case GroupMessageType.voice:
                    baseData = new GroupMessageByGroupId_VoiceData()
                    {
                        filter = filter,
                        voice = new GroupMessageByGroupId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "voice"
                    };
                    break;

                case GroupMessageType.mpnews:
                    baseData = new GroupMessageByGroupId_MpNewsData()
                    {
                        filter = filter,
                        mpnews = new GroupMessageByGroupId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "mpnews"
                    };
                    break;

                case GroupMessageType.video:
                    baseData = new GroupMessageByGroupId_MpVideoData()
                    {
                        filter = filter,
                        mpvideo = new GroupMessageByGroupId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "mpvideo"
                    };
                    break;

                case GroupMessageType.wxcard:
                    baseData = new GroupMessageByGroupId_WxCardData()
                    {
                        filter = filter,
                        wxcard = new GroupMessageByGroupId_WxCard()
                        {
                            card_id = value
                        },
                        msgtype = "wxcard"
                    };
                    break;

                case GroupMessageType.text:
                    baseData = new GroupMessageByGroupId_TextData()
                    {
                        filter = filter,
                        text = new GroupMessageByGroupId_Content()
                        {
                            content = value
                        },
                        msgtype = "text"
                    };
                    break;

                default:
                    throw new Exception("参数错误。");
                    //break;
                }

                baseData.send_ignore_reprint = sendIgnoreReprint ? 0 : 1;//待群发的文章被判定为转载时,是否继续群发

                return Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync <SendResult>(accessToken, urlFormat, baseData, timeOut: timeOut);
            }, accessTokenOrAppId));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 创建卡券
        /// </summary>
        /// <param name="accessTokenOrAppId"></param>
        /// <param name="cardInfo">创建卡券需要的数据,格式可以看CardCreateData.cs</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static CardCreateResultJson CreateCard(string accessTokenOrAppId, BaseCardInfo cardInfo, int timeOut = Config.TIME_OUT)
        {
            return(ApiHandlerWapper.TryCommonApi(accessToken =>
            {
                var urlFormat = string.Format("https://api.weixin.qq.com/card/create?access_token={0}", accessToken);

                CardCreateInfo cardData = null;
                CardType cardType = cardInfo.GetCardType();

                switch (cardType)
                {
                case CardType.GENERAL_COUPON:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_GeneralCoupon()
                        {
                            card_type = cardType.ToString(),
                            general_coupon = cardInfo as Card_GeneralCouponData
                        }
                    };
                    break;

                case CardType.GROUPON:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_Groupon()
                        {
                            card_type = cardType.ToString(),
                            groupon = cardInfo as Card_GrouponData
                        }
                    };
                    break;

                case CardType.GIFT:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_Gift()
                        {
                            card_type = cardType.ToString(),
                            gift = cardInfo as Card_GiftData
                        }
                    };
                    break;

                case CardType.CASH:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_Cash()
                        {
                            card_type = cardType.ToString(),
                            cash = cardInfo as Card_CashData
                        }
                    };
                    break;

                case CardType.DISCOUNT:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_DisCount()
                        {
                            card_type = cardType.ToString(),
                            discount = cardInfo as Card_DisCountData
                        }
                    };
                    break;

                case CardType.MEMBER_CARD:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_MemberCard()
                        {
                            card_type = cardType.ToString(),
                            member_card = cardInfo as Card_MemberCardData
                        }
                    };
                    break;

                case CardType.SCENIC_TICKET:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_ScenicTicket()
                        {
                            card_type = cardType.ToString(),
                            scenic_ticket = cardInfo as Card_ScenicTicketData
                        }
                    };
                    break;

                case CardType.MOVIE_TICKET:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_MovieTicket()
                        {
                            card_type = cardType.ToString(),

                            movie_ticket = cardInfo as Card_MovieTicketData
                        }
                    };
                    break;

                case CardType.BOARDING_PASS:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_BoardingPass()
                        {
                            card_type = cardType.ToString(),
                            boarding_pass = cardInfo as Card_BoardingPassData
                        }
                    };
                    break;

                case CardType.LUCKY_MONEY:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_LuckyMoney()
                        {
                            card_type = cardType.ToString(),
                            lucky_money = cardInfo as Card_LuckyMoneyData
                        }
                    };
                    break;

                case CardType.MEETING_TICKET:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_MeetingTicket()
                        {
                            card_type = cardType.ToString(),
                            meeting_ticket = cardInfo as Card_MeetingTicketData
                        }
                    };
                    break;

                default:
                    break;
                }

                var jsonSetting = new JsonSetting(true, null,
                                                  new List <Type>()
                {
                    //typeof (Modify_Msg_Operation),
                    //typeof (CardCreateInfo),
                    typeof(Card_BaseInfoBase)     //过滤Modify_Msg_Operation主要起作用的是这个
                });

                var result = CommonJsonSend.Send <CardCreateResultJson>(null, urlFormat, cardData, timeOut: timeOut,
                                                                        //针对特殊字段的null值进行过滤
                                                                        jsonSetting: jsonSetting);
                return result;
            }, accessTokenOrAppId));
        }
Ejemplo n.º 13
0
        public static CreateQrCodeResult Create(string accessTokenOrAppId, int expireSeconds, int sceneId, QrCode_ActionName actionName, string sceneStr = null, int timeOut = Config.TIME_OUT)
        {
            return(ApiHandlerWapper.TryCommonApi(accessToken =>
            {
                var urlFormat = Config.ApiMpHost + "/cgi-bin/qrcode/create?access_token={0}";
                object data = null;

                switch (actionName)
                {
                case QrCode_ActionName.QR_SCENE:
                    data = new
                    {
                        expire_seconds = expireSeconds,
                        action_name = "QR_SCENE",
                        action_info = new
                        {
                            scene = new
                            {
                                scene_id = sceneId
                            }
                        }
                    };
                    break;

                case QrCode_ActionName.QR_LIMIT_SCENE:
                    data = new
                    {
                        action_name = "QR_LIMIT_SCENE",
                        action_info = new
                        {
                            scene = new
                            {
                                scene_id = sceneId
                            }
                        }
                    };
                    break;

                case QrCode_ActionName.QR_LIMIT_STR_SCENE:
                    data = new
                    {
                        action_name = "QR_LIMIT_STR_SCENE",
                        action_info = new
                        {
                            scene = new
                            {
                                scene_str = sceneStr
                            }
                        }
                    };
                    break;

                case QrCode_ActionName.QR_STR_SCENE:
                    data = new
                    {
                        expire_seconds = expireSeconds,
                        action_name = "QR_STR_SCENE",
                        action_info = new
                        {
                            scene = new
                            {
                                scene_str = sceneStr
                            }
                        }
                    };
                    break;

                default:
                    //throw new ArgumentOutOfRangeException(nameof(actionName), actionName, null);
                    throw new ArgumentOutOfRangeException(actionName.GetType().Name, actionName, null);
                }

                return CommonJsonSend.Send <CreateQrCodeResult>(accessToken, urlFormat, data, timeOut: timeOut);
            }, accessTokenOrAppId));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 【异步方法】预览接口【订阅号与服务号认证后均可用】
        /// 注意:openId与wxName两者任选其一,同时传入以wxName优先
        /// </summary>
        /// <param name="accessTokenOrAppId"></param>
        /// <param name="value">群发媒体消息时为media_id,群发文本信息为content</param>
        /// <param name="type"></param>
        /// <param name="openId">接收消息用户对应该公众号的openid</param>
        /// <param name="wxName">接收消息用户的微信号</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static async Task <SendResult> SendGroupMessagePreviewAsync(string accessTokenOrAppId, GroupMessageType type, string value, string openId, string wxName = null, int timeOut = Config.TIME_OUT)
        {
            return(await ApiHandlerWapper.TryCommonApiAsync(accessToken =>
            {
                const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token={0}";

                BaseGroupMessageDataPreview baseData = null;
                switch (type)
                {
                case GroupMessageType.image:
                    baseData = new GroupMessagePreview_ImageData()
                    {
                        touser = openId,
                        towxname = wxName,
                        image = new GroupMessagePreview_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "image"
                    };
                    break;

                case GroupMessageType.voice:
                    baseData = new GroupMessagePreview_VoiceData()
                    {
                        touser = openId,
                        towxname = wxName,
                        voice = new GroupMessagePreview_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "voice"
                    };
                    break;

                case GroupMessageType.mpnews:
                    baseData = new GroupMessagePreview_MpNewsData()
                    {
                        touser = openId,
                        towxname = wxName,
                        mpnews = new GroupMessagePreview_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "mpnews"
                    };
                    break;

                case GroupMessageType.video:
                    baseData = new GroupMessagePreview_MpVideoData()
                    {
                        touser = openId,
                        towxname = wxName,
                        mpvideo = new GroupMessagePreview_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "mpvideo"
                    };
                    break;

                case GroupMessageType.text:
                    baseData = new GroupMessagePreview_TextData()
                    {
                        touser = openId,
                        towxname = wxName,
                        text = new GroupMessagePreview_Content()
                        {
                            content = value
                        },
                        msgtype = "text"
                    };
                    break;

                case GroupMessageType.wxcard:
                    throw new Exception("发送卡券息请使用WxCardGroupMessagePreview方法。");
                    break;

                default:
                    throw new Exception("参数错误。");
                    break;
                }
                return Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync <SendResult>(accessToken, urlFormat, baseData, timeOut: timeOut);
            }, accessTokenOrAppId));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 【异步方法】根据OpenId进行群发
        /// </summary>
        /// <param name="accessTokenOrAppId"></param>
        /// <param name="value">群发媒体文件时传入mediaId,群发文本消息时传入content,群发卡券时传入cardId</param>
        /// <param name="type"></param>
        /// <param name="openIds">openId字符串数组</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static async Task <SendResult> SendGroupMessageByOpenIdAsync(string accessTokenOrAppId, GroupMessageType type, string value, int timeOut = Config.TIME_OUT, params string[] openIds)
        {
            return(await ApiHandlerWapper.TryCommonApiAsync(accessToken =>
            {
                const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token={0}";

                BaseGroupMessageDataByOpenId baseData = null;
                switch (type)
                {
                case GroupMessageType.image:
                    baseData = new GroupMessageByOpenId_ImageData()
                    {
                        touser = openIds,
                        image = new GroupMessageByOpenId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "image"
                    };
                    break;

                case GroupMessageType.voice:
                    baseData = new GroupMessageByOpenId_VoiceData()
                    {
                        touser = openIds,
                        voice = new GroupMessageByOpenId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "voice"
                    };
                    break;

                case GroupMessageType.mpnews:
                    baseData = new GroupMessageByOpenId_MpNewsData()
                    {
                        touser = openIds,
                        mpnews = new GroupMessageByOpenId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "mpnews"
                    };
                    break;

                case GroupMessageType.wxcard:
                    baseData = new GroupMessageByOpenId_WxCardData()
                    {
                        touser = openIds,
                        wxcard = new GroupMessageByOpenId_WxCard()
                        {
                            card_id = value
                        },
                        msgtype = "wxcard"
                    };
                    break;

                case GroupMessageType.video:
                    throw new Exception("发送视频信息请使用SendVideoGroupMessageByOpenId方法。");
                    break;

                case GroupMessageType.text:
                    baseData = new GroupMessageByOpenId_TextData()
                    {
                        touser = openIds,
                        text = new GroupMessageByOpenId_Content()
                        {
                            content = value
                        },
                        msgtype = "text"
                    };
                    break;

                default:
                    throw new Exception("参数错误。");
                    break;
                }
                return Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync <SendResult>(accessToken, urlFormat, baseData, timeOut: timeOut);
            }, accessTokenOrAppId));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 根据分组进行群发【订阅号与服务号认证后均可用】
        ///
        /// 请注意:
        /// 1、该接口暂时仅提供给已微信认证的服务号
        /// 2、虽然开发者使用高级群发接口的每日调用限制为100次,但是用户每月只能接收4条,请小心测试
        /// 3、无论在公众平台网站上,还是使用接口群发,用户每月只能接收4条群发消息,多于4条的群发将对该用户发送失败。
        /// 4、群发视频时需要先调用GetVideoMediaIdResult接口获取专用的MediaId然后进行群发
        ///
        /// </summary>
        /// <param name="accessTokenOrAppId"></param>
        /// <param name="groupId">群发到的分组的group_id,参加用户管理中用户分组接口,若is_to_all值为true,可不填写group_id</param>
        /// <param name="value">群发媒体文件时传入mediaId,群发文本消息时传入content,群发卡券时传入cardId</param>
        /// <param name="type"></param>
        /// <param name="isToAll">用于设定是否向全部用户发送,值为true或false,选择true该消息群发给所有用户,选择false可根据group_id发送给指定群组的用户</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static SendResult SendGroupMessageByGroupId(string accessTokenOrAppId, string groupId, string value, GroupMessageType type, bool isToAll = false, int timeOut = Config.TIME_OUT)
        {
            return(ApiHandlerWapper.TryCommonApi(accessToken =>
            {
                const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token={0}";

                BaseGroupMessageDataByGroupId baseData = null;
                switch (type)
                {
                case GroupMessageType.image:
                    baseData = new GroupMessageByGroupId_ImageData()
                    {
                        filter = new GroupMessageByGroupId_GroupId()
                        {
                            group_id = groupId,
                            is_to_all = isToAll
                        },
                        image = new GroupMessageByGroupId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "image"
                    };
                    break;

                case GroupMessageType.voice:
                    baseData = new GroupMessageByGroupId_VoiceData()
                    {
                        filter = new GroupMessageByGroupId_GroupId()
                        {
                            group_id = groupId,
                            is_to_all = isToAll
                        },
                        voice = new GroupMessageByGroupId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "voice"
                    };
                    break;

                case GroupMessageType.mpnews:
                    baseData = new GroupMessageByGroupId_MpNewsData()
                    {
                        filter = new GroupMessageByGroupId_GroupId()
                        {
                            group_id = groupId,
                            is_to_all = isToAll
                        },
                        mpnews = new GroupMessageByGroupId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "mpnews"
                    };
                    break;

                case GroupMessageType.video:
                    baseData = new GroupMessageByGroupId_MpVideoData()
                    {
                        filter = new GroupMessageByGroupId_GroupId()
                        {
                            group_id = groupId,
                            is_to_all = isToAll
                        },
                        mpvideo = new GroupMessageByGroupId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "mpvideo"
                    };
                    break;

                case GroupMessageType.wxcard:
                    baseData = new GroupMessageByGroupId_WxCardData()
                    {
                        filter = new GroupMessageByGroupId_GroupId()
                        {
                            group_id = groupId,
                            is_to_all = isToAll
                        },
                        wxcard = new GroupMessageByGroupId_WxCard()
                        {
                            card_id = value
                        },
                        msgtype = "wxcard"
                    };
                    break;

                case GroupMessageType.text:
                    baseData = new GroupMessageByGroupId_TextData()
                    {
                        filter = new GroupMessageByGroupId_GroupId()
                        {
                            group_id = groupId,
                            is_to_all = isToAll
                        },
                        text = new GroupMessageByGroupId_Content()
                        {
                            content = value
                        },
                        msgtype = "text"
                    };
                    break;

                default:
                    throw new Exception("参数错误。");
                    break;
                }

                return CommonJsonSend.Send <SendResult>(accessToken, urlFormat, baseData, timeOut: timeOut);
            }, accessTokenOrAppId));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 创建卡券
        /// </summary>
        /// <param name="accessTokenOrAppId"></param>
        /// <param name="cardInfo">创建卡券需要的数据,格式可以看CardCreateData.cs</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static CardCreateResultJson CreateCard(string accessTokenOrAppId, BaseCardInfo cardInfo, int timeOut = Config.TIME_OUT)
        {
            return(ApiHandlerWapper.TryCommonApi(accessToken =>
            {
                var urlFormat = string.Format("https://api.weixin.qq.com/card/create?access_token={0}", accessToken);

                CardCreateInfo cardData = null;
                CardType cardType = cardInfo.CardType;
                switch (cardType)
                {
                case CardType.GENERAL_COUPON:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_GeneralCoupon()
                        {
                            card_type = cardType,
                            general_coupon = cardInfo as Card_GeneralCouponData
                        }
                    };
                    break;

                case CardType.GROUPON:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_Groupon()
                        {
                            card_type = cardType,
                            groupon = cardInfo as Card_GrouponData
                        }
                    };
                    break;

                case CardType.GIFT:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_Gift()
                        {
                            card_type = cardType,
                            gift = cardInfo as Card_GiftData
                        }
                    };
                    break;

                case CardType.CASH:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_Cash()
                        {
                            card_type = cardType,
                            cash = cardInfo as Card_CashData
                        }
                    };
                    break;

                case CardType.DISCOUNT:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_DisCount()
                        {
                            card_type = cardType,
                            discount = cardInfo as Card_DisCountData
                        }
                    };
                    break;

                case CardType.MEMBER_CARD:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_MemberCard()
                        {
                            card_type = cardType,
                            member_card = cardInfo as Card_MemberCardData
                        }
                    };
                    break;

                case CardType.SCENIC_TICKET:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_ScenicTicket()
                        {
                            card_type = cardType,
                            scenic_ticket = cardInfo as Card_ScenicTicketData
                        }
                    };
                    break;

                case CardType.MOVIE_TICKET:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_MovieTicket()
                        {
                            card_type = cardType,

                            movie_ticket = cardInfo as Card_MovieTicketData
                        }
                    };
                    break;

                case CardType.BOARDING_PASS:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_BoardingPass()
                        {
                            card_type = cardType,
                            boarding_pass = cardInfo as Card_BoardingPassData
                        }
                    };
                    break;

                case CardType.LUCKY_MONEY:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_LuckyMoney()
                        {
                            card_type = cardType,
                            lucky_money = cardInfo as Card_LuckyMoneyData
                        }
                    };
                    break;

                case CardType.MEETING_TICKET:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_MeetingTicket()
                        {
                            card_type = cardType,
                            meeting_ticket = cardInfo as Card_MeetingTicketData
                        }
                    };
                    break;

                default:
                    break;
                }

                return CommonJsonSend.Send <CardCreateResultJson>(null, urlFormat, cardData, timeOut: timeOut);
            }, accessTokenOrAppId));
        }
Ejemplo n.º 18
0
        //官方文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1481187827_i0l21

        #region  步方法

        #region 根据分组或标签群发

        /// <summary>
        /// 根据分组或标签进行群发【订阅号与服务号认证后均可用】
        ///
        /// 请注意:
        /// 1、该接口暂时仅提供给已微信认证的服务号
        /// 2、虽然开发者使用高级群发接口的每日调用限制为100次,但是用户每月只能接收4条,请小心测试
        /// 3、无论在公众平台网站上,还是使用接口群发,用户每月只能接收4条群发消息,多于4条的群发将对该用户发送失败。
        /// 4、群发视频时需要先调用GetVideoMediaIdResult接口获取专用的MediaId然后进行群发
        ///
        /// </summary>
        /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
        /// <param name="groupId">群发到的分组的group_id,参见用户管理中用户分组接口,若is_to_all值为true,可不填写group_id;如果groupId和tagId同时填写,优先使用groupId;groupId和tagId最多只能使用一个</param>
        /// <param name="tagId">群发到的标签的tag_id,若is_to_all值为true,可不填写tag_id;如果groupId和tagId同时填写,优先使用groupId;groupId和tagId最多只能使用一个</param>
        /// <param name="value">群发媒体文件时传入mediaId,群发文本消息时传入content,群发卡券时传入cardId</param>
        /// <param name="type"></param>
        /// <param name="isToAll">用于设定是否向全部用户发送,值为true或false,选择true该消息群发给所有用户,选择false可根据group_id发送给指定群组的用户</param>
        /// <param name="sendIgnoreReprint">待群发的文章被判定为转载时,是否继续群发</param>
        /// <param name="clientmsgid">开发者侧群发msgid,长度限制64字节,如不填,则后台默认以群发范围和群发内容的摘要值做为clientmsgid</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        private static SendResult SendGroupMessageByFilter(string accessTokenOrAppId, string groupId, string tagId, string value, GroupMessageType type, bool isToAll = false, bool sendIgnoreReprint = false, string clientmsgid = null, int timeOut = Config.TIME_OUT)
        {
            return(ApiHandlerWapper.TryCommonApi(accessToken =>
            {
                string urlFormat = Config.ApiMpHost + "/cgi-bin/message/mass/sendall?access_token={0}";

                BaseGroupMessageDataByFilter baseData = null;
                BaseGroupMessageByFilter filter = null;
                if (!groupId.IsNullOrEmpty())
                {
                    filter = new GroupMessageByGroupId()
                    {
                        group_id = groupId,
                        is_to_all = isToAll,
                    };
                }
                else
                {
                    filter = new GroupMessageByTagId()
                    {
                        tag_id = tagId,
                        is_to_all = isToAll,
                    };
                }

                switch (type)
                {
                case GroupMessageType.image:
                    baseData = new GroupMessageByFilter_ImageData()
                    {
                        filter = filter,
                        image = new GroupMessageByGroupId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "image"
                    };
                    break;

                case GroupMessageType.voice:
                    baseData = new GroupMessageByFilter_VoiceData()
                    {
                        filter = filter,
                        voice = new GroupMessageByGroupId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "voice"
                    };
                    break;

                case GroupMessageType.mpnews:
                    baseData = new GroupMessageByFilter_MpNewsData()
                    {
                        filter = filter,
                        mpnews = new GroupMessageByGroupId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "mpnews"
                    };
                    break;

                case GroupMessageType.video:
                    baseData = new GroupMessageByFilter_MpVideoData()
                    {
                        filter = filter,
                        mpvideo = new GroupMessageByGroupId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "mpvideo"
                    };
                    break;

                case GroupMessageType.wxcard:
                    baseData = new GroupMessageByFilter_WxCardData()
                    {
                        filter = filter,
                        wxcard = new GroupMessageByGroupId_WxCard()
                        {
                            card_id = value
                        },
                        msgtype = "wxcard"
                    };
                    break;

                case GroupMessageType.text:
                    baseData = new GroupMessageByFilter_TextData()
                    {
                        filter = filter,
                        text = new GroupMessageByGroupId_Content()
                        {
                            content = value
                        },
                        msgtype = "text"
                    };
                    break;

                default:
                    throw new Exception("参数错误。");
                    //break;
                }

                baseData.send_ignore_reprint = sendIgnoreReprint ? 0 : 1;//待群发的文章被判定为转载时,是否继续群发
                baseData.clientmsgid = clientmsgid;

                return CommonJsonSend.Send <SendResult>(accessToken, urlFormat, baseData, timeOut: timeOut);
            }, accessTokenOrAppId));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 根据OpenId进行群发【订阅号不可用,服务号认证后可用】
        /// </summary>
        /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
        /// <param name="value">群发媒体文件时传入mediaId,群发文本消息时传入content,群发卡券时传入cardId</param>
        /// <param name="type"></param>
        /// <param name="openIds">openId字符串数组</param>
        /// <param name="clientmsgid">开发者侧群发msgid,长度限制64字节,如不填,则后台默认以群发范围和群发内容的摘要值做为clientmsgid</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static SendResult SendGroupMessageByOpenId(string accessTokenOrAppId, GroupMessageType type, string value, string clientmsgid = null, int timeOut = Config.TIME_OUT, params string[] openIds)
        {
            return(ApiHandlerWapper.TryCommonApi(accessToken =>
            {
                string urlFormat = Config.ApiMpHost + "/cgi-bin/message/mass/send?access_token={0}";

                BaseGroupMessageDataByOpenId baseData = null;
                switch (type)
                {
                case GroupMessageType.image:
                    baseData = new GroupMessageByOpenId_ImageData()
                    {
                        touser = openIds,
                        image = new GroupMessageByOpenId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "image"
                    };
                    break;

                case GroupMessageType.voice:
                    baseData = new GroupMessageByOpenId_VoiceData()
                    {
                        touser = openIds,
                        voice = new GroupMessageByOpenId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "voice"
                    };
                    break;

                case GroupMessageType.mpnews:
                    baseData = new GroupMessageByOpenId_MpNewsData()
                    {
                        touser = openIds,
                        mpnews = new GroupMessageByOpenId_MediaId()
                        {
                            media_id = value
                        },
                        msgtype = "mpnews"
                    };
                    break;

                case GroupMessageType.wxcard:
                    baseData = new GroupMessageByOpenId_WxCardData()
                    {
                        touser = openIds,
                        wxcard = new GroupMessageByOpenId_WxCard()
                        {
                            card_id = value
                        },
                        msgtype = "wxcard"
                    };
                    break;

                case GroupMessageType.video:
                    throw new Exception("发送视频信息请使用SendVideoGroupMessageByOpenId方法。");
                    break;

                case GroupMessageType.text:
                    baseData = new GroupMessageByOpenId_TextData()
                    {
                        touser = openIds,
                        text = new GroupMessageByOpenId_Content()
                        {
                            content = value
                        },
                        msgtype = "text"
                    };
                    break;

                default:
                    throw new Exception("参数错误。");
                    break;
                }

                baseData.clientmsgid = clientmsgid;

                return CommonJsonSend.Send <SendResult>(accessToken, urlFormat, baseData, timeOut: timeOut);
            }, accessTokenOrAppId));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 【异步方法】发消息
        /// </summary>
        /// <param name="accessTokenOrAppKey"></param>
        /// <param name="sender">发送人的userId</param>
        /// <param name="type">接收人类型:single|group,分别表示:群聊|单聊</param>
        /// <param name="msgType">消息类型,text|image|file</param>
        /// <param name="chatIdOrUserId">会话值,为userid|chatid,分别表示:成员id|会话id,单聊是userid,群聊是chatid</param>
        /// <param name="contentOrMediaId">文本消息是content,图片或文件是mediaId</param>
        /// <param name="timeOut"></param>
        /// <returns></returns>
        public static async Task <WorkJsonResult> SendChatMessageAsync(string accessTokenOrAppKey, string sender, Chat_Type type, ChatMsgType msgType, string chatIdOrUserId, string contentOrMediaId, int timeOut = Config.TIME_OUT)
        {
            return(await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
            {
                var url = string.Format("https://qyapi.weixin.qq.com/cgi-bin/chat/send?access_token={0}", accessToken.AsUrlData());

                BaseSendChatMessageData data;

                switch (msgType)
                {
                case ChatMsgType.text:
                    data = new SendTextMessageData()
                    {
                        receiver = new Receiver()
                        {
                            type = type.ToString(),
                            id = chatIdOrUserId
                        },
                        sender = sender,
                        msgtype = msgType.ToString(),
                        text = new Chat_Content()
                        {
                            content = contentOrMediaId
                        }
                    };
                    break;

                case ChatMsgType.image:
                    data = new SendImageMessageData()
                    {
                        receiver = new Receiver()
                        {
                            type = type.ToString(),
                            id = chatIdOrUserId
                        },
                        sender = sender,
                        msgtype = msgType.ToString(),
                        image = new Chat_Image()
                        {
                            media_id = contentOrMediaId
                        }
                    };
                    break;

                case ChatMsgType.file:
                    data = new SendFileMessageData()
                    {
                        receiver = new Receiver()
                        {
                            type = type.ToString(),
                            id = chatIdOrUserId
                        },
                        sender = sender,
                        msgtype = msgType.ToString(),
                        file = new Chat_File()
                        {
                            media_id = contentOrMediaId
                        }
                    };
                    break;

                default:
                    throw new ArgumentOutOfRangeException("msgType");
                }

                return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync <WorkJsonResult>(null, url, data, CommonJsonSendType.POST, timeOut);
            }, accessTokenOrAppKey));
        }