Ejemplo n.º 1
0
        /// <summary>
        /// 向需要AccessToken的API发送消息的公共方法
        /// </summary>
        /// <param name="accessToken">这里的AccessToken是通用接口的AccessToken,非OAuth的。如果不需要,可以为null,此时urlFormat不要提供{0}参数</param>
        /// <param name="urlFormat"></param>
        /// <param name="data">如果是Get方式,可以为null</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static T Send <T>(string accessToken, string urlFormat, object data, CommonJsonSendType sendType = CommonJsonSendType.POST, int timeOut = Config.TIME_OUT) where T : WxJsonResult, new()
        {
            var url = string.IsNullOrEmpty(accessToken) ? urlFormat : string.Format(urlFormat, accessToken);

            switch (sendType)
            {
            case CommonJsonSendType.GET:
                return(GetMethod.GetJson <T>(url));

            case CommonJsonSendType.POST:
                SerializerHelper serializerHelper = new SerializerHelper();
                var jsonString = serializerHelper.GetJsonString(data);
                using (MemoryStream ms = new MemoryStream())
                {
                    var bytes = Encoding.UTF8.GetBytes(jsonString);
                    ms.Write(bytes, 0, bytes.Length);
                    ms.Seek(0, SeekOrigin.Begin);

                    return(PostMethod.PostGetJson <T>(url, null, ms, timeOut: timeOut));
                }

            default:
                throw new ArgumentOutOfRangeException("sendType");
            }
        }
Ejemplo n.º 2
0
        private GetMemberResult GetMemberFunc(int weixinId, string openId)
        {
            var url      = _passport.ApiUrl + "GetMember";
            var formData = new Dictionary <string, string>();

            formData["token"]    = _passport.Token;
            formData["openid"]   = openId;
            formData["weixinId"] = weixinId.ToString();

            var result = PostMethod.PostGetJson <GetMemberResult>(url, formData: formData);

            return(result);
        }