Exemplo n.º 1
0
        public GetAccessTokenResult GetAccessToken(string appId, string appSecret)
        {
            var cacheKey = appId;

            if (IGetAccessTokenCache != null)
            {
                var cacheObj = IGetAccessTokenCache.Get(cacheKey);
                if (ToolFactory.CreateIValidatorTool().IsNotEmpty(cacheObj))
                {
                    return(cacheObj);
                }
            }
            string url    = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", appId, appSecret);
            var    client = ToolFactory.Ioc.Get <IHttpClient>();
            var    result = client.DownloadToString(url);

            if (WeiXinHelper.IsFailureInvokeWeiXinAPI(result))
            {
                throw new Exception(result);
            }
            var iJson       = ToolFactory.CreateIJsonSerializeTool();
            var accessToken = iJson.DeserializeFromString <GetAccessTokenResult>(result);

            if (IGetAccessTokenCache != null)
            {
                IGetAccessTokenCache.Set(cacheKey, accessToken);
            }
            return(accessToken);
        }
Exemplo n.º 2
0
        public GetQRCodeTicketResultDto GetQRCodeTicket(string accessToken, QRCodePostDataDto qrCodePostDataDto)
        {
            var weiXinUrl = string.Format(WEIXIN_CREATE_QR_URL, accessToken);

            IHttpClient client      = ToolFactory.BLLIoc.Get <IHttpClient>();
            var         iJsonHelper = ToolFactory.CreateIJsonSerializeTool();
            var         postData    = iJsonHelper.SerializeToString(qrCodePostDataDto);
            var         postResult  = client.Post(weiXinUrl, postData);

            WeiXinHelper.IsFailureInvokeWeiXinAPIThrowException(postResult);
            var result = iJsonHelper.DeserializeFromString <GetQRCodeTicketResultDto>(postResult);

            return(result);
        }
Exemplo n.º 3
0
        public IList <WeiXinAccount> GetBasicAccountInfos(string accessToken, IList <GetBasicAccountInfosParam> getBasicAccountInfosParams)
        {
            var user_list = new GetBasicAccountInfosParamUserList()
            {
                user_list = getBasicAccountInfosParams
            };
            var url      = string.Format("https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token={0}", accessToken);
            var client   = ToolFactory.Ioc.Get <IHttpClient>();
            var postData = ToolFactory.CreateIJsonSerializeTool().SerializeToString(user_list);
            var result   = client.Post(url, postData);

            WeiXinHelper.IsFailureInvokeWeiXinAPIThrowException(result);
            var modelResult = WeiXinHelper.JsonHelper().DeserializeFromString <GetBasicAccountInfosResultUserInfoList>(result);

            return(modelResult.user_info_list);
        }
Exemplo n.º 4
0
        public void UnGZip()
        {
            var filePath = @"d:\2.gz";

            var jsonHelper = ToolFactory.CreateIJsonSerializeTool();

            using (var sr = GZipHelper.UnGZipToStreamReader(filePath))
            {
                while (sr.EndOfStream == false)
                {
                    var l    = sr.ReadLine();
                    var json = l + "]}";
                }
            }

            var i = 0;
        }
Exemplo n.º 5
0
        public T GetOrCreate <T>(Guid configId, T defaultConfig)
        {
            var iJson  = ToolFactory.CreateIJsonSerializeTool();
            var models = this.FindById(configId);

            if (models != null)
            {
                var result = iJson.DeserializeFromString <T>(models.ConfigContent);
                return(result);
            }
            else
            {
                var configJsonString = iJson.SerializeToString(defaultConfig);
                this.Insert(new ComConfigMainDto()
                {
                    ID            = configId,
                    ConfigContent = configJsonString
                });
                return(defaultConfig);
            }
        }
Exemplo n.º 6
0
 public static void ResponseWriteJson(object obj)
 {
     Response.ContentType = "application/json";
     Response.Write(ToolFactory.CreateIJsonSerializeTool().SerializeToString(obj));
 }
Exemplo n.º 7
0
 public static ISerializeTool JsonHelper()
 {
     return(ToolFactory.CreateIJsonSerializeTool());
 }
Exemplo n.º 8
0
        public static GetJsTickectResultDto ToGetJsTickectResultDto(string content)
        {
            var iSerialize = ToolFactory.CreateIJsonSerializeTool();

            return(iSerialize.DeserializeFromString <GetJsTickectResultDto>(content));
        }
Exemplo n.º 9
0
        public static ErrorResultDto ToErrorResultDto(string returnResult)
        {
            var iSerialize = ToolFactory.CreateIJsonSerializeTool();

            return(iSerialize.DeserializeFromString <ErrorResultDto>(returnResult));
        }